Skip to content

Commit da061b5

Browse files
committed
feat: get media id from different sources (idk where to use it for now)
1 parent 6ffc55f commit da061b5

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import 'dart:convert';
2+
3+
import 'package:flutter/cupertino.dart';
4+
import 'package:flutter_qjs/quickjs/ffi.dart';
5+
import 'package:http/http.dart' as http;
6+
import 'package:json_annotation/json_annotation.dart';
7+
8+
part 'GetMediaIDs.g.dart';
9+
10+
List<AnimeID>? _animeList;
11+
12+
class GetMediaIDs {// use if ever needed
13+
14+
static Future<AnimeID?> fetchAndFindIds(int anilistId) async {
15+
if (_animeList == null) {
16+
await _getData();
17+
}
18+
return _animeList?.firstWhereOrNull((entry) => entry.anilistId == anilistId);
19+
}
20+
21+
static Future<void> _getData() async {
22+
final url = Uri.parse(
23+
'https://raw.githubusercontent.com/Fribb/anime-lists/refs/heads/master/anime-list-full.json');
24+
final response = await http.get(url);
25+
26+
if (response.statusCode == 200) {
27+
List<dynamic> jsonData = jsonDecode(response.body);
28+
_animeList = jsonData.map((e) => AnimeID.fromJson(e)).toList();
29+
} else {
30+
debugPrint('Failed to load data: ${response.statusCode}');
31+
return;
32+
}
33+
}
34+
}
35+
36+
//@JsonSerializable()
37+
class AnimeID {
38+
@JsonKey(name: 'anime-planet_id')
39+
final String? animePlanetId;
40+
@JsonKey(name: 'anisearch_id')
41+
final int? anisearchId;
42+
@JsonKey(name: 'anidb_id')
43+
final int? anidbId;
44+
@JsonKey(name: 'kitsu_id')
45+
final int? kitsuId;
46+
@JsonKey(name: 'mal_id')
47+
final int? malId;
48+
final String? type;
49+
@JsonKey(name: 'notify.moe_id')
50+
final String? notifyMoeId;
51+
@JsonKey(name: 'anilist_id')
52+
final int? anilistId;
53+
@JsonKey(name: 'imdb_id')
54+
final String? imdbId;
55+
@JsonKey(name: 'livechart_id')
56+
final int? livechartId;
57+
@JsonKey(name: 'thetvdb_id')
58+
final int? thetvdbId;
59+
@JsonKey(name: 'themoviedb_id')
60+
final String? themoviedbId;
61+
62+
AnimeID({
63+
this.animePlanetId,
64+
this.kitsuId,
65+
this.malId,
66+
this.type,
67+
this.anilistId,
68+
this.imdbId,
69+
this.anisearchId,
70+
this.anidbId,
71+
this.notifyMoeId,
72+
this.livechartId,
73+
this.thetvdbId,
74+
this.themoviedbId,
75+
});
76+
77+
factory AnimeID.fromJson(Map<String, dynamic> json) =>
78+
_$AnimeIDFromJson(json);
79+
80+
Map<String, dynamic> toJson() => _$AnimeIDToJson(this);
81+
}

lib/api/EpisodeDetails/GetMediaIDs/GetMediaIDs.g.dart

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api/EpisodeDetails/Jikan/Jikan.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ class Jikan {
4242
} else if (response.statusCode == 429) {
4343
return eps;
4444
} else {
45-
throw Exception('Error: ${response.statusCode}');
45+
break;
4646
}
4747
}
48-
4948
return eps;
5049
}
5150
}

0 commit comments

Comments
 (0)