Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

remove unused code

Predidit54d5bdf13bef
diff --git a/lib/pages/plugin_editor/plugin_view_page.dart b/lib/pages/plugin_editor/plugin_view_page.dart
index 64007aa8..47aa4999 100644
--- a/lib/pages/plugin_editor/plugin_view_page.dart
+++ b/lib/pages/plugin_editor/plugin_view_page.dart
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/utils/utils.dart';
@@ -169,7 +170,8 @@ class _PluginViewPageState extends State<PluginViewPage> {
pluginsController.pluginList[index]);
} else if (result == 'Share') {
SmartDialog.show(
- animationTime: const Duration(milliseconds: 100),
+ animationTime:
+ const Duration(milliseconds: 100),
builder: (context) {
return AlertDialog(
title: const Text('规则链接'),
@@ -195,11 +197,12 @@ class _PluginViewPageState extends State<PluginViewPage> {
),
TextButton(
onPressed: () {
- Utils.copyToClipboard(
- Utils.jsonToKazumiBase64(json
- .encode(pluginsController
- .pluginList[index]
- .toJson())));
+ Clipboard.setData(ClipboardData(
+ text: Utils.jsonToKazumiBase64(
+ json.encode(
+ pluginsController
+ .pluginList[index]
+ .toJson()))));
SmartDialog.dismiss();
},
child: const Text('复制到剪贴板'),
diff --git a/lib/utils/parser.dart b/lib/utils/parser.dart
deleted file mode 100644
index 42e68341..00000000
--- a/lib/utils/parser.dart
+++ /dev/null
@@ -1,73 +0,0 @@
-import 'package:html/parser.dart' show parse;
-import 'package:flutter/material.dart' show debugPrint;
-import 'dart:core';
-
-// 弃用
-class ParserWithoutWebview {
- static String extractM3U8Links(dynamic htmlContent) {
- debugPrint('开始解析 m3u8');
- var document = parse(htmlContent);
- // 匹配以http或https开头,后跟任意字符,然后是.m3u8的链接
- RegExp regExp = RegExp(r'(http[s]?://.*?\.m3u8)');
- // 匹配任何URL参数中的.m3u8链接
- RegExp paramRegExp = RegExp(r'(\?|\&)([^=]+)=([^&]*\.m3u8)');
-
- List<String> m3u8Urls = [];
- document.body!.querySelectorAll('*').forEach((element) {
- element.attributes.forEach((name, value) {
- var matches = regExp.allMatches(value);
- for (var match in matches) {
- var m3u8Url = match.group(0);
- if (m3u8Url!.contains('?')) {
- debugPrint('m3u8链接为URL参数');
- var paramMatches = paramRegExp.allMatches(m3u8Url);
- for (var paramMatch in paramMatches) {
- // 提取参数中的.m3u8链接
- var paramString = paramMatch.group(3);
- if (paramString != null && paramString.endsWith('.m3u8')) {
- m3u8Url = Uri.decodeComponent(paramString);
- m3u8Urls.add(m3u8Url);
- }
- }
- } else {
- m3u8Urls.add(m3u8Url);
- }
- }
- });
- });
- return m3u8Urls[0];
- }
-
- static String extractMP4Links(dynamic htmlContent) {
- var document = parse(htmlContent);
- // 匹配以http或https开头,后跟任意字符,然后是.mp4的链接
- RegExp regExp = RegExp(r'(http[s]?://.*?\.mp4)');
- // 匹配任何URL参数中的.mp4链接
- RegExp paramRegExp = RegExp(r'(\?|\&)([^=]+)=([^&]*\.mp4)');
-
- List<String> mp4Urls = [];
- document.body!.querySelectorAll('*').forEach((element) {
- element.attributes.forEach((name, value) {
- var matches = regExp.allMatches(value);
- for (var match in matches) {
- var mp4Url = match.group(0);
- // 检查.mp4链接是否为URL参数
- if (mp4Url!.contains('?')) {
- var paramMatches = paramRegExp.allMatches(mp4Url);
- for (var paramMatch in paramMatches) {
- // 提取参数中的.mp4链接
- var paramString = paramMatch.group(3);
- if (paramString != null && paramString.endsWith('.mp4')) {
- mp4Url = Uri.decodeComponent(paramString);
- mp4Urls.add(mp4Url);
- }
- }
- } else {
- mp4Urls.add(mp4Url);
- }
- }
- });
- });
- return mp4Urls[0];
- }
-}
diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart
index 03bd2c07..17fc649d 100644
--- a/lib/utils/utils.dart
+++ b/lib/utils/utils.dart
@@ -3,12 +3,10 @@ import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:dio/dio.dart';
-import 'package:crypto/crypto.dart';
import 'package:hive/hive.dart';
import 'package:kazumi/utils/storage.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:kazumi/request/api.dart';
import 'package:screen_pixel/screen_pixel.dart';
import 'package:kazumi/utils/constants.dart';
@@ -67,32 +65,6 @@ class Utils {
return screenInfo;
}
- static Future<String> getCookiePath() async {
- final Directory tempDir = await getApplicationSupportDirectory();
- final String tempPath = "${tempDir.path}/.plpl/";
- final Directory dir = Directory(tempPath);
- final bool b = await dir.exists();
- if (!b) {
- dir.createSync(recursive: true);
- }
- return tempPath;
- }
-
- static String numFormat(dynamic number) {
- if (number == null) {
- return '0';
- }
- if (number is String) {
- return number;
- }
- final String res = (number / 10000).toString();
- if (int.parse(res.split('.')[0]) >= 1) {
- return '${(number / 10000).toStringAsFixed(1)}万';
- } else {
- return number.toString();
- }
- }
-
// 从URL参数中解析 m3u8/mp4
static String decodeVideoSource(String iframeUrl) {
var decodedUrl = Uri.decodeFull(iframeUrl);
@@ -113,27 +85,6 @@ class Utils {
return Uri.encodeFull(matchedUrl);
}
- static String timeFormat(dynamic time) {
- // 1小时内
- if (time is String && time.contains(':')) {
- return time;
- }
- if (time < 3600) {
- final int minute = time ~/ 60;
- final double res = time / 60;
- if (minute != res) {
- return '${minute < 10 ? '0$minute' : minute}:${(time - minute * 60) < 10 ? '0${(time - minute * 60)}' : (time - minute * 60)}';
- } else {
- return '$minute:00';
- }
- } else {
- final int hour = time ~/ 3600;
- final String hourStr = hour < 10 ? '0$hour' : hour.toString();
- var a = timeFormat(time - hour * 3600);
- return '$hourStr:$a';
- }
- }
-
// 完全相对时间显示
static String formatTimestampToRelativeTime(timeStamp) {
var difference = DateTime.now()
@@ -254,36 +205,6 @@ class Utils {
return v.toString() + random.nextInt(9999).toString();
}
- static int duration(String duration) {
- List timeList = duration.split(':');
- int len = timeList.length;
- if (len == 2) {
- return int.parse(timeList[0]) * 60 + int.parse(timeList[1]);
- }
- if (len == 3) {
- return int.parse(timeList[0]) * 3600 +
- int.parse(timeList[1]) * 60 +
- int.parse(timeList[2]);
- }
- return 0;
- }
-
- static int findClosestNumber(int target, List<int> numbers) {
- int minDiff = 127;
- late int closestNumber;
- try {
- for (int number in numbers) {
- int diff = (number - target).abs();
-
- if (diff < minDiff) {
- minDiff = diff;
- closestNumber = number;
- }
- }
- } catch (_) {}
- return closestNumber;
- }
-
// 版本对比
static bool needUpdate(localVersion, remoteVersion) {
List<String> localVersionList = localVersion.split('.');
@@ -300,17 +221,6 @@ class Utils {
return false;
}
- // 时间戳转时间
- static tampToSeektime(number) {
- int hours = number ~/ 60;
- int minutes = number % 60;
-
- String formattedHours = hours.toString().padLeft(2, '0');
- String formattedMinutes = minutes.toString().padLeft(2, '0');
-
- return '$formattedHours:$formattedMinutes';
- }
-
// 日期字符串转换为 weekday (eg: 2024-09-23 -> 1 (星期一))
static int dateStringToWeekday(String dateString) {
try {
@@ -321,56 +231,6 @@ class Utils {
}
}
- static String appSign(
- Map<String, dynamic> params, String appkey, String appsec) {
- params['appkey'] = appkey;
- var searchParams = Uri(queryParameters: params).query;
- var sortedParams = searchParams.split('&')..sort();
- var sortedQueryString = sortedParams.join('&');
-
- var appsecString = sortedQueryString + appsec;
- var md5Digest = md5.convert(utf8.encode(appsecString));
- var md5String = md5Digest.toString(); // 获取MD5哈希值
-
- return md5String;
- }
-
- static List<int> generateRandomBytes(int minLength, int maxLength) {
- return List<int>.generate(random.nextInt(maxLength - minLength + 1),
- (_) => random.nextInt(0x60) + 0x20);
- }
-
- static String base64EncodeRandomString(int minLength, int maxLength) {
- List<int> randomBytes = generateRandomBytes(minLength, maxLength);
- return base64.encode(randomBytes);
- }
-
- static String jsonToWebVTT(Map<String, dynamic> json) {
- var webvttContent = 'WEBVTT FILE\n\n';
- int i = 1;
- for (var entry in json['body']) {
- final startTime = formatTime(entry['from']);
- final endTime = formatTime(entry['to']);
- final content = entry['content'];
- webvttContent += '${i.toString()}\n$startTime --> $endTime\n$content\n\n';
- i = i + 1;
- }
- return webvttContent;
- }
-
- static String formatTime(double seconds) {
- if (seconds <= 0) {
- return '00:00';
- }
- final hours = seconds ~/ 3600;
- final minutes = (seconds % 3600) ~/ 60;
- final secs = seconds % 60;
- if (hours == 0) {
- return '${minutes.toString().padLeft(2, '0')}:${secs.floor().toString().padLeft(2, '0')}';
- }
- return '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${secs.floor().toString().padLeft(2, '0')}';
- }
-
static String jsonToKazumiBase64(String jsonStr) {
String base64Str = base64Encode(utf8.encode(jsonStr));
return 'kazumi://$base64Str';
@@ -385,10 +245,6 @@ class Utils {
return jsonStr;
}
- static void copyToClipboard(String text) {
- Clipboard.setData(ClipboardData(text: text));
- }
-
static String durationToString(Duration duration) {
String pad(int n) => n.toString().padLeft(2, '0');
var hours = pad(duration.inHours % 24);
@@ -428,11 +284,6 @@ class Utils {
);
}
- static String getBaseUrl(String url) {
- Uri uri = Uri.parse(url);
- return '${uri.scheme}://${uri.host}';
- }
-
static generateDanmakuColor(int colorValue) {
// 提取颜色分量
int red = (colorValue >> 16) & 0xFF;