-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·43 lines (43 loc) · 1.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from rich.console import Console
from rich.table import Table
from rich.prompt import Prompt
import webbrowser
from utils.anime import getSources, search, getEpisode, getAnimeInfo
console = Console()
def main():
query = Prompt.ask("Search Anime")
with console.status(f"[bold green]Searching for {query}...") as status:
if True:
searchResults = search(query)
console.print(f"{len(searchResults)} results found")
table = Table(show_header=True, header_style="bold yellow")
table.add_column("SN", style="bold cyan")
table.add_column("Anime", style="blue")
for i, searchResult in enumerate(searchResults, start=1):
table.add_row(str(i), searchResult.title)
console.print(table)
selectedAnime = Prompt.ask(f"Select Anime[1-{len(searchResults)}]")
selectedAnime = int(selectedAnime)
if not (selectedAnime in range(1, len(searchResults)+1)):
raise Exception("Invalid Input")
anime = searchResults[selectedAnime-1]
animeInfo = getAnimeInfo(anime.url)
selectedEpisode = Prompt.ask(f"Select Episode[1-{animeInfo.episodes}]")
selectedEpisode = int(selectedEpisode)
if not (selectedEpisode in range(1, int(animeInfo.episodes)+1)):
raise Exception("Invalid Input")
episode = getEpisode(animeInfo.animeID, selectedEpisode)
sources = getSources(episode.url).get("source")
table = Table(show_header=True, header_style="bold yellow")
table.add_column("SN", style="bold cyan")
table.add_column("Quality", style="blue")
for i, source in enumerate(sources, start=1):
table.add_row(str(i), source.get("label").split()[0])
console.print(table)
selectedQuality = Prompt.ask(f"Select Quality[1-{len(sources)}]")
selectedQuality = int(selectedQuality)
if not (selectedQuality in range(1,len(sources)+1)):
raise Exception("Invalid Input")
webbrowser.open(f'{sources[selectedQuality-1].get("file")}')
if __name__ == "__main__":
main()