Skip to content

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

add referer support in plugin

KotaHv47dd0a83609c
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dart
index 7b943a63..60dffe17 100644
--- a/lib/pages/player/player_controller.dart
+++ b/lib/pages/player/player_controller.dart
@@ -97,8 +97,10 @@ abstract class _PlayerController with Store {
userAgent = videoPageController.currentPlugin.userAgent;
}
KazumiLogger().log(Level.info, 'media_kit UA: $userAgent');
+ String referer = videoPageController.currentPlugin.referer;
var httpHeaders = {
'user-agent': userAgent,
+ if (referer.isNotEmpty) 'referer': referer,
};
mediaPlayer = VideoPlayerController.networkUrl(Uri.parse(videoUrl),
httpHeaders: httpHeaders);
diff --git a/lib/pages/plugin_editor/plugin_editor_page.dart b/lib/pages/plugin_editor/plugin_editor_page.dart
index 4f86ecde..fd671b3d 100644
--- a/lib/pages/plugin_editor/plugin_editor_page.dart
+++ b/lib/pages/plugin_editor/plugin_editor_page.dart
@@ -27,6 +27,7 @@ class _PluginEditorPageState extends State<PluginEditorPage> {
final TextEditingController searchResultController = TextEditingController();
final TextEditingController chapterRoadsController = TextEditingController();
final TextEditingController chapterResultController = TextEditingController();
+ final TextEditingController refererController = TextEditingController();
bool muliSources = true;
bool useWebview = true;
bool useNativePlayer = false;
@@ -48,6 +49,7 @@ class _PluginEditorPageState extends State<PluginEditorPage> {
searchResultController.text = plugin.searchResult;
chapterRoadsController.text = plugin.chapterRoads;
chapterResultController.text = plugin.chapterResult;
+ refererController.text = plugin.referer;
muliSources = plugin.muliSources;
useWebview = plugin.useWebview;
useNativePlayer = plugin.useNativePlayer;
@@ -131,6 +133,10 @@ class _PluginEditorPageState extends State<PluginEditorPage> {
controller: userAgentController,
decoration: const InputDecoration(labelText: 'UserAgent'),
),
+ TextField(
+ controller: refererController,
+ decoration: const InputDecoration(labelText: 'Referer'),
+ ),
],
),
],
@@ -155,6 +161,7 @@ class _PluginEditorPageState extends State<PluginEditorPage> {
plugin.useWebview = useWebview;
plugin.useNativePlayer = useNativePlayer;
plugin.usePost = usePost;
+ plugin.referer = refererController.text;
await pluginsController.savePluginToJsonFile(plugin);
await pluginsController.loadPlugins();
Navigator.of(context).pop();
diff --git a/lib/plugins/plugins.dart b/lib/plugins/plugins.dart
index 5416ca74..805f3ec6 100644
--- a/lib/plugins/plugins.dart
+++ b/lib/plugins/plugins.dart
@@ -24,6 +24,7 @@ class Plugin {
String searchResult;
String chapterRoads;
String chapterResult;
+ String referer;
Plugin({
required this.api,
@@ -42,6 +43,7 @@ class Plugin {
required this.searchResult,
required this.chapterRoads,
required this.chapterResult,
+ required this.referer,
});
factory Plugin.fromJson(Map<String, dynamic> json) {
@@ -61,7 +63,8 @@ class Plugin {
searchName: json['searchName'],
searchResult: json['searchResult'],
chapterRoads: json['chapterRoads'],
- chapterResult: json['chapterResult']);
+ chapterResult: json['chapterResult'],
+ referer: json['referer'] ?? '');
}
factory Plugin.fromTemplate() {
@@ -81,7 +84,8 @@ class Plugin {
searchName: '',
searchResult: '',
chapterRoads: '',
- chapterResult: '');
+ chapterResult: '',
+ referer: '');
}
Map<String, dynamic> toJson() {
@@ -102,12 +106,13 @@ class Plugin {
data['searchResult'] = searchResult;
data['chapterRoads'] = chapterRoads;
data['chapterResult'] = chapterResult;
+ data['referer'] = referer;
return data;
}
queryBangumi(String keyword, {bool shouldRethrow = false}) async {
String queryURL = searchURL.replaceAll('@keyword', keyword);
- dynamic resp;
+ dynamic resp;
List<SearchItem> searchItems = [];
if (usePost) {
Uri uri = Uri.parse(queryURL);
@@ -122,13 +127,15 @@ class Plugin {
'Content-Type': 'application/x-www-form-urlencoded',
};
resp = await Request().post(postUri.toString(),
- options: Options(headers: httpHeaders), data: queryParams, shouldRethrow: shouldRethrow);
+ options: Options(headers: httpHeaders),
+ data: queryParams,
+ shouldRethrow: shouldRethrow);
} else {
var httpHeaders = {
'referer': '$baseUrl/',
};
- resp =
- await Request().get(queryURL, options: Options(headers: httpHeaders), shouldRethrow: shouldRethrow);
+ resp = await Request().get(queryURL,
+ options: Options(headers: httpHeaders), shouldRethrow: shouldRethrow);
}
var htmlString = resp.data.toString();