基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
import 'package:flutter_test/flutter_test.dart';
import 'package:kazumi/services/network/bangumi_image_url_rewriter.dart';
void main() {
group('BangumiImageUrlRewriter', () {
test('rewrites lain images and preserves GIF animation', () {
expect(
BangumiImageUrlRewriter.rewrite(
Uri.parse('https://lain.bgm.tv/pic/cover/l/cover.jpg'),
).toString(),
'https://wsrv.nl/?url=lain.bgm.tv%2Fpic%2Fcover%2Fl%2Fcover.jpg',
);
expect(
BangumiImageUrlRewriter.rewrite(
Uri.parse('https://lain.bgm.tv/pic/cover/l/animated.gif'),
).toString(),
'https://wsrv.nl/?url=lain.bgm.tv%2Fpic%2Fcover%2Fl%2Fanimated.gif&n=-1',
);
});
test('rewrites synthetic API image endpoints', () {
for (final type in ['subjects', 'characters', 'persons']) {
final source = 'https://api.bgm.tv/v0/$type/590353/image?type=large';
expect(
BangumiImageUrlRewriter.rewrite(Uri.parse(source)).toString(),
'https://wsrv.nl/?url=api.bgm.tv%2Fv0%2F$type%2F590353%2Fimage%3Ftype%3Dlarge',
);
}
});
test('rejects URLs outside the image boundary', () {
for (final url in [
'ftp://lain.bgm.tv/pic/cover/l/cover.jpg',
'https://api.bgm.tv/v0/subjects/590353',
'https://api.bgm.tv/v0/subjects/not-an-id/image?type=large',
'https://api.bgm.tv/v0/episodes/1/image?type=large',
'https://example.com/v0/subjects/590353/image?type=large',
]) {
expect(BangumiImageUrlRewriter.rewrite(Uri.parse(url)).toString(), url);
}
});
});
}