Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

Revert "fix: remove video source cancelled exception"

Predidit91365c3216e7
diff --git a/lib/pages/download/download_controller.dart b/lib/pages/download/download_controller.dart
index e0cfac3d..465f37a5 100644
--- a/lib/pages/download/download_controller.dart
+++ b/lib/pages/download/download_controller.dart
@@ -361,6 +361,8 @@ abstract class _DownloadController with Store {
m3u8Url = source.url;
} on VideoSourceTimeoutException {
KazumiLogger().w('DownloadController: WebView resolution timed out');
+ } on VideoSourceCancelledException {
+ KazumiLogger().i('DownloadController: WebView resolution cancelled');
} catch (e) {
KazumiLogger()
.e('DownloadController: WebView resolution failed', error: e);
diff --git a/lib/pages/video/video_controller.dart b/lib/pages/video/video_controller.dart
index 99966d16..8efaca49 100644
--- a/lib/pages/video/video_controller.dart
+++ b/lib/pages/video/video_controller.dart
@@ -296,6 +296,9 @@ abstract class _VideoPageController with Store {
} on VideoSourceTimeoutException {
loading = false;
errorMessage = '视频解析超时,请重试';
+ } on VideoSourceCancelledException {
+ KazumiLogger().i('VideoPageController: video URL resolution cancelled');
+ // 不设置 loading = false,因为可能是切换到新的集数
} catch (e) {
loading = false;
errorMessage = '视频解析失败:${e.toString()}';
diff --git a/lib/providers/video_source_provider.dart b/lib/providers/video_source_provider.dart
index df613fca..aea3c4a3 100644
--- a/lib/providers/video_source_provider.dart
+++ b/lib/providers/video_source_provider.dart
@@ -47,6 +47,14 @@ class VideoSourceTimeoutException implements Exception {
String toString() => 'VideoSourceTimeoutException: Timed out after ${timeout.inSeconds}s';
}
+/// 视频源解析取消异常
+class VideoSourceCancelledException implements Exception {
+ const VideoSourceCancelledException();
+
+ @override
+ String toString() => 'VideoSourceCancelledException: Resolution was cancelled';
+}
+
/// 视频源提供者接口
///
/// 抽象视频源的获取方式,支持多种实现:
@@ -66,6 +74,7 @@ abstract class IVideoSourceProvider {
/// 可能抛出:
/// - [VideoSourceNotFoundException] 未找到视频源
/// - [VideoSourceTimeoutException] 解析超时
+ /// - [VideoSourceCancelledException] 解析被取消
Future<VideoSource> resolve(
String episodeUrl, {
required bool useLegacyParser,
@@ -74,6 +83,8 @@ abstract class IVideoSourceProvider {
});
/// 取消当前正在进行的解析
+ ///
+ /// 调用后,正在进行的 [resolve] 会抛出 [VideoSourceCancelledException]
void cancel();
/// 释放资源
diff --git a/lib/providers/webview_video_source_provider.dart b/lib/providers/webview_video_source_provider.dart
index 51256802..059aa8a5 100644
--- a/lib/providers/webview_video_source_provider.dart
+++ b/lib/providers/webview_video_source_provider.dart
@@ -32,6 +32,9 @@ class WebViewVideoSourceProvider implements IVideoSourceProvider {
}) async {
resolveId++;
final currentResolveId = resolveId;
+ if (_completer != null && !_completer!.isCompleted) {
+ _completer!.completeError(const VideoSourceCancelledException());
+ }
await _subscription?.cancel();
_subscription = null;
@@ -77,6 +80,11 @@ class WebViewVideoSourceProvider implements IVideoSourceProvider {
);
return result;
+ } catch (e) {
+ if (currentResolveId != resolveId) {
+ throw const VideoSourceCancelledException();
+ }
+ rethrow;
} finally {
if (currentResolveId == resolveId) {
await _subscription?.cancel();
@@ -89,6 +97,9 @@ class WebViewVideoSourceProvider implements IVideoSourceProvider {
@override
void cancel() {
+ if (_completer != null && !_completer!.isCompleted) {
+ _completer!.completeError(const VideoSourceCancelledException());
+ }
_subscription?.cancel();
_subscription = null;
}