-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.py
99 lines (83 loc) · 2.71 KB
/
cli.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from kickassanime_scraper import automate_scraping, player, check_latest_version
from automatic_checker import download_location, main as checker
from sys import platform, argv
from os import system
import asyncio
try:
from selectmenu import SelectMenu #type: ignore
except ImportError:
if len(argv) <= 1: print('\nSelectmenu not installed, using basic menu layout.')
class SelectMenu:
def add_choices(self, choices: list):
self.choices = choices
def select(self, prompt=None):
print(prompt or "What would you like?")
for j, i in enumerate(self.choices): print(j, i)
print()
return self.choices[int(input('Enter choice number: '))]
base_url = "https://www2.kickassanime.lol"
async def search_and_download():
query = input("Enter anime name: ")
data = await player.search(query)
if not data:
exit(1)
print(data["name"])
print("Skip episode numbers to default to first or latest episode")
link = base_url + data["slug"]
try:
ep_start = int(input("Enter Episode to start from: "))
except ValueError:
ep_start = None
try:
ep_end = int(input("Enter Episode to end from: "))
except:
ep_end = None
await automate_scraping(
link,
ep_start,
ep_end,
only_player=False,
get_ext_servers=True,
download_location=download_location,
)
async def play():
if platform.startswith("win"):
system("play.bat")
else:
system("bash play.sh")
async def auto_update():
await checker()
input("Enter to exit...")
async def config():
print("Go to your download location -> Config")
print("To see current configuration settings")
async def latest():
await player.fetch_latest()
menu = SelectMenu()
choices = {
"Play Episode": play,
"Search And Download": search_and_download,
"Autoupdate Library": auto_update,
"Fetch Latest": latest,
"Check For Updates": check_latest_version,
"See Config": config,
}
if len(argv) > 1:
if argv[1] == 'update':
asyncio.run(choices["Autoupdate Library"]())
elif argv[1] == 'download':
asyncio.run(choices["Search And Download"]())
elif argv[1] == 'latest':
asyncio.run(choices["Fetch Latest"]())
elif argv[1] == 'check':
asyncio.run(choices["Check For Updates"]())
else:
if platform.startswith("win"):
system(f'python play.py {" ".join(argv[1:])}')
else:
system(f'python3 play.py {" ".join(argv[1:])}')
exit()
menu.add_choices(list(choices.keys()))
result = menu.select("What would you like?")
print(result)
asyncio.run(choices[result]())