-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added source handler for anime 1/3
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:daizy_tv/utils/sources/Anime/Extensions/anivibe_scrapper.dart'; | ||
import 'package:daizy_tv/utils/sources/Anime/Extensions/gogoanime.dart'; | ||
import 'package:daizy_tv/utils/sources/Anime/Base/base_class.dart'; | ||
import 'package:daizy_tv/utils/sources/Anime/Extensions/hianime_api.dart'; | ||
import 'package:daizy_tv/utils/sources/Anime/Extensions/hianime_scrapper.dart'; | ||
|
||
class AnimeSourcehandler { | ||
final Map<String, EXtractAnimes> animeSources = { | ||
"Hianime": HianimeApi(), | ||
"Hianime (Scrapper)": HianimeScrapper(), | ||
"GogoAnime": GogoAnime(), | ||
"AniVibe": AniVibe() | ||
}; | ||
|
||
AnimeSourcehandler() { | ||
selectedSource = animeSources.entries.first.key; | ||
} | ||
|
||
String selectedSource = ""; | ||
|
||
String getSelectedSource() { | ||
if (selectedSource == "") { | ||
return selectedSource = animeSources.entries.first.key; | ||
} | ||
return selectedSource; | ||
} | ||
|
||
void changeSource(String sourceName) { | ||
if (animeSources.entries.any((source) => source.key == sourceName)) { | ||
selectedSource = sourceName; | ||
} | ||
selectedSource = animeSources.entries.first.key; | ||
} | ||
|
||
List<Map<String,String>> getAvailableSources() { | ||
return animeSources.entries.map((entry) { | ||
return {"name": entry.value.sourceName}; | ||
}).toList(); | ||
} | ||
|
||
Future<dynamic> mappedSourceId(String query) async { | ||
try { | ||
final String? id = await animeSources[selectedSource]?.mappingId(query); | ||
if (id != null && id.isNotEmpty) { | ||
return await fetchEpisodes(id); | ||
} | ||
} catch (e) { | ||
log("Error in mappedSourceId: $e"); | ||
return null; | ||
} | ||
} | ||
|
||
Future<dynamic> fetchEpisodes(String url) async { | ||
final data = await animeSources[selectedSource]?.scrapeAnimeEpisodes(url); | ||
return data; | ||
} | ||
|
||
Future<dynamic> fetchSearchResults(String query) async { | ||
final data = await animeSources[selectedSource]?.scrapeAnimeSearch(query); | ||
return data; | ||
} | ||
|
||
Future<dynamic> fetchEpisodesSrcs( | ||
String id, String server, String category) async { | ||
final data = await animeSources[selectedSource] | ||
?.scrapeEpisodesSrc(id, server, category); | ||
return data; | ||
} | ||
} |