mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-13 20:53:58 +08:00
@@ -31,7 +31,7 @@ abstract final class DownloadHttp {
|
||||
seasonId: entry.seasonId,
|
||||
epid: ep?.episodeId,
|
||||
qn: entry.preferedVideoQuality,
|
||||
tryLook: !isLogin && Pref.p1080,
|
||||
tryLook: !isLogin,
|
||||
videoType: switch (ep?.from) {
|
||||
'pugv' => VideoType.pugv,
|
||||
!= null when isLogin => VideoType.pgc,
|
||||
|
||||
@@ -19,7 +19,6 @@ import 'package:brotli/brotli.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:dio_http2_adapter/dio_http2_adapter.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
|
||||
class Request {
|
||||
static const _gzipDecoder = GZipDecoder();
|
||||
@@ -116,41 +115,16 @@ class Request {
|
||||
}
|
||||
|
||||
static (IOHttpClientAdapter, ConnectionManager?) _createPool() {
|
||||
final bool enableSystemProxy;
|
||||
late final String systemProxyHost;
|
||||
late final int? systemProxyPort;
|
||||
if (Pref.enableSystemProxy) {
|
||||
systemProxyHost = Pref.systemProxyHost;
|
||||
systemProxyPort = int.tryParse(Pref.systemProxyPort);
|
||||
enableSystemProxy = systemProxyPort != null && systemProxyHost.isNotEmpty;
|
||||
} else {
|
||||
enableSystemProxy = false;
|
||||
}
|
||||
|
||||
final http11Adapter = IOHttpClientAdapter(
|
||||
createHttpClient: enableSystemProxy
|
||||
? () => HttpClient()
|
||||
..idleTimeout = const Duration(seconds: 15)
|
||||
..autoUncompress = false
|
||||
..findProxy = ((_) => 'PROXY $systemProxyHost:$systemProxyPort')
|
||||
..badCertificateCallback = (cert, host, port) => true
|
||||
: () => HttpClient()
|
||||
..idleTimeout = const Duration(seconds: 15)
|
||||
..autoUncompress = false, // Http2Adapter没有自动解压, 统一行为
|
||||
createHttpClient: () => HttpClient()
|
||||
..idleTimeout = const Duration(seconds: 15)
|
||||
..autoUncompress = false, // Http2Adapter没有自动解压, 统一行为
|
||||
);
|
||||
|
||||
final connectionManager = _enableHttp2
|
||||
? ConnectionManager(
|
||||
idleTimeout: const Duration(seconds: 15),
|
||||
onClientCreate: enableSystemProxy
|
||||
? (_, config) => config
|
||||
..proxy = Uri(
|
||||
scheme: 'http',
|
||||
host: systemProxyHost,
|
||||
port: systemProxyPort,
|
||||
)
|
||||
..onBadCertificate = (_) => true
|
||||
: Pref.badCertificateCallback
|
||||
onClientCreate: Pref.badCertificateCallback
|
||||
? (_, config) => config.onBadCertificate = (_) => true
|
||||
: null,
|
||||
)
|
||||
@@ -195,15 +169,15 @@ class Request {
|
||||
}
|
||||
|
||||
// 日志拦截器 输出请求、响应内容
|
||||
if (kDebugMode) {
|
||||
dio.interceptors.add(
|
||||
LogInterceptor(
|
||||
request: false,
|
||||
requestHeader: false,
|
||||
responseHeader: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
// if (kDebugMode) {
|
||||
// dio.interceptors.add(
|
||||
// LogInterceptor(
|
||||
// request: false,
|
||||
// requestHeader: false,
|
||||
// responseHeader: false,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
dio
|
||||
..transformer = BackgroundTransformer()
|
||||
|
||||
@@ -31,23 +31,16 @@ import 'package:PiliPlus/models_new/video/video_shot/data.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/app_sign.dart';
|
||||
import 'package:PiliPlus/utils/extension/string_ext.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/recommend_filter.dart';
|
||||
import 'package:PiliPlus/utils/request_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:PiliPlus/utils/wbi_sign.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart' show compute;
|
||||
import 'package:protobuf/protobuf.dart';
|
||||
|
||||
/// view层根据 status 判断渲染逻辑
|
||||
abstract final class VideoHttp {
|
||||
static RegExp zoneRegExp = RegExp(Pref.banWordForZone, caseSensitive: false);
|
||||
static bool enableFilter = zoneRegExp.pattern.isNotEmpty;
|
||||
|
||||
// 首页推荐视频
|
||||
static Future<LoadingState<List<RcmdVideoItemModel>>> rcmdVideoList({
|
||||
required int ps,
|
||||
@@ -68,15 +61,7 @@ abstract final class VideoHttp {
|
||||
if (res.data['code'] == 0) {
|
||||
List<RcmdVideoItemModel> list = <RcmdVideoItemModel>[];
|
||||
for (final i in res.data['data']['item']) {
|
||||
//过滤掉live与ad,以及拉黑用户
|
||||
if (i['goto'] == 'av' &&
|
||||
(i['owner'] != null &&
|
||||
!GlobalData().blackMids.contains(i['owner']['mid']))) {
|
||||
RcmdVideoItemModel videoItem = RcmdVideoItemModel.fromJson(i);
|
||||
if (!RecommendFilter.filter(videoItem)) {
|
||||
list.add(videoItem);
|
||||
}
|
||||
}
|
||||
list.add(RcmdVideoItemModel.fromJson(i));
|
||||
}
|
||||
return Success(list);
|
||||
} else {
|
||||
@@ -142,20 +127,9 @@ abstract final class VideoHttp {
|
||||
List<RcmdVideoItemAppModel> list = <RcmdVideoItemAppModel>[];
|
||||
for (final i in res.data['data']['items']) {
|
||||
// 屏蔽推广和拉黑用户
|
||||
if (i['card_goto'] != 'ad_av' &&
|
||||
i['card_goto'] != 'ad_web_s' &&
|
||||
i['ad_info'] == null &&
|
||||
(i['args'] != null &&
|
||||
!GlobalData().blackMids.contains(i['args']['up_id']))) {
|
||||
if (enableFilter &&
|
||||
i['args']?['tname'] != null &&
|
||||
zoneRegExp.hasMatch(i['args']['tname'])) {
|
||||
continue;
|
||||
}
|
||||
RcmdVideoItemAppModel videoItem = RcmdVideoItemAppModel.fromJson(i);
|
||||
if (!RecommendFilter.filter(videoItem)) {
|
||||
list.add(videoItem);
|
||||
}
|
||||
final goto = i['card_goto'];
|
||||
if (goto != 'ad_av' && goto != 'ad_web_s' && i['ad_info'] == null) {
|
||||
list.add(RcmdVideoItemAppModel.fromJson(i));
|
||||
}
|
||||
}
|
||||
return Success(list);
|
||||
@@ -176,19 +150,7 @@ abstract final class VideoHttp {
|
||||
if (res.data['code'] == 0) {
|
||||
List<HotVideoItemModel> list = <HotVideoItemModel>[];
|
||||
for (final i in res.data['data']['list']) {
|
||||
if (!GlobalData().blackMids.contains(i['owner']['mid']) &&
|
||||
!RecommendFilter.filterTitle(i['title']) &&
|
||||
!RecommendFilter.filterLikeRatio(
|
||||
i['stat']['like'],
|
||||
i['stat']['view'],
|
||||
)) {
|
||||
if (enableFilter &&
|
||||
i['tname'] != null &&
|
||||
zoneRegExp.hasMatch(i['tname'])) {
|
||||
continue;
|
||||
}
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
}
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
}
|
||||
return Success(list);
|
||||
} else {
|
||||
@@ -208,7 +170,6 @@ abstract final class VideoHttp {
|
||||
required bool tryLook,
|
||||
required VideoType videoType,
|
||||
String? language,
|
||||
bool voiceBalance = false,
|
||||
}) async {
|
||||
final params = await WbiSign.makSign({
|
||||
'avid': ?avid,
|
||||
@@ -221,7 +182,7 @@ abstract final class VideoHttp {
|
||||
'fnval': 4048,
|
||||
'fourk': 1,
|
||||
'fnver': 0,
|
||||
'voice_balance': voiceBalance ? 1 : 0,
|
||||
'voice_balance': 0,
|
||||
'gaia_source': 'pre-load',
|
||||
'isGaiaAvoided': true,
|
||||
'web_location': 1315873,
|
||||
@@ -318,13 +279,11 @@ abstract final class VideoHttp {
|
||||
queryParameters: {'bvid': bvid},
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
final items = (res.data['data'] as List?)?.map(
|
||||
(i) => HotVideoItemModel.fromJson(i),
|
||||
return Success(
|
||||
(res.data['data'] as List?)
|
||||
?.map((i) => HotVideoItemModel.fromJson(i))
|
||||
.toList(),
|
||||
);
|
||||
final list = RecommendFilter.applyFilterToRelatedVideos
|
||||
? items?.where((i) => !RecommendFilter.filterAll(i)).toList()
|
||||
: items?.toList();
|
||||
return Success(list);
|
||||
} else {
|
||||
return Error(res.data['message']);
|
||||
}
|
||||
@@ -561,13 +520,6 @@ abstract final class VideoHttp {
|
||||
if (res.data['code'] == 0) {
|
||||
try {
|
||||
final replyInfo = RequestUtils.replyCast(res.data['data']['reply']);
|
||||
GStorage.reply?.put(
|
||||
replyInfo.id.toString(),
|
||||
(replyInfo.deepCopy()
|
||||
..unknownFields.clear()
|
||||
..clearTrackInfo())
|
||||
.writeToBuffer(),
|
||||
);
|
||||
return Success(replyInfo);
|
||||
} catch (e, s) {
|
||||
Utils.reportError(e, s);
|
||||
@@ -594,7 +546,6 @@ abstract final class VideoHttp {
|
||||
options: Options(contentType: Headers.formUrlEncodedContentType),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
GStorage.reply?.delete(rpid.toString());
|
||||
return const Success(null);
|
||||
} else {
|
||||
return const Error('请退出账号后重新登录');
|
||||
@@ -860,23 +811,6 @@ abstract final class VideoHttp {
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool _canAddRank(Map i) {
|
||||
if (!GlobalData().blackMids.contains(i['owner']['mid']) &&
|
||||
!RecommendFilter.filterTitle(i['title']) &&
|
||||
!RecommendFilter.filterLikeRatio(
|
||||
i['stat']['like'],
|
||||
i['stat']['view'],
|
||||
)) {
|
||||
if (enableFilter &&
|
||||
i['tname'] != null &&
|
||||
zoneRegExp.hasMatch(i['tname'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 视频排行
|
||||
static Future<LoadingState<List<HotVideoItemModel>>> getRankVideoList(
|
||||
int rid,
|
||||
@@ -888,17 +822,7 @@ abstract final class VideoHttp {
|
||||
if (res.data['code'] == 0) {
|
||||
List<HotVideoItemModel> list = <HotVideoItemModel>[];
|
||||
for (final i in res.data['data']['list']) {
|
||||
if (_canAddRank(i)) {
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
// final List? others = i['others'];
|
||||
// if (others != null && others.isNotEmpty) {
|
||||
// for (final j in others) {
|
||||
// if (_canAddRank(j)) {
|
||||
// list.add(HotVideoItemModel.fromJson(j));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
}
|
||||
return Success(list);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user