feat: add name suggesting

This commit is contained in:
Simon Ding
2024-07-19 16:59:12 +08:00
parent 1786e44933
commit 80d802fb4c
8 changed files with 152 additions and 55 deletions

View File

@@ -15,6 +15,7 @@ class APIs {
static final watchlistMovieUrl = "$_baseUrl/api/v1/media/movie/watchlist";
static final availableMoviesUrl = "$_baseUrl/api/v1/media/movie/resources/";
static final seriesDetailUrl = "$_baseUrl/api/v1/media/record/";
static final suggestedTvName = "$_baseUrl/api/v1/media/suggest/";
static final searchAndDownloadUrl = "$_baseUrl/api/v1/indexer/download";
static final allIndexersUrl = "$_baseUrl/api/v1/indexer/";
static final addIndexerUrl = "$_baseUrl/api/v1/indexer/add";

View File

@@ -17,6 +17,18 @@ final tvWatchlistDataProvider = FutureProvider.autoDispose((ref) async {
return favList;
});
final suggestNameDataProvider = FutureProvider.autoDispose.family(
(ref, int arg) async {
final dio = await APIs.getDio();
var resp = await dio.get(APIs.suggestedTvName + arg.toString());
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0) {
throw sp.message;
}
return sp.data["name"] as String;
},
);
final movieWatchlistDataProvider = FutureProvider.autoDispose((ref) async {
final dio = await APIs.getDio();
var resp = await dio.get(APIs.watchlistMovieUrl);
@@ -75,14 +87,15 @@ class SearchPageData
state = newState;
}
Future<void> submit2Watchlist(
int tmdbId, int storageId, String resolution, String mediaType) async {
Future<void> submit2Watchlist(int tmdbId, int storageId, String resolution,
String mediaType, String folder) async {
final dio = await APIs.getDio();
if (mediaType == "tv") {
var resp = await dio.post(APIs.watchlistTvUrl, data: {
"tmdb_id": tmdbId,
"storage_id": storageId,
"resolution": resolution
"resolution": resolution,
"folder": folder
});
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0) {
@@ -93,7 +106,8 @@ class SearchPageData
var resp = await dio.post(APIs.watchlistMovieUrl, data: {
"tmdb_id": tmdbId,
"storage_id": storageId,
"resolution": resolution
"resolution": resolution,
"folder": folder
});
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0) {
@@ -116,9 +130,11 @@ class SearchResponse {
page: json["page"],
totalPage: json["total_page"],
totalResults: json["total_results"],
results: json["results"] == null ? []: json["results"]
.map((v) => SearchResult.fromJson(v))
.toList());
results: json["results"] == null
? []
: (json["results"] as List)
.map((v) => SearchResult.fromJson(v))
.toList());
}
}