基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
add rich text parser, make comments and logs selectable
ErBW_s775157238903
diff --git a/lib/bean/card/episode_comments_card.dart b/lib/bean/card/episode_comments_card.dartindex 3bfb364e..39f68826 100644--- a/lib/bean/card/episode_comments_card.dart+++ b/lib/bean/card/episode_comments_card.dart@@ -1,6 +1,9 @@import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';import 'package:kazumi/modules/comments/comment_item.dart';import 'package:kazumi/utils/utils.dart';+import 'package:styled_text/styled_text.dart';class EpisodeCommentsCard extends StatelessWidget {const EpisodeCommentsCard({@@ -34,7 +37,7 @@ class EpisodeCommentsCard extends StatelessWidget {],),const SizedBox(height: 8),- Text(commentItem.comment.comment),+ commentsWithStyledText(Utils.richTextParser(commentItem.comment.comment), context),(commentItem.replies.isNotEmpty)? ListView.builder(physics: const NeverScrollableScrollPhysics(),@@ -45,7 +48,7 @@ class EpisodeCommentsCard extends StatelessWidget {padding: const EdgeInsets.only(left: 48),child: Column(crossAxisAlignment: CrossAxisAlignment.start,- children: [+ children: <Widget>[Divider(color: Theme.of(context).dividerColor.withAlpha(60)),Row(children: [@@ -66,7 +69,7 @@ class EpisodeCommentsCard extends StatelessWidget {],),const SizedBox(height: 8),- Text(commentItem.replies[index].comment),+ commentsWithStyledText(Utils.richTextParser(commentItem.replies[index].comment), context),]),);})@@ -75,4 +78,80 @@ class EpisodeCommentsCard extends StatelessWidget {),);}++ Widget commentsWithStyledText(String comment, BuildContext context) {+ return StyledText(text: comment, tags: {+ 'b': StyledTextTag(+ style: const TextStyle(fontWeight: FontWeight.bold),+ ),+ 'i': StyledTextTag(+ style: const TextStyle(fontStyle: FontStyle.italic),+ ),+ 'q': StyledTextTag(+ style: TextStyle(color: Theme.of(context).colorScheme.outline),+ ),+ 'format_quote': StyledTextIconTag(+ Icons.format_quote,+ color: Theme.of(context).colorScheme.outline,+ alignment: PlaceholderAlignment.top+ ),+ 's': StyledTextTag(+ style: const TextStyle(decoration: TextDecoration.lineThrough),+ ),+ 'u': StyledTextTag(+ style: const TextStyle(decoration: TextDecoration.underline),+ ),+ 'image': StyledTextWidgetBuilderTag(+ (_, attributes, textContent) {+ return Image.network(+ textContent!,+ errorBuilder: (context, error, stackTrace) {+ return const Text('.');+ },+ );+ },+ ),+ 'link': StyledTextActionTag(+ (_, attrs) {+ _copyLink(attrs);+ },+ style: const TextStyle(color: Colors.blue),+ ),+ 'color': StyledTextCustomTag(+ baseStyle: const TextStyle(fontStyle: FontStyle.normal),+ parse: (baseStyle, attributes) {+ if (attributes.containsKey('color')) {+ final String color = attributes['color']!;+ switch (color) {+ case 'red': return baseStyle?.copyWith(color: Colors.red);+ case 'blue': return baseStyle?.copyWith(color: Colors.blue);+ case 'orange': return baseStyle?.copyWith(color: Colors.orange);+ case 'green': return baseStyle?.copyWith(color: Colors.green);+ case 'grey': return baseStyle?.copyWith(color: Colors.grey);+ default: return baseStyle;+ }+ } else {+ return baseStyle;+ }+ }+ ),+ 'size': StyledTextCustomTag(+ baseStyle: const TextStyle(fontStyle: FontStyle.normal),+ parse: (baseStyle, attributes) {+ if (attributes.containsKey('size')) {+ double size = double.tryParse(attributes['size']!) ?? 14;+ return baseStyle?.copyWith(fontSize: size);+ } else {+ return baseStyle;+ }+ }+ ),+ });+ }++ Future<void> _copyLink(Map<String?, String?> attrs) async {+ final String? link = attrs['href'];+ await Clipboard.setData(ClipboardData(text: link!));+ SmartDialog.showToast('已复制链接到剪贴板');+ }}diff --git a/lib/pages/info/comments_sheet.dart b/lib/pages/info/comments_sheet.dartindex 88f34859..877217be 100644--- a/lib/pages/info/comments_sheet.dart+++ b/lib/pages/info/comments_sheet.dart@@ -89,7 +89,8 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {}Widget get commentsListBody {- return Padding(+ return SelectionArea(+ child: Padding(padding: const EdgeInsets.all(4.0),child: Observer(builder: (context) {if (infoController.commentsList.isEmpty && !commentsQueryTimeout) {@@ -110,11 +111,12 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {commentItem: infoController.commentsList[index]);});}),- );+ ));}Widget get charactersListBody {- return Padding(+ return SelectionArea(+ child: Padding(padding: const EdgeInsets.fromLTRB(4.0, 4.0, 4.0, 4.0),child: Observer(builder: (context) {if (infoController.characterList.isEmpty && !charactersQueryTimeout) {@@ -134,7 +136,7 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {characterItem: infoController.characterList[index]);});}),- );+ ));}@overridediff --git a/lib/pages/logs/logs_page.dart b/lib/pages/logs/logs_page.dartindex 95667176..bb0d9e7a 100644--- a/lib/pages/logs/logs_page.dart+++ b/lib/pages/logs/logs_page.dart@@ -52,7 +52,8 @@ class _LogsPageState extends State<LogsPage> {@overrideWidget build(BuildContext context) {- return Scaffold(+ return SelectionArea(+ child: Scaffold(appBar: const SysAppBar(title: Text('日志'),),@@ -76,6 +77,6 @@ class _LogsPageState extends State<LogsPage> {),],),- );+ ));}}diff --git a/lib/pages/player/episode_comments_sheet.dart b/lib/pages/player/episode_comments_sheet.dartindex 0fd21d91..a62c78a3 100644--- a/lib/pages/player/episode_comments_sheet.dart+++ b/lib/pages/player/episode_comments_sheet.dart@@ -59,7 +59,8 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {}Widget get episodeCommentsBody {- return Padding(+ return SelectionArea(+ child: Padding(padding: const EdgeInsets.fromLTRB(4, 0, 4, 4),child: Observer(builder: (context) {if (isLoading) {@@ -80,7 +81,7 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {commentItem: infoController.episodeCommentsList[index]);});}),- );+ ));}Widget get commentsInfo {diff --git a/lib/utils/utils.dart b/lib/utils/utils.dartindex 5e657546..03bd2c07 100644--- a/lib/utils/utils.dart+++ b/lib/utils/utils.dart@@ -454,6 +454,81 @@ class Utils {return 0;}+ static String richTextParser(String input) {+ RegExp bgmEmoji = RegExp(r'\(bgm(\d+)\)');+ input = input.replaceAllMapped(bgmEmoji, (match) {+ if (match.group(1) == '11' || match.group(1) == '23') {+ return '<image>https://bangumi.tv/img/smiles/bgm/${match.group(1)}.gif</image>';+ }+ int num = int.tryParse(match.group(1)!) ?? 0;+ if (num < 24) {+ return '<image>https://bangumi.tv/img/smiles/bgm/${match.group(1)}.png</image>';+ }+ if (num < 33) {+ return '<image>https://bangumi.tv/img/smiles/tv/0${num - 23}.gif</image>';+ }+ return '<image>https://bangumi.tv/img/smiles/tv/${num - 23}.gif</image>';+ });++ RegExp quote = RegExp(r'\[quote\]([\s\S]*?)\[/quote\]');+ input = input.replaceAllMapped(quote, (match) {+ return '<q>${match.group(1)}</q><format_quote/>';+ });++ RegExp bold = RegExp(r'\[b\]([\s\S]*?)\[/b\]');+ input = input.replaceAllMapped(bold, (match) {+ return '<b>${match.group(1)}</b>';+ });++ RegExp img = RegExp(r'\[img([\s\S]*?)\]([\s\S]*?)\[/img\]');+ input = input.replaceAllMapped(img, (match) {+ return '<image>${match.group(2)}</image>';+ });++ RegExp strikeThrough = RegExp(r'\[s\]([\s\S]*?)\[/s\]');+ input = input.replaceAllMapped(strikeThrough, (match) {+ return '<s>${match.group(1)}</s>';+ });++ RegExp underLine = RegExp(r'\[u\]([\s\S]*?)\[/u\]');+ input = input.replaceAllMapped(underLine, (match) {+ return '<u>${match.group(1)}</u>';+ });++ RegExp italic = RegExp(r'\[i\]([\s\S]*?)\[/i\]');+ input = input.replaceAllMapped(italic, (match) {+ return '<i>${match.group(1)}</i>';+ });++ RegExp ignore = RegExp(r'\[(mask|code)\]([\s\S]*?)\[/\1\]');+ input = input.replaceAllMapped(ignore, (match) {+ return '${match.group(2)}';+ });++ RegExp link = RegExp(r'\[url=([\s\S]*?)\]([\s\S]*?)\[/url\]');+ input = input.replaceAllMapped(link, (match) {+ return '<link href="${match.group(1)}">${match.group(2)}</link>';+ });++ RegExp color = RegExp(r'\[color=([\s\S]*?)\]([\s\S]*?)\[/color\]');+ input = input.replaceAllMapped(color, (match) {+ return '<color color="${match.group(1)}">${match.group(2)}</color>';+ });++ RegExp size = RegExp(r'\[size=(\d+)\]([\s\S]*?)\[/size\]');+ input = input.replaceAllMapped(size, (match) {+ return '<size size="${match.group(1)}">${match.group(2)}</size>';+ });++ // 为了解决一些特殊情况再执行一次+ RegExp secondColor = RegExp(r'\[color=([\s\S]*?)\]([\s\S]*?)\[/color\]');+ input = input.replaceAllMapped(secondColor, (match) {+ return '<color color="${match.group(1)}">${match.group(2)}</color>';+ });++ return input;+ }+/// 判断是否为桌面设备static bool isDesktop() {if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {diff --git a/pubspec.yaml b/pubspec.yamlindex d92ae854..08756205 100644--- a/pubspec.yaml+++ b/pubspec.yaml@@ -84,6 +84,7 @@ dependencies:git:url: https://github.com/Predidit/linux_webview_window.gitref: no_texture+ styled_text: ^8.1.0dev_dependencies:flutter_test: