基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat: add staff card
Predidit27043a48d564
diff --git a/lib/bean/card/staff_card.dart b/lib/bean/card/staff_card.dartnew file mode 100644index 00000000..a10c3a05--- /dev/null+++ b/lib/bean/card/staff_card.dart@@ -0,0 +1,31 @@+import 'package:flutter/material.dart';+import 'package:kazumi/modules/staff/staff_item.dart';++class StaffCard extends StatelessWidget {+ const StaffCard({+ super.key,+ required this.staffFullItem,+ });++ final StaffFullItem staffFullItem;++ @override+ Widget build(BuildContext context) {+ return ListTile(+ leading: CircleAvatar(+ backgroundImage: staffFullItem.staff.images?.grid == null ? null : NetworkImage(staffFullItem.staff.images!.grid),+ ),+ title: Text(+ staffFullItem.staff.name,+ overflow: TextOverflow.ellipsis,+ maxLines: 1,+ ),+ subtitle: staffFullItem.staff.nameCN.isNotEmpty+ ? Text(staffFullItem.staff.nameCN)+ : null,+ trailing: Text(staffFullItem.positions.isNotEmpty+ ? (staffFullItem.positions[0].type.cn)+ : ''),+ );+ }+}diff --git a/lib/modules/staff/staff_item.dart b/lib/modules/staff/staff_item.dartnew file mode 100644index 00000000..7b280a16--- /dev/null+++ b/lib/modules/staff/staff_item.dart@@ -0,0 +1,201 @@+class StaffFullItem {+ final Staff staff;+ final List<Position> positions;++ StaffFullItem({+ required this.staff,+ required this.positions,+ });++ factory StaffFullItem.fromJson(Map<String, dynamic> json) {+ return StaffFullItem(+ staff: json['staff'] != null+ ? Staff.fromJson(json['staff'] as Map<String, dynamic>)+ : Staff.fromTemplate(),+ positions: (json['positions'] as List<dynamic>? ?? [])+ .map((item) => Position.fromJson(item as Map<String, dynamic>))+ .toList(),+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'staff': staff.toJson(),+ 'positions': positions.map((item) => item.toJson()).toList(),+ };+ }+}++class Staff {+ final int id;+ final String name;+ final String nameCN;+ final int type;+ final String info;+ final int comment;+ final bool lock;+ final bool nsfw;+ final Images? images;++ Staff({+ required this.id,+ required this.name,+ required this.nameCN,+ required this.type,+ required this.info,+ required this.comment,+ required this.lock,+ required this.nsfw,+ this.images,+ });++ factory Staff.fromJson(Map<String, dynamic> json) {+ return Staff(+ id: json['id'] is int ? json['id'] as int : 0,+ name: json['name'] as String? ?? '',+ nameCN: json['nameCN'] as String? ?? '',+ type: json['type'] is int ? json['type'] as int : 0,+ info: json['info'] as String? ?? '',+ comment: json['comment'] is int ? json['comment'] as int : 0,+ lock: json['lock'] as bool? ?? false,+ nsfw: json['nsfw'] as bool? ?? false,+ images: json['images'] != null+ ? Images.fromJson(json['images'] as Map<String, dynamic>)+ : null,+ );+ }++ factory Staff.fromTemplate() {+ return Staff(+ id: 0,+ name: '',+ nameCN: '',+ type: 0,+ info: '',+ comment: 0,+ lock: false,+ nsfw: false,+ images: null,+ );+ }++ Map<String, dynamic> toJson() {+ final data = <String, dynamic>{+ 'id': id,+ 'name': name,+ 'nameCN': nameCN,+ 'type': type,+ 'info': info,+ 'comment': comment,+ 'lock': lock,+ 'nsfw': nsfw,+ };+ if (images != null) {+ data['images'] = images!.toJson();+ }+ return data;+ }+}++class Images {+ final String large;+ final String medium;+ final String small;+ final String grid;++ Images({+ required this.large,+ required this.medium,+ required this.small,+ required this.grid,+ });++ factory Images.fromJson(Map<String, dynamic> json) {+ return Images(+ large: json['large'] as String? ?? '',+ medium: json['medium'] as String? ?? '',+ small: json['small'] as String? ?? '',+ grid: json['grid'] as String? ?? '',+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'large': large,+ 'medium': medium,+ 'small': small,+ 'grid': grid,+ };+ }+}++class Position {+ final PositionType type;+ final String summary;+ final String appearEps;++ Position({+ required this.type,+ required this.summary,+ required this.appearEps,+ });++ factory Position.fromJson(Map<String, dynamic> json) {+ return Position(+ type: json['type'] != null+ ? PositionType.fromJson(json['type'] as Map<String, dynamic>)+ : PositionType.fromTemplate(),+ summary: json['summary'] as String? ?? '',+ appearEps: json['appearEps'] as String? ?? '',+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'type': type.toJson(),+ 'summary': summary,+ 'appearEps': appearEps,+ };+ }+}++class PositionType {+ final int id;+ final String en;+ final String cn;+ final String jp;++ PositionType({+ required this.id,+ required this.en,+ required this.cn,+ required this.jp,+ });++ factory PositionType.fromJson(Map<String, dynamic> json) {+ return PositionType(+ id: json['id'] is int ? json['id'] as int : 0,+ en: json['en'] as String? ?? '',+ cn: json['cn'] as String? ?? '',+ jp: json['jp'] as String? ?? '',+ );+ }++ factory PositionType.fromTemplate() {+ return PositionType(+ id: 0,+ en: '',+ cn: '',+ jp: '',+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'id': id,+ 'en': en,+ 'cn': cn,+ 'jp': jp,+ };+ }+}\ No newline at end of filediff --git a/lib/modules/staff/staff_response.dart b/lib/modules/staff/staff_response.dartnew file mode 100644index 00000000..a1dbda07--- /dev/null+++ b/lib/modules/staff/staff_response.dart@@ -0,0 +1,34 @@+import 'package:kazumi/modules/staff/staff_item.dart';++class StaffResponse {+ final List<StaffFullItem> data;+ final int total;++ StaffResponse({+ required this.data,+ required this.total,+ });++ factory StaffResponse.fromJson(Map<String, dynamic> json) {+ return StaffResponse(+ data: (json['data'] as List<dynamic>? ?? [])+ .map((item) => StaffFullItem.fromJson(item as Map<String, dynamic>))+ .toList(),+ total: json['total'] is int ? json['total'] as int : 0,+ );+ }++ factory StaffResponse.fromTemplate() {+ return StaffResponse(+ data: [],+ total: 0,+ );+ }++ Map<String, dynamic> toJson() {+ return {+ 'data': data.map((item) => item.toJson()).toList(),+ 'total': total,+ };+ }+}diff --git a/lib/pages/info/info_controller.dart b/lib/pages/info/info_controller.dartindex b1e7b02c..c6d3789f 100644--- a/lib/pages/info/info_controller.dart+++ b/lib/pages/info/info_controller.dart@@ -13,6 +13,7 @@ import 'package:kazumi/utils/logger.dart';import 'package:kazumi/modules/comments/comment_item.dart';import 'package:kazumi/modules/characters/character_item.dart';import 'package:kazumi/modules/bangumi/episode_item.dart';+import 'package:kazumi/modules/staff/staff_item.dart';part 'info_controller.g.dart';@@ -41,6 +42,9 @@ abstract class _InfoController with Store {@observablevar characterList = ObservableList<CharacterItem>();+ @observable+ var staffList = ObservableList<StaffFullItem>();+Future<void> queryBangumiInfoByID(int id, {String type = "init"}) async {isLoading = true;await BangumiHTTP.getBangumiInfoByID(id).then((value) {@@ -120,4 +124,12 @@ abstract class _InfoController with Store {}KazumiLogger().log(Level.info, '已加载角色列表长度 ${characterList.length}');}++ Future<void> queryBangumiStaffsByID(int id) async {+ staffList.clear();+ await BangumiHTTP.getBangumiStaffByID(id).then((value) {+ staffList.addAll(value.data);+ });+ KazumiLogger().log(Level.info, '已加载制作人员列表长度 ${staffList.length}');+ }}diff --git a/lib/pages/info/info_controller.g.dart b/lib/pages/info/info_controller.g.dartindex f0144b8e..13d712fe 100644--- a/lib/pages/info/info_controller.g.dart+++ b/lib/pages/info/info_controller.g.dart@@ -106,6 +106,22 @@ mixin _$InfoController on _InfoController, Store {});}+ late final _$staffListAtom =+ Atom(name: '_InfoController.staffList', context: context);++ @override+ ObservableList<StaffFullItem> get staffList {+ _$staffListAtom.reportRead();+ return super.staffList;+ }++ @override+ set staffList(ObservableList<StaffFullItem> value) {+ _$staffListAtom.reportWrite(value, super.staffList, () {+ super.staffList = value;+ });+ }+@overrideString toString() {return '''@@ -114,7 +130,8 @@ pluginSearchResponseList: ${pluginSearchResponseList},pluginSearchStatus: ${pluginSearchStatus},commentsList: ${commentsList},episodeCommentsList: ${episodeCommentsList},-characterList: ${characterList}+characterList: ${characterList},+staffList: ${staffList}''';}}diff --git a/lib/pages/info/info_page.dart b/lib/pages/info/info_page.dartindex fcacf7b4..cc0dc4e1 100644--- a/lib/pages/info/info_page.dart+++ b/lib/pages/info/info_page.dart@@ -27,8 +27,7 @@ class InfoPage extends StatefulWidget {State<InfoPage> createState() => _InfoPageState();}-class _InfoPageState extends State<InfoPage>- with TickerProviderStateMixin {+class _InfoPageState extends State<InfoPage> with TickerProviderStateMixin {final InfoController infoController = Modular.get<InfoController>();final VideoPageController videoPageController =Modular.get<VideoPageController>();@@ -40,6 +39,8 @@ class _InfoPageState extends State<InfoPage>bool charactersIsLoading = false;bool commentsQueryTimeout = false;bool charactersQueryTimeout = false;+ bool staffIsLoading = false;+ bool staffQueryTimeout = false;Future<void> loadCharacters() async {if (charactersIsLoading) return;@@ -64,6 +65,29 @@ class _InfoPageState extends State<InfoPage>});}+ Future<void> loadStaff() async {+ if (staffIsLoading) return;+ setState(() {+ staffIsLoading = true;+ staffQueryTimeout = false;+ });+ infoController+ .queryBangumiStaffsByID(infoController.bangumiItem.id)+ .then((_) {+ if (infoController.staffList.isEmpty && mounted) {+ setState(() {+ staffIsLoading = false;+ staffQueryTimeout = true;+ });+ }+ if (infoController.staffList.isNotEmpty && mounted) {+ setState(() {+ staffIsLoading = false;+ });+ }+ });+ }+Future<void> loadMoreComments({int offset = 0}) async {if (commentsIsLoading) return;setState(() {@@ -101,7 +125,6 @@ class _InfoPageState extends State<InfoPage>TabController(length: pluginsController.pluginList.length, vsync: this);infoTabController = TabController(length: 5, vsync: this);infoTabController.addListener(() {- if (infoTabController.indexIsChanging) return;int index = infoTabController.index;if (index == 1 &&infoController.commentsList.isEmpty &&@@ -113,6 +136,9 @@ class _InfoPageState extends State<InfoPage>!charactersIsLoading) {loadCharacters();}+ if (index == 4 && infoController.staffList.isEmpty && !staffIsLoading) {+ loadStaff();+ }});}@@ -120,6 +146,7 @@ class _InfoPageState extends State<InfoPage>void dispose() {infoController.characterList.clear();infoController.commentsList.clear();+ infoController.staffList.clear();infoController.pluginSearchResponseList.clear();videoPageController.currentEpisode = 1;sourceTabController.dispose();@@ -291,23 +318,25 @@ class _InfoPageState extends State<InfoPage>),];},- body: Observer(- builder: (context) {- return InfoTabView(- tabController: infoTabController,- bangumiItem: infoController.bangumiItem,- commentsIsLoading: commentsIsLoading,- charactersIsLoading: charactersIsLoading,- commentsQueryTimeout: commentsQueryTimeout,- charactersQueryTimeout: charactersQueryTimeout,- loadMoreComments: loadMoreComments,- loadCharacters: loadCharacters,- commentsList: infoController.commentsList,- characterList: infoController.characterList,- isLoading: infoController.isLoading,- );- }- ),+ body: Observer(builder: (context) {+ return InfoTabView(+ tabController: infoTabController,+ bangumiItem: infoController.bangumiItem,+ commentsIsLoading: commentsIsLoading,+ charactersIsLoading: charactersIsLoading,+ staffIsLoading: staffIsLoading,+ commentsQueryTimeout: commentsQueryTimeout,+ charactersQueryTimeout: charactersQueryTimeout,+ staffQueryTimeout: staffQueryTimeout,+ loadMoreComments: loadMoreComments,+ loadCharacters: loadCharacters,+ loadStaff: loadStaff,+ commentsList: infoController.commentsList,+ characterList: infoController.characterList,+ staffList: infoController.staffList,+ isLoading: infoController.isLoading,+ );+ }),),floatingActionButton: FloatingActionButton.extended(icon: const Icon(Icons.play_arrow_rounded),diff --git a/lib/pages/info/info_tabview.dart b/lib/pages/info/info_tabview.dartindex 9e1a5b0a..aee9f056 100644--- a/lib/pages/info/info_tabview.dart+++ b/lib/pages/info/info_tabview.dart@@ -3,38 +3,48 @@ import 'package:flutter/material.dart';import 'package:kazumi/bean/widget/error_widget.dart';import 'package:kazumi/bean/card/comments_card.dart';import 'package:kazumi/bean/card/character_card.dart';+import 'package:kazumi/bean/card/staff_card.dart';import 'package:kazumi/utils/utils.dart';import 'package:skeletonizer/skeletonizer.dart';import 'package:kazumi/modules/bangumi/bangumi_item.dart';import 'package:kazumi/modules/comments/comment_item.dart';import 'package:kazumi/modules/characters/character_item.dart';+import 'package:kazumi/modules/staff/staff_item.dart';class InfoTabView extends StatefulWidget {const InfoTabView({super.key,required this.commentsIsLoading,required this.charactersIsLoading,+ required this.staffIsLoading,required this.commentsQueryTimeout,required this.charactersQueryTimeout,+ required this.staffQueryTimeout,required this.tabController,required this.loadMoreComments,required this.loadCharacters,+ required this.loadStaff,required this.bangumiItem,required this.commentsList,required this.characterList,+ required this.staffList,required this.isLoading,});final bool commentsIsLoading;final bool charactersIsLoading;+ final bool staffIsLoading;final bool commentsQueryTimeout;final bool charactersQueryTimeout;+ final bool staffQueryTimeout;final TabController tabController;final Future<void> Function({int offset}) loadMoreComments;final Future<void> Function() loadCharacters;+ final Future<void> Function() loadStaff;final BangumiItem bangumiItem;final List<CommentItem> commentsList;final List<CharacterItem> characterList;+ final List<StaffFullItem> staffList;final bool isLoading;@override@@ -198,8 +208,7 @@ class _InfoTabViewState extends State<InfoTabView>onNotification: (scrollEnd) {final metrics = scrollEnd.metrics;if (metrics.pixels >= metrics.maxScrollExtent - 200) {- widget.loadMoreComments(- offset: widget.commentsList.length);+ widget.loadMoreComments(offset: widget.commentsList.length);}return true;},@@ -214,8 +223,7 @@ class _InfoTabViewState extends State<InfoTabView>NestedScrollView.sliverOverlapAbsorberHandleFor(context),),SliverLayoutBuilder(builder: (context, _) {- if (widget.commentsList.isEmpty &&- widget.commentsIsLoading) {+ if (widget.commentsList.isEmpty && widget.commentsIsLoading) {return SliverList.builder(itemCount: 4,itemBuilder: (context, _) {@@ -302,6 +310,81 @@ class _InfoTabViewState extends State<InfoTabView>);}+ Widget get staffListBody {+ return Builder(+ builder: (BuildContext context) {+ return CustomScrollView(+ scrollBehavior: const ScrollBehavior().copyWith(+ scrollbars: false,+ ),+ key: PageStorageKey<String>('制作人员'),+ slivers: <Widget>[+ SliverOverlapInjector(+ handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),+ ),+ SliverLayoutBuilder(builder: (context, _) {+ if (widget.staffList.isEmpty && widget.staffIsLoading) {+ return SliverList.builder(+ itemCount: 8,+ itemBuilder: (context, _) {+ return Align(+ alignment: Alignment.topCenter,+ child: SizedBox(+ width: MediaQuery.sizeOf(context).width > maxWidth+ ? maxWidth+ : MediaQuery.sizeOf(context).width - 32,+ child: Skeletonizer.zone(+ child: ListTile(+ leading: Bone.circle(size: 36),+ title: Bone.text(width: 100),+ subtitle: Bone.text(width: 80),+ ),+ ),+ ),+ );+ },+ );+ }+ if (widget.staffQueryTimeout) {+ return SliverFillRemaining(+ child: GeneralErrorWidget(+ errMsg: '获取失败,请重试',+ actions: [+ GeneralErrorButton(+ onPressed: () {+ widget.loadStaff();+ },+ text: '重试',+ ),+ ],+ ),+ );+ }+ return SliverList.builder(+ itemCount: widget.staffList.length,+ itemBuilder: (context, index) {+ return Center(+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16.0),+ child: SizedBox(+ width: MediaQuery.sizeOf(context).width > maxWidth+ ? maxWidth+ : MediaQuery.sizeOf(context).width - 32,+ child: StaffCard(+ staffFullItem: widget.staffList[index],+ ),+ ),+ ),+ );+ },+ );+ }),+ ],+ );+ },+ );+ }+Widget get charactersListBody {return Builder(builder: (BuildContext context) {@@ -315,8 +398,7 @@ class _InfoTabViewState extends State<InfoTabView>handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),),SliverLayoutBuilder(builder: (context, _) {- if (widget.characterList.isEmpty &&- widget.charactersIsLoading) {+ if (widget.characterList.isEmpty && widget.charactersIsLoading) {return SliverList.builder(itemCount: 4,itemBuilder: (context, _) {@@ -435,26 +517,7 @@ class _InfoTabViewState extends State<InfoTabView>);},),- Builder(- builder: (BuildContext context) {- return CustomScrollView(- scrollBehavior: const ScrollBehavior().copyWith(- scrollbars: false,- ),- key: PageStorageKey<String>('制作人员'),- slivers: <Widget>[- SliverOverlapInjector(- handle:- NestedScrollView.sliverOverlapAbsorberHandleFor(context),- ),- // TODO: 制作人员- SliverFillRemaining(- child: Center(child: Text('施工中')),- ),- ],- );- },- ),+ staffListBody,],);}diff --git a/lib/request/api.dart b/lib/request/api.dartindex 24a4b67f..08e91f65 100644--- a/lib/request/api.dart+++ b/lib/request/api.dart@@ -32,6 +32,7 @@ class Api {static const String characterInfoByCharacterIDNext = 'https://next.bgm.tv/p1/characters/{0}';static const String bangumiEpisodeByIDNext = 'https://next.bgm.tv/p1/episodes/';static const String bangumiCharacterByIDNext = 'https://next.bgm.tv/p1/characters/';+ static const String bangumiStaffByIDNext = 'https://next.bgm.tv/p1/subjects/{0}/staffs/persons';// 弹弹Playstatic const String dandanIndex = 'https://www.dandanplay.com/';static const String dandanAPIDomain = 'https://api.dandanplay.net';diff --git a/lib/request/bangumi.dart b/lib/request/bangumi.dartindex 3908ba70..0d88929e 100644--- a/lib/request/bangumi.dart+++ b/lib/request/bangumi.dart@@ -9,6 +9,7 @@ import 'package:kazumi/modules/comments/comment_response.dart';import 'package:kazumi/modules/characters/characters_response.dart';import 'package:kazumi/modules/bangumi/episode_item.dart';import 'package:kazumi/modules/character/character_full_item.dart';+import 'package:kazumi/modules/staff/staff_response.dart';class BangumiHTTP {// why the api havn't been replaced by getCalendarBySearch?@@ -285,6 +286,20 @@ class BangumiHTTP {return commentResponse;}+ static Future<StaffResponse> getBangumiStaffByID(int id) async {+ StaffResponse staffResponse = StaffResponse.fromTemplate();+ try {+ final res = await Request().get(Api.formatUrl(Api.bangumiStaffByIDNext, [id]),+ options: Options(headers: bangumiHTTPHeader));+ final jsonData = res.data;+ staffResponse = StaffResponse.fromJson(jsonData);+ } catch (e) {+ KazumiLogger()+ .log(Level.error, 'Resolve bangumi staff failed ${e.toString()}');+ }+ return staffResponse;+ }+static Future<CharactersResponse> getCharatersByBangumiID(int id) async {CharactersResponse charactersResponse = CharactersResponse.fromTemplate();try {