|
| 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 | +} |
0 commit comments