Skip to content

Commit

Permalink
Feat: TMDB data binding correction
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Aug 25, 2023
1 parent d7cad71 commit 7ddf396
Show file tree
Hide file tree
Showing 16 changed files with 855 additions and 186 deletions.
7 changes: 5 additions & 2 deletions assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"uk": "Українська",
"zh": "中文"
},

"common": {
"home": "Home",
"search": "Search",
Expand Down Expand Up @@ -107,7 +107,10 @@
"overview": "Overview",
"cast": "Cast",
"additional-info": "Additional Info",
"get-lastest-data-error": "Failed to get latest data"
"get-lastest-data-error": "Failed to get latest data",
"modify-tmdb-binding": "Modify TMDB Binding",
"no-tmdb-data": "No TMDB data matched, please bind the data yourself",
"tmdb-key-missing": "TMDB API Key missing, please fill in the settings"
},

"video": {
Expand Down
5 changes: 4 additions & 1 deletion assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@
"overview": "概览",
"cast": "演员",
"additional-info": "附加信息",
"get-lastest-data-error": "获取最新数据失败"
"get-lastest-data-error": "获取最新数据失败",
"modify-tmdb-binding": "修改 TMDB 绑定",
"no-tmdb-data": "未匹配到 TMDB 数据,请自行绑定数据",
"tmdb-key-missing": "TMDB API Key 丢失,请前往设置填写"
},

"video": {
Expand Down
28 changes: 19 additions & 9 deletions lib/api/tmdb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class TmdbApi {
defaultLanguage: MiruStorage.getSetting(SettingKey.language),
);

static Future<tmdb_model.TMDBDetail?> getDetail(String keyword,
{int page = 1}) async {
final result = await tmdb.v3.search.queryMulti(
static Future<tmdb_model.TMDBDetail?> getDetailBySearch(
String keyword, {
int page = 1,
}) async {
final result = await search(
keyword,
page: page,
);
Expand All @@ -19,20 +21,28 @@ class TmdbApi {
if (results.isEmpty) {
return null;
}
return getDetail(
results.first["id"],
results.first["media_type"],
);
}

static Future<tmdb_model.TMDBDetail> getDetail(
int id,
String mediaType,
) async {
late Map data;
final mediaType = results[0]["media_type"];
if (mediaType == "movie") {
data = await tmdb.v3.movies.getDetails(
results[0]["id"],
id,
appendToResponse: "credits,images",
);
} else {
data = await tmdb.v3.tv.getDetails(
results[0]["id"],
id,
appendToResponse: "credits,images",
);
}

return tmdb_model.TMDBDetail(
id: data["id"],
mediaType: mediaType,
Expand Down Expand Up @@ -69,7 +79,7 @@ class TmdbApi {
);
}

static String? getImageUrl(String path) {
return tmdb.images.getUrl(path);
static String? getImageUrl(String path, {size = ImageSizes.ORIGINAL}) {
return tmdb.images.getUrl(path, size: size);
}
}
1 change: 1 addition & 0 deletions lib/models/tmdb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TMDB {
@Index(unique: true)
late int tmdbID;
late String data;
late String mediaType;
}

@JsonSerializable()
Expand Down
183 changes: 180 additions & 3 deletions lib/models/tmdb.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ddf396

Please sign in to comment.