From a53429dc103a6be12d606642acd16d8e441eeeb5 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Mon, 9 Dec 2024 00:05:43 +0800 Subject: [PATCH] mod --- lib/http/api.dart | 33 +++++++++++++++++++++++ lib/http/constants.dart | 1 + lib/http/html.dart | 2 +- lib/http/init.dart | 9 ------- lib/http/live.dart | 14 ++++++++++ lib/models/video_detail_res.dart | 40 ---------------------------- lib/pages/fav_detail/controller.dart | 18 +++++++++++++ lib/pages/video/detail/view.dart | 10 +++---- lib/plugin/pl_player/controller.dart | 28 ++++--------------- lib/router/app_pages.dart | 3 +++ lib/utils/utils.dart | 15 ----------- pubspec.lock | 8 ++++++ pubspec.yaml | 18 +++---------- 13 files changed, 92 insertions(+), 107 deletions(-) diff --git a/lib/http/api.dart b/lib/http/api.dart index 79b504f8..d7d60160 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -562,4 +562,37 @@ class Api { /// 系统通知标记已读 static const String systemMarkRead = '${HttpString.messageBaseUrl}/x/sys-msg/update_cursor'; + + /// 编辑收藏夹 + static const String editFavFolder = '/x/v3/fav/folder/edit'; + + /// 新建收藏夹 + static const String addFavFolder = '/x/v3/fav/folder/add'; + + /// 直播间弹幕信息 + static const String getDanmuInfo = + '${HttpString.liveBaseUrl}/xlive/web-room/v1/index/getDanmuInfo'; + + /// 直播间发送弹幕 + static const String sendLiveMsg = '${HttpString.liveBaseUrl}/msg/send'; + + /// 我的关注 - 正在直播 + static const String getFollowingLive = + '${HttpString.liveBaseUrl}/xlive/web-ucenter/user/following'; + + /// 稍后再看&收藏夹视频列表 + static const String mediaList = '/x/v2/medialist/resource/list'; + + /// 用户专栏 + static const String opusList = '/x/polymer/web-dynamic/v1/opus/feed/space'; + + /// + static const String getViewInfo = '/x/article/viewinfo'; + + /// 直播间记录 + static const String liveRoomEntry = + '${HttpString.liveBaseUrl}/xlive/web-room/v1/index/roomEntryAction'; + + /// 删除评论 + static const String replyDel = '/x/v2/reply/del'; } diff --git a/lib/http/constants.dart b/lib/http/constants.dart index cad413ef..b734c279 100644 --- a/lib/http/constants.dart +++ b/lib/http/constants.dart @@ -6,6 +6,7 @@ class HttpString { static const String liveBaseUrl = 'https://api.live.bilibili.com'; static const String passBaseUrl = 'https://passport.bilibili.com'; static const String messageBaseUrl = 'https://message.bilibili.com'; + static const String bangumiBaseUrl = 'https://bili.meark.me'; static const List validateStatusCodes = [ 302, 304, diff --git a/lib/http/html.dart b/lib/http/html.dart index 26c3bb23..100887e5 100644 --- a/lib/http/html.dart +++ b/lib/http/html.dart @@ -70,7 +70,7 @@ class HtmlHttp { static Future reqReadHtml(id, dynamicType) async { var response = await Request().get( "https://www.bilibili.com/$dynamicType/$id/", - extra: {'ua': 'pc', 'opus-goback': '1'}, + extra: {'ua': 'pc'}, ); Document rootTree = parse(response.data); Element body = rootTree.body!; diff --git a/lib/http/init.dart b/lib/http/init.dart index 5c7c8ad9..eae94ae4 100644 --- a/lib/http/init.dart +++ b/lib/http/init.dart @@ -226,15 +226,6 @@ class Request { if (extra['ua'] != null) { options.headers = {'user-agent': headerUa(type: extra['ua'])}; } - if (extra['opus-goback'] != null) { - List cookies = await cookieManager.cookieJar - .loadForRequest(Uri.parse(HttpString.baseUrl)); - String cookieHeader = cookies - .map((cookie) => '${cookie.name}=${cookie.value}') - .join('; '); - options.headers!['cookie'] = - '$cookieHeader; opus-goback = ${extra['opus-goback']}'; - } } options.responseType = resType; diff --git a/lib/http/live.dart b/lib/http/live.dart index d60c9e7f..259f86fc 100644 --- a/lib/http/live.dart +++ b/lib/http/live.dart @@ -145,4 +145,18 @@ class LiveHttp { }; } } + + // 直播历史记录 + static Future liveRoomEntry({required int roomId}) async { + await Request().post( + Api.liveRoomEntry, + data: { + 'room_id': roomId, + 'platform': 'pc', + 'csrf_token': await Request.getCsrf(), + 'csrf': await Request.getCsrf(), + 'visit_id': '', + }, + ); + } } diff --git a/lib/models/video_detail_res.dart b/lib/models/video_detail_res.dart index b5c1e686..ae272375 100644 --- a/lib/models/video_detail_res.dart +++ b/lib/models/video_detail_res.dart @@ -703,43 +703,3 @@ class Vip { status = json['status']; } } - -class Staff { - Staff({ - this.mid, - this.title, - this.name, - this.face, - this.vip, - }); - - int? mid; - String? title; - String? name; - String? face; - int? status; - Vip? vip; - - Staff.fromJson(Map json) { - mid = json['mid']; - title = json['title']; - name = json['name']; - face = json['face']; - vip = Vip.fromJson(json['vip']); - } -} - -class Vip { - Vip({ - this.type, - this.status, - }); - - int? type; - int? status; - - Vip.fromJson(Map json) { - type = json['type']; - status = json['status']; - } -} diff --git a/lib/pages/fav_detail/controller.dart b/lib/pages/fav_detail/controller.dart index 1f9b1dd7..ba722481 100644 --- a/lib/pages/fav_detail/controller.dart +++ b/lib/pages/fav_detail/controller.dart @@ -132,4 +132,22 @@ class FavDetailController extends GetxController { title.value = res['title']; print(title); } + + Future toViewPlayAll() async { + final FavDetailItemData firstItem = favList.first; + final String heroTag = Utils.makeHeroTag(firstItem.bvid); + Get.toNamed( + '/video?bvid=${firstItem.bvid}&cid=${firstItem.cid}', + arguments: { + 'videoItem': firstItem, + 'heroTag': heroTag, + 'sourceType': 'fav', + 'mediaId': favInfo['id'], + 'oid': firstItem.id, + 'favTitle': favInfo['title'], + 'favInfo': favInfo, + 'count': favInfo['media_count'], + }, + ); + } } diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 5c6c2d24..d3afdf1d 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -668,11 +668,11 @@ class _VideoDetailPageState extends State tag: heroTag, child: Stack( children: [ - if (isShowing) - Padding( - padding: EdgeInsets.only(top: 0), - child: videoPlayerPanel, - ), + Obx( + () => isShowing.value + ? buildVideoPlayerPanel() + : const SizedBox(), + ), /// 关闭自动播放时 手动播放 Obx( diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index a8ed354f..8dff954a 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -366,13 +366,7 @@ class PlPlayerController { } // 配置Player 音轨、字幕等等 _videoPlayerController = await _createVideoController( - dataSource, - _looping, - enableHA, - width, - height, - seekTo, - ); + dataSource, _looping, enableHA, width, height, seekTo); // 获取视频时长 00:00 _duration.value = duration ?? _videoPlayerController!.state.duration; updateDurationSecond(); @@ -403,7 +397,7 @@ class PlPlayerController { bool enableHA, double? width, double? height, - Duration? seekTo, + Duration seekTo, ) async { // 每次配置时先移除监听 removeListeners(); @@ -491,12 +485,9 @@ class PlPlayerController { play: false, ); } - player.open( - Media( - dataSource.videoSource!, - httpHeaders: dataSource.httpHeaders, - start: seekTo ?? Duration.zero, - ), + await player.open( + Media(dataSource.videoSource!, + httpHeaders: dataSource.httpHeaders, start: seekTo), play: false, ); // 音轨 @@ -536,15 +527,6 @@ class PlPlayerController { await setPlaybackSpeed(1.0); } } - getVideoFit(); - // if (_looping) { - // await setLooping(_looping); - // } - - // 自动播放 - if (_autoPlay) { - await play(duration: duration); - } } List subscriptions = []; diff --git a/lib/router/app_pages.dart b/lib/router/app_pages.dart index 67dd770d..25f42d56 100644 --- a/lib/router/app_pages.dart +++ b/lib/router/app_pages.dart @@ -193,6 +193,9 @@ class Routes { // 专栏 CustomGetPage(name: '/opus', page: () => const OpusPage()), CustomGetPage(name: '/read', page: () => const ReadPage()), + // 用户专栏 + CustomGetPage( + name: '/memberArticle', page: () => const MemberArticlePage()), ]; } diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index ac650278..e50c295c 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -226,21 +226,6 @@ class Utils { } } catch (_) {} - // 向上查找 - if (closestNumber == 0) { - try { - for (int number in numbers) { - int diff = (number - target).abs(); - - if (diff < minDiff) { - minDiff = diff; - closestNumber = number; - return closestNumber; - } - } - } catch (_) {} - } - // 向上查找 if (closestNumber == 0) { try { diff --git a/pubspec.lock b/pubspec.lock index 1eac70f7..b9d48c78 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -129,6 +129,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "4.0.4" + brotli: + dependency: "direct main" + description: + name: brotli + sha256: "7f891558ed779aab2bed874f0a36b8123f9ff3f19cf6efbee89e18ed294945ae" + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.6.0" build: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a13583b7..ac04a1b0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -147,6 +147,10 @@ dependencies: # 二维码 qr_flutter: ^4.1.0 bottom_sheet: ^4.0.4 + web_socket_channel: ^2.4.5 + brotli: ^0.6.0 + # 文本语法高亮 + re_highlight: ^0.0.3 dev_dependencies: flutter_test: @@ -180,20 +184,6 @@ dependency_overrides: url: https://github.com/media-kit/media-kit path: libs/universal/media_kit_libs_video -dependency_overrides: - media_kit: - git: - url: https://github.com/media-kit/media-kit.git - path: media_kit - media_kit_video: - git: - url: https://github.com/media-kit/media-kit.git - path: media_kit_video - media_kit_libs_video: - git: - url: https://github.com/media-kit/media-kit.git - path: libs/universal/media_kit_libs_video - flutter_launcher_icons: android: true ios: true