diff --git a/lib/common/widgets/video_card_v.dart b/lib/common/widgets/video_card_v.dart index a461e09e1..6f9ea33fb 100644 --- a/lib/common/widgets/video_card_v.dart +++ b/lib/common/widgets/video_card_v.dart @@ -4,6 +4,7 @@ import 'package:pilipala/common/constants.dart'; import 'package:pilipala/common/widgets/stat/danmu.dart'; import 'package:pilipala/common/widgets/stat/view.dart'; import 'package:pilipala/pages/rcmd/index.dart'; +import 'package:pilipala/utils/id_utils.dart'; import 'package:pilipala/utils/utils.dart'; import 'package:pilipala/pages/home/controller.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; @@ -45,8 +46,8 @@ class VideoCardV extends StatelessWidget { child: InkWell( onTap: () async { await Future.delayed(const Duration(milliseconds: 200)); - print(videoItem.bvid); - Get.toNamed('/video?bvid=${videoItem.bvid}&cid=${videoItem.cid}', + String bvid = videoItem.bvid ?? IdUtils.av2bv(videoItem.aid); + Get.toNamed('/video?bvid=$bvid&cid=${videoItem.cid}', arguments: {'videoItem': videoItem, 'heroTag': heroTag}); }, child: Column( @@ -79,20 +80,22 @@ class VideoCardV extends StatelessWidget { height: maxHeight, ), ), - Positioned( - left: 0, - right: 0, - bottom: 0, - child: AnimatedOpacity( - opacity: 1, - duration: const Duration(milliseconds: 200), - child: VideoStat( - view: videoItem.stat.view, - danmaku: videoItem.stat.danmaku, - duration: videoItem.duration, + if (videoItem.stat.view is int && + videoItem.stat.danmaku is int) + Positioned( + left: 0, + right: 0, + bottom: 0, + child: AnimatedOpacity( + opacity: 1, + duration: const Duration(milliseconds: 200), + child: VideoStat( + view: videoItem.stat.view, + danmaku: videoItem.stat.danmaku, + duration: videoItem.duration, + ), ), ), - ), ], ); }), @@ -137,7 +140,8 @@ class VideoContent extends StatelessWidget { height: 18, child: Row( children: [ - if (videoItem.rcmdReason.content != '') ...[ + if (videoItem.rcmdReason != null && + videoItem.rcmdReason.content != '') ...[ Container( padding: const EdgeInsets.fromLTRB(3, 1, 3, 1), decoration: BoxDecoration( diff --git a/lib/http/api.dart b/lib/http/api.dart index 5707ca05b..b8805cc44 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -1,7 +1,7 @@ class Api { // 推荐视频 - // static const String recommendList = - // 'https://app.bilibili.com/x/v2/feed/index?appkey=27eb53fc9058f8c3'; + static const String recommendListApp = + 'https://app.bilibili.com/x/v2/feed/index'; static const String recommendList = '/x/web-interface/index/top/feed/rcmd'; // 热门视频 diff --git a/lib/http/init.dart b/lib/http/init.dart index 925b56334..08c73b396 100644 --- a/lib/http/init.dart +++ b/lib/http/init.dart @@ -4,6 +4,8 @@ import 'dart:io'; import 'dart:async'; import 'package:dio/dio.dart'; import 'package:cookie_jar/cookie_jar.dart'; +import 'package:hive/hive.dart'; +import 'package:pilipala/utils/storage.dart'; import 'package:pilipala/utils/utils.dart'; import 'package:pilipala/http/constants.dart'; import 'package:pilipala/http/interceptor.dart'; @@ -88,10 +90,14 @@ class Request { "app-key": 'android', "x-bili-aurora-eid": 'UlMFQVcABlAH', "x-bili-aurora-zone": 'sh001', - // "x-bili-mid": '' + 'referer': 'https://www.bilibili.com/', }, ); + Box user = GStrorage.user; + if (user.get(UserBoxKey.userMid) != null) { + options.headers['x-bili-mid'] = user.get(UserBoxKey.userMid).toString(); + } dio.options = options; //添加拦截器 diff --git a/lib/http/video.dart b/lib/http/video.dart index 50b78e94a..48b99ec62 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -3,6 +3,7 @@ import 'dart:developer'; import 'package:pilipala/http/api.dart'; import 'package:pilipala/http/init.dart'; import 'package:pilipala/models/common/reply_type.dart'; +import 'package:pilipala/models/home/rcmd/result.dart'; import 'package:pilipala/models/model_hot_video_item.dart'; import 'package:pilipala/models/model_rec_video_item.dart'; import 'package:pilipala/models/user/fav_folder.dart'; @@ -20,9 +21,11 @@ class VideoHttp { var res = await Request().get( Api.recommendList, data: { + 'version': 1, 'feed_version': 'V3', 'ps': ps, 'fresh_idx': freshIdx, + 'fresh_type': 999999 }, ); if (res.data['code'] == 0) { @@ -39,6 +42,35 @@ class VideoHttp { } } + static Future rcmdVideoListApp( + {required int ps, required int freshIdx}) async { + try { + var res = await Request().get( + Api.recommendListApp, + data: { + 'idx': freshIdx, + 'flush': '5', + 'column': '4', + 'device': 'pad', + 'device_type': 0, + 'device_name': 'vivo', + 'pull': freshIdx == 0 ? 'true' : 'false', + }, + ); + if (res.data['code'] == 0) { + List list = []; + for (var i in res.data['data']['items']) { + list.add(RecVideoItemAppModel.fromJson(i)); + } + return {'status': true, 'data': list}; + } else { + return {'status': false, 'data': [], 'msg': ''}; + } + } catch (err) { + return {'status': false, 'data': [], 'msg': err.toString()}; + } + } + // 最热视频 static Future hotVideoList({required int pn, required int ps}) async { try { diff --git a/lib/models/home/rcmd/result.dart b/lib/models/home/rcmd/result.dart new file mode 100644 index 000000000..592d7edb9 --- /dev/null +++ b/lib/models/home/rcmd/result.dart @@ -0,0 +1,65 @@ +class RecVideoItemAppModel { + RecVideoItemAppModel({ + this.id, + this.aid, + this.bvid, + this.cid, + this.pic, + this.stat, + this.duration, + this.title, + this.isFollowed, + this.owner, + this.rcmdReason, + }); + + int? id; + int? aid; + int? bvid; + int? cid; + String? pic; + Stat? stat; + int? duration; + String? title; + int? isFollowed; + Owner? owner; + String? rcmdReason; + + RecVideoItemAppModel.fromJson(Map json) { + id = json['player_args']['aid']; + aid = json['player_args']['aid']; + cid = json['player_args']['cid']; + pic = json['cover']; + stat = Stat.fromJson(json); + duration = json['player_args']['duration']; + title = json['title']; + isFollowed = 0; + owner = Owner.fromJson(json); + } +} + +class Stat { + Stat({ + this.view, + this.like, + this.danmaku, + }); + String? view; + String? like; + String? danmaku; + + Stat.fromJson(Map json) { + view = json["cover_left_text_1"]; + danmaku = json['cover_left_text_2']; + } +} + +class Owner { + Owner({this.name}); + + String? name; + + Owner.fromJson(Map json) { + name = json['args']['up_name']; + } +} diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 25edb1c42..a0eaae4d8 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -166,7 +166,7 @@ class _DynamicsPageState extends State bottom: 0, child: Align( alignment: Alignment.center, - child: user.get(UserBoxKey.userLogin) + child: user.get(UserBoxKey.userLogin) ?? false ? GestureDetector( onTap: () => showModalBottomSheet( context: context, diff --git a/lib/pages/home/controller.dart b/lib/pages/home/controller.dart index 05ecefb86..e154fc0d3 100644 --- a/lib/pages/home/controller.dart +++ b/lib/pages/home/controller.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:pilipala/pages/hot/index.dart'; +import 'package:pilipala/pages/live/index.dart'; import 'package:pilipala/pages/rcmd/index.dart'; class HomeController extends GetxController with GetTickerProviderStateMixin { @@ -34,7 +35,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { int initialIndex = 1; late TabController tabController; List ctrList = [ - '', + Get.find, Get.find, Get.find, ]; diff --git a/lib/pages/member/controller.dart b/lib/pages/member/controller.dart index 66db2de4c..54c236984 100644 --- a/lib/pages/member/controller.dart +++ b/lib/pages/member/controller.dart @@ -18,7 +18,7 @@ class MemberController extends GetxController { void onInit() { super.onInit(); mid = int.parse(Get.parameters['mid']!); - ownerMid = user.get(UserBoxKey.userMid); + ownerMid = user.get(UserBoxKey.userMid) ?? -1; face = Get.arguments['face'] ?? ''; heroTag = Get.arguments['heroTag'] ?? ''; } diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index 7def4799c..4d0cba91c 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -4,11 +4,13 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_meedu_media_kit/meedu_player.dart'; import 'package:get/get.dart'; +import 'package:hive/hive.dart'; import 'package:pilipala/http/constants.dart'; import 'package:pilipala/http/video.dart'; import 'package:pilipala/models/video/play/url.dart'; import 'package:pilipala/models/video/reply/item.dart'; import 'package:pilipala/pages/video/detail/replyReply/index.dart'; +import 'package:pilipala/utils/storage.dart'; class VideoDetailController extends GetxController with GetSingleTickerProviderStateMixin { @@ -50,6 +52,7 @@ class VideoDetailController extends GetxController Timer? timer; RxString bgCover = ''.obs; + Box user = GStrorage.user; @override void onInit() { @@ -140,6 +143,9 @@ class VideoDetailController extends GetxController } void markHeartBeat() async { + if (user.get(UserBoxKey.userMid) == null) { + return; + } Duration progress = meeduPlayerController.position.value; await VideoHttp.heartBeat( bvid: bvid, diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 186296091..db097dcc6 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -324,8 +324,11 @@ class VideoIntroController extends GetxController { // 关注/取关up Future actionRelationMod() async { + if (user.get(UserBoxKey.userMid) == null) { + SmartDialog.showToast('账号未登录'); + return; + } int currentStatus = followStatus['attribute']; - print(currentStatus); int actionStatus = 0; switch (currentStatus) { case 0: diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 1eb226653..3af637923 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -423,7 +423,11 @@ class _VideoInfoState extends State with TickerProviderStateMixin { ? '关注' : '已关注'), ) - : const SizedBox(), + : ElevatedButton( + onPressed: () => videoIntroController + .actionRelationMod(), + child: const Text('关注'), + ), ), ), ),