基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
fix(windows): force HLS demuxing for detected M3U sources
Predidit43e0fe808f04
diff --git a/lib/pages/player/controller/player_models.dart b/lib/pages/player/controller/player_models.dartindex c4460be2..d8ced769 100644--- a/lib/pages/player/controller/player_models.dart+++ b/lib/pages/player/controller/player_models.dart@@ -1,7 +1,10 @@+import 'package:kazumi/services/video_source/video_source_format.dart';+class PlaybackInitParams {final String videoUrl;final int offset;final bool isLocalPlayback;+ final VideoSourceFormat videoSourceFormat;final int bangumiId;final String pluginName;final int episode;@@ -31,6 +34,7 @@ class PlaybackInitParams {required this.episodeTitle,required this.referer,required this.currentRoad,+ this.videoSourceFormat = VideoSourceFormat.auto,this.pageUrl = '',this.sortNumber,this.coverUrl,diff --git a/lib/pages/player/controller/player_playback_controller.dart b/lib/pages/player/controller/player_playback_controller.dartindex 58600bf3..2fc3d453 100644--- a/lib/pages/player/controller/player_playback_controller.dart+++ b/lib/pages/player/controller/player_playback_controller.dart@@ -15,6 +15,7 @@ import 'package:kazumi/services/network/system_proxy_service.dart';import 'package:kazumi/services/player/playback_cache_policy.dart';import 'package:kazumi/services/player/player_screenshot_service.dart';import 'package:kazumi/services/storage/storage.dart';+import 'package:kazumi/services/video_source/video_source_format.dart';import 'package:media_kit/media_kit.dart';import 'package:media_kit_video/media_kit_video.dart';import 'package:mobx/mobx.dart';@@ -234,6 +235,7 @@ abstract class _PlayerPlaybackController with Store {bool adBlockerEnabled, {required bool Function() canInstall,int offset = 0,+ VideoSourceFormat videoSourceFormat = VideoSourceFormat.auto,}) async {startOffset = offset;superResolutionMode = SuperResolutionMode.fromStorageValue(@@ -410,6 +412,13 @@ abstract class _PlayerPlaybackController with Store {}}+ if (videoSourceFormat == VideoSourceFormat.hls) {+ await pp.setProperty('demuxer-lavf-format', 'hls');+ if (!isCurrentPlayer(player)) {+ return await _discardIfNotCurrent(candidate);+ }+ }+await player.open(Media(videoUrl(),start: Duration(seconds: offset), httpHeaders: httpHeaders),diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dartindex d37c1704..232902d9 100644--- a/lib/pages/player/player_controller.dart+++ b/lib/pages/player/player_controller.dart@@ -202,6 +202,7 @@ class PlayerController implements Disposable {params.adBlockerEnabled,canInstall: () => initialization.isActive,offset: params.offset,+ videoSourceFormat: params.videoSourceFormat,);} catch (e) {if (initialization.isStale) {diff --git a/lib/pages/video/video_controller.dart b/lib/pages/video/video_controller.dartindex c1594907..182ae777 100644--- a/lib/pages/video/video_controller.dart+++ b/lib/pages/video/video_controller.dart@@ -624,6 +624,7 @@ abstract class _VideoPageController with Store implements Disposable {videoUrl: source.url,offset: source.offset,isLocalPlayback: false,+ videoSourceFormat: source.format,bangumiId: bangumiItem.id,pluginName: currentPlugin.name,episode: resolvedEpisode.listIndex,diff --git a/lib/services/video_source/video_source_format.dart b/lib/services/video_source/video_source_format.dartnew file mode 100644index 00000000..20266f6c--- /dev/null+++ b/lib/services/video_source/video_source_format.dart@@ -0,0 +1,4 @@+enum VideoSourceFormat {+ auto,+ hls,+}diff --git a/lib/services/video_source/video_source_service.dart b/lib/services/video_source/video_source_service.dartindex bd778e06..2c851bf4 100644--- a/lib/services/video_source/video_source_service.dart+++ b/lib/services/video_source/video_source_service.dart@@ -1,5 +1,7 @@import 'dart:async';+import 'package:kazumi/services/video_source/video_source_format.dart';+/// 视频源类型enum VideoSourceType {/// 在线解析(WebView)@@ -20,14 +22,19 @@ class VideoSource {/// 视频源类型final VideoSourceType type;+ /// 解析视频源时确认的媒体格式提示+ final VideoSourceFormat format;+const VideoSource({required this.url,required this.offset,required this.type,+ this.format = VideoSourceFormat.auto,});@override- String toString() => 'VideoSource(url: $url, offset: $offset, type: $type)';+ String toString() =>+ 'VideoSource(url: $url, offset: $offset, type: $type, format: $format)';}/// 视频源未找到异常diff --git a/lib/services/video_source/webview_video_source_service.dart b/lib/services/video_source/webview_video_source_service.dartindex e552c85a..506b8809 100644--- a/lib/services/video_source/webview_video_source_service.dart+++ b/lib/services/video_source/webview_video_source_service.dart@@ -90,7 +90,7 @@ class WebViewVideoSourceService implements IVideoSourceService {throw VideoSourceTimeoutException(timeout);},);- final cancelFuture = request.cancelled.then<(String, int)>((_) {+ final cancelFuture = request.cancelled.then<VideoParserEvent>((_) {throw const VideoSourceCancelledException();});final event = await Future.any([parserFuture, cancelFuture]);@@ -98,9 +98,10 @@ class WebViewVideoSourceService implements IVideoSourceService {request.throwIfNotCurrent(_activeRequest);return VideoSource(- url: event.$1,- offset: event.$2,+ url: event.url,+ offset: event.offset,type: VideoSourceType.online,+ format: event.format,);} catch (e) {if (e is VideoSourceCancelledException) {diff --git a/lib/webview/video/impl/video_webview_android_impl.dart b/lib/webview/video/impl/video_webview_android_impl.dartindex 038759ef..7b78e7d0 100644--- a/lib/webview/video/impl/video_webview_android_impl.dart+++ b/lib/webview/video/impl/video_webview_android_impl.dart@@ -102,8 +102,8 @@ class VideoWebviewAndroidImpllogEventController.add('Loading video source ${decodeVideoSource(encodedUrl)}');unloadPage();- videoParserEventController- .add((decodeVideoSource(encodedUrl), offset));+ final videoUrl = decodeVideoSource(encodedUrl);+ notifyVideoSourceResolved(videoUrl);}}});@@ -120,7 +120,7 @@ class VideoWebviewAndroidImplisVideoSourceLoaded = true;videoLoadingEventController.add(false);unloadPage();- videoParserEventController.add((message, offset));+ notifyVideoSourceResolved(message);}});}diff --git a/lib/webview/video/impl/video_webview_apple_impl.dart b/lib/webview/video/impl/video_webview_apple_impl.dartindex 5d1e0ca8..f8f2acf5 100644--- a/lib/webview/video/impl/video_webview_apple_impl.dart+++ b/lib/webview/video/impl/video_webview_apple_impl.dart@@ -177,8 +177,8 @@ class VideoWebviewAppleImpllogEventController.add('Loading video source ${decodeVideoSource(encodedUrl)}');unloadPage();- videoParserEventController- .add((decodeVideoSource(encodedUrl), offset));+ final videoUrl = decodeVideoSource(encodedUrl);+ notifyVideoSourceResolved(videoUrl);}}});@@ -195,7 +195,7 @@ class VideoWebviewAppleImplisVideoSourceLoaded = true;videoLoadingEventController.add(false);unloadPage();- videoParserEventController.add((message, offset));+ notifyVideoSourceResolved(message);}});}diff --git a/lib/webview/video/impl/video_webview_impl.dart b/lib/webview/video/impl/video_webview_impl.dartindex 3a7ba10f..6769bca7 100644--- a/lib/webview/video/impl/video_webview_impl.dart+++ b/lib/webview/video/impl/video_webview_impl.dart@@ -46,7 +46,7 @@ class VideoWebviewImplisVideoSourceLoaded = true;videoLoadingEventController.add(false);unloadPage();- videoParserEventController.add((url, offset));+ notifyVideoSourceResolved(url);}return null;},@@ -129,8 +129,8 @@ class VideoWebviewImpllogEventController.add('Loading video source ${decodeVideoSource(encodedUrl)}');unloadPage();- videoParserEventController- .add((decodeVideoSource(encodedUrl), offset));+ final videoUrl = decodeVideoSource(encodedUrl);+ notifyVideoSourceResolved(videoUrl);}}});@@ -147,7 +147,7 @@ class VideoWebviewImplisVideoSourceLoaded = true;videoLoadingEventController.add(false);unloadPage();- videoParserEventController.add((message, offset));+ notifyVideoSourceResolved(message);}});}diff --git a/lib/webview/video/impl/video_webview_linux_impl.dart b/lib/webview/video/impl/video_webview_linux_impl.dartindex a4217254..6845f801 100644--- a/lib/webview/video/impl/video_webview_linux_impl.dart+++ b/lib/webview/video/impl/video_webview_linux_impl.dart@@ -108,8 +108,8 @@ class VideoWebviewLinuxImpl extends VideoWebviewController<Webview> {logEventController.add('Loading video source ${decodeVideoSource(messageItem)}');unloadPage();- videoParserEventController- .add((decodeVideoSource(messageItem), offset));+ final videoUrl = decodeVideoSource(messageItem);+ notifyVideoSourceResolved(videoUrl);}}}@@ -125,7 +125,7 @@ class VideoWebviewLinuxImpl extends VideoWebviewController<Webview> {isVideoSourceLoaded = true;videoLoadingEventController.add(false);unloadPage();- videoParserEventController.add((videoUrl, offset));+ notifyVideoSourceResolved(videoUrl);}}});diff --git a/lib/webview/video/impl/video_webview_windows_impl.dart b/lib/webview/video/impl/video_webview_windows_impl.dartindex 6408ce17..fce3327e 100644--- a/lib/webview/video/impl/video_webview_windows_impl.dart+++ b/lib/webview/video/impl/video_webview_windows_impl.dart@@ -4,6 +4,7 @@ import 'package:kazumi/webview/video/video_webview_controller.dart';import 'package:kazumi/services/storage/storage.dart';import 'package:kazumi/services/network/proxy_utils.dart';import 'package:kazumi/services/logging/logger.dart';+import 'package:kazumi/services/video_source/video_source_format.dart';class VideoWebviewWindowsImplextends VideoWebviewController<WebviewController> {@@ -62,7 +63,10 @@ class VideoWebviewWindowsImplisVideoSourceLoaded = true;videoLoadingEventController.add(false);logEventController.add('Loading m3u8 source: $url');- videoParserEventController.add((url, offset));+ notifyVideoSourceResolved(+ url,+ format: VideoSourceFormat.hls,+ );}));subscriptions.add(headlessWebview!.onVideoSourceLoaded.listen((data) {if (headlessWebview == null) return;@@ -75,7 +79,7 @@ class VideoWebviewWindowsImplisVideoSourceLoaded = true;videoLoadingEventController.add(false);logEventController.add('Loading video source: $url');- videoParserEventController.add((url, offset));+ notifyVideoSourceResolved(url);}));await headlessWebview!.loadUrl(url);}diff --git a/lib/webview/video/video_webview_controller.dart b/lib/webview/video/video_webview_controller.dartindex a9debe54..51184f0f 100644--- a/lib/webview/video/video_webview_controller.dart+++ b/lib/webview/video/video_webview_controller.dart@@ -1,12 +1,20 @@import 'dart:io';import 'dart:async';+import 'package:flutter/foundation.dart';import 'package:kazumi/webview/video/impl/video_webview_android_impl.dart';import 'package:kazumi/webview/video/impl/video_webview_impl.dart';import 'package:kazumi/webview/video/impl/video_webview_windows_impl.dart';import 'package:kazumi/webview/video/impl/video_webview_linux_impl.dart';import 'package:kazumi/webview/video/impl/video_webview_apple_impl.dart';import 'package:kazumi/services/platform/webview_feature_service.dart';+import 'package:kazumi/services/video_source/video_source_format.dart';++typedef VideoParserEvent = ({+ String url,+ int offset,+ VideoSourceFormat format,+});abstract class VideoWebviewController<T> {// WebView controller.@@ -40,13 +48,25 @@ abstract class VideoWebviewController<T> {// Stream to notify when the video source is loadedStream<bool> get onVideoLoading => videoLoadingEventController.stream;- // Stream to notify video source URL when the video source is loaded- // The first parameter is the video source URL and the second parameter is the video offset (start position)- final StreamController<(String, int)> videoParserEventController =- StreamController<(String, int)>.broadcast();-- Stream<(String, int)> get onVideoURLParser =>- videoParserEventController.stream;+ // Stream to notify when a video source URL is resolved, including its+ // playback offset and any format information confirmed by the parser.+ final StreamController<VideoParserEvent> _videoParserEventController =+ StreamController<VideoParserEvent>.broadcast();++ Stream<VideoParserEvent> get onVideoURLParser =>+ _videoParserEventController.stream;++ @protected+ void notifyVideoSourceResolved(+ String url, {+ VideoSourceFormat format = VideoSourceFormat.auto,+ }) {+ _videoParserEventController.add((+ url: url,+ offset: offset,+ format: format,+ ));+ }void disposeEventControllers() {if (!initEventController.isClosed) {@@ -58,8 +78,8 @@ abstract class VideoWebviewController<T> {if (!videoLoadingEventController.isClosed) {videoLoadingEventController.close();}- if (!videoParserEventController.isClosed) {- videoParserEventController.close();+ if (!_videoParserEventController.isClosed) {+ _videoParserEventController.close();}}