Skip to content

Commit e18ca5c

Browse files
committed
feat!: TMDB 元数据支持
1 parent 5c52345 commit e18ca5c

22 files changed

+2625
-72
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Miru App
3737
- [x] 影视播放进度
3838
- [x] 漫画小说设置
3939
- [x] 漫画小说历史记录
40-
- [ ] TMDB 元数据
41-
- [ ] 字幕
40+
- [x] TMDB 元数据
41+
- [ ] 字幕支持
4242
- [ ] BT 种子播放
4343
- [ ] 数据同步
4444
- [ ] 自动搜寻字幕

assets/i18n/en.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
"continue-watching": "Continue {episode}",
8484
"total-episodes": "Total {total}",
8585
"overview": "Overview",
86-
"cast": "Cast"
86+
"cast": "Cast",
87+
"additional-info": "Additional Info",
88+
"get-lastest-data-error": "Failed to get latest data"
8789
},
8890

8991
"video": {
@@ -137,5 +139,15 @@
137139
"other-infomation": "Other Infomation",
138140
"license": "License",
139141
"title": "Extension Info"
142+
},
143+
144+
"tmdb": {
145+
"backdrops": "Backdrops",
146+
"status": "Status",
147+
"original-title": "Original Title",
148+
"release-date": "Release Date",
149+
"genres": "Genres",
150+
"runtime": "Runtime",
151+
"languages": "Languages"
140152
}
141153
}

assets/i18n/zh.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888
"continue-watching": "继续 {episode}",
8989
"total-episodes": "共 {total}",
9090
"overview": "概览",
91-
"cast": "演员"
91+
"cast": "演员",
92+
"additional-info": "附加信息",
93+
"get-lastest-data-error": "获取最新数据失败"
9294
},
9395

9496
"video": {
@@ -142,5 +144,15 @@
142144
"other-infomation": "其他信息",
143145
"license": "许可",
144146
"title": "扩展详情"
147+
},
148+
149+
"tmdb": {
150+
"backdrops": "剧照",
151+
"status": "状态",
152+
"original-title": "原始标题",
153+
"release-date": "发布日期",
154+
"genres": "类型",
155+
"runtime": "时长",
156+
"languages": "语言"
145157
}
146158
}

lib/api/tmdb.dart

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'package:miru_app/models/tmdb.dart' as tmdb_model;
2+
import 'package:miru_app/utils/miru_storage.dart';
3+
import 'package:tmdb_api/tmdb_api.dart';
4+
5+
class TmdbApi {
6+
static TMDB tmdb = TMDB(
7+
ApiKeys(MiruStorage.getSetting(SettingKey.tmdbKay), ''),
8+
defaultLanguage: MiruStorage.getSetting(SettingKey.language),
9+
);
10+
11+
static Future<tmdb_model.TMDBDetail> getDetail(String keyword,
12+
{int page = 1}) async {
13+
final result = await tmdb.v3.search.queryMulti(
14+
keyword,
15+
page: page,
16+
);
17+
// print(result);
18+
final results = result["results"] as List;
19+
if (results.isEmpty) {
20+
throw Exception("No results");
21+
}
22+
late Map data;
23+
final mediaType = results[0]["media_type"];
24+
if (mediaType == "movie") {
25+
data = await tmdb.v3.movies.getDetails(
26+
results[0]["id"],
27+
appendToResponse: "credits,images",
28+
);
29+
} else {
30+
data = await tmdb.v3.tv.getDetails(
31+
results[0]["id"],
32+
appendToResponse: "credits,images",
33+
);
34+
}
35+
36+
return tmdb_model.TMDBDetail(
37+
id: data["id"],
38+
mediaType: mediaType,
39+
title: data["title"] ?? data["name"],
40+
cover: data["poster_path"] ?? data["profile_path"],
41+
backdrop: data["backdrop_path"],
42+
genres: List<String>.from(data["genres"].map((e) => e["name"])),
43+
languages:
44+
List<String>.from(data["spoken_languages"].map((e) => e["name"])),
45+
images: List<String>.from(
46+
data["images"]["backdrops"].map((e) => e["file_path"]),
47+
),
48+
overview: data["overview"],
49+
status: data["status"],
50+
casts: List<tmdb_model.TMDBCast>.from(
51+
data["credits"]["cast"].map((e) => tmdb_model.TMDBCast(
52+
id: e["id"],
53+
name: e["name"],
54+
profilePath: e["profile_path"],
55+
character: e["character"],
56+
))),
57+
releaseDate: data["release_date"] ?? data["first_air_date"],
58+
runtime: data["runtime"] ?? data["episode_run_time"][0],
59+
originalTitle: data["original_title"] ?? data["original_name"],
60+
);
61+
}
62+
63+
static Future<Map> search(String keyword, {int page = 1}) {
64+
return tmdb.v3.search.queryMulti(
65+
keyword,
66+
page: page,
67+
);
68+
}
69+
70+
static String? getImageUrl(String path) {
71+
return tmdb.images.getUrl(path);
72+
}
73+
}

lib/models/index.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export 'favorite.dart';
33
export 'history.dart';
44
export 'extension_setting.dart';
55
export 'manga_setting.dart';
6+
export 'miru_detail.dart';

lib/models/miru_detail.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:isar/isar.dart';
2+
3+
part 'miru_detail.g.dart';
4+
5+
@collection
6+
class MiruDetail {
7+
Id id = Isar.autoIncrement;
8+
@Index(name: 'package&url', composite: [CompositeIndex('url')])
9+
late String package;
10+
late String url;
11+
late String data;
12+
int? tmdbID;
13+
DateTime updateTime = DateTime.now();
14+
}

0 commit comments

Comments
 (0)