Skip to content

Commit

Permalink
feat!: TMDB 元数据支持
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Aug 6, 2023
1 parent 5c52345 commit e18ca5c
Show file tree
Hide file tree
Showing 22 changed files with 2,625 additions and 72 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Miru App
- [x] 影视播放进度
- [x] 漫画小说设置
- [x] 漫画小说历史记录
- [ ] TMDB 元数据
- [ ] 字幕
- [x] TMDB 元数据
- [ ] 字幕支持
- [ ] BT 种子播放
- [ ] 数据同步
- [ ] 自动搜寻字幕
Expand Down
14 changes: 13 additions & 1 deletion assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
"continue-watching": "Continue {episode}",
"total-episodes": "Total {total}",
"overview": "Overview",
"cast": "Cast"
"cast": "Cast",
"additional-info": "Additional Info",
"get-lastest-data-error": "Failed to get latest data"
},

"video": {
Expand Down Expand Up @@ -137,5 +139,15 @@
"other-infomation": "Other Infomation",
"license": "License",
"title": "Extension Info"
},

"tmdb": {
"backdrops": "Backdrops",
"status": "Status",
"original-title": "Original Title",
"release-date": "Release Date",
"genres": "Genres",
"runtime": "Runtime",
"languages": "Languages"
}
}
14 changes: 13 additions & 1 deletion assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
"continue-watching": "继续 {episode}",
"total-episodes": "共 {total}",
"overview": "概览",
"cast": "演员"
"cast": "演员",
"additional-info": "附加信息",
"get-lastest-data-error": "获取最新数据失败"
},

"video": {
Expand Down Expand Up @@ -142,5 +144,15 @@
"other-infomation": "其他信息",
"license": "许可",
"title": "扩展详情"
},

"tmdb": {
"backdrops": "剧照",
"status": "状态",
"original-title": "原始标题",
"release-date": "发布日期",
"genres": "类型",
"runtime": "时长",
"languages": "语言"
}
}
73 changes: 73 additions & 0 deletions lib/api/tmdb.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:miru_app/models/tmdb.dart' as tmdb_model;
import 'package:miru_app/utils/miru_storage.dart';
import 'package:tmdb_api/tmdb_api.dart';

class TmdbApi {
static TMDB tmdb = TMDB(
ApiKeys(MiruStorage.getSetting(SettingKey.tmdbKay), ''),
defaultLanguage: MiruStorage.getSetting(SettingKey.language),
);

static Future<tmdb_model.TMDBDetail> getDetail(String keyword,
{int page = 1}) async {
final result = await tmdb.v3.search.queryMulti(
keyword,
page: page,
);
// print(result);
final results = result["results"] as List;
if (results.isEmpty) {
throw Exception("No results");
}
late Map data;
final mediaType = results[0]["media_type"];
if (mediaType == "movie") {
data = await tmdb.v3.movies.getDetails(
results[0]["id"],
appendToResponse: "credits,images",
);
} else {
data = await tmdb.v3.tv.getDetails(
results[0]["id"],
appendToResponse: "credits,images",
);
}

return tmdb_model.TMDBDetail(
id: data["id"],
mediaType: mediaType,
title: data["title"] ?? data["name"],
cover: data["poster_path"] ?? data["profile_path"],
backdrop: data["backdrop_path"],
genres: List<String>.from(data["genres"].map((e) => e["name"])),
languages:
List<String>.from(data["spoken_languages"].map((e) => e["name"])),
images: List<String>.from(
data["images"]["backdrops"].map((e) => e["file_path"]),
),
overview: data["overview"],
status: data["status"],
casts: List<tmdb_model.TMDBCast>.from(
data["credits"]["cast"].map((e) => tmdb_model.TMDBCast(
id: e["id"],
name: e["name"],
profilePath: e["profile_path"],
character: e["character"],
))),
releaseDate: data["release_date"] ?? data["first_air_date"],
runtime: data["runtime"] ?? data["episode_run_time"][0],
originalTitle: data["original_title"] ?? data["original_name"],
);
}

static Future<Map> search(String keyword, {int page = 1}) {
return tmdb.v3.search.queryMulti(
keyword,
page: page,
);
}

static String? getImageUrl(String path) {
return tmdb.images.getUrl(path);
}
}
1 change: 1 addition & 0 deletions lib/models/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export 'favorite.dart';
export 'history.dart';
export 'extension_setting.dart';
export 'manga_setting.dart';
export 'miru_detail.dart';
14 changes: 14 additions & 0 deletions lib/models/miru_detail.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:isar/isar.dart';

part 'miru_detail.g.dart';

@collection
class MiruDetail {
Id id = Isar.autoIncrement;
@Index(name: 'package&url', composite: [CompositeIndex('url')])
late String package;
late String url;
late String data;
int? tmdbID;
DateTime updateTime = DateTime.now();
}

0 comments on commit e18ca5c

Please sign in to comment.