-
Notifications
You must be signed in to change notification settings - Fork 4
/
play.py
105 lines (87 loc) · 2.8 KB
/
play.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
100
101
102
103
104
105
from utilities.watcher import watch, names as server_names
import asyncio
import argparse
commands = '''
commands:
update Autoupdate the library by fetching the latest episodes form to_update.json
download Run the download menu to download a range of episodes
latest Prints the latest updates on the website
check Checks for any available updates for download
'''
parser = argparse.ArgumentParser(description="Play anime directly" + commands, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
"--list",
"-L",
action="store_true",
help="Optional switch to list available player servers (not ext) with their index",
)
# Optional positional argument
parser.add_argument("name", type=str, nargs="*", help="Name of the anime to search")
# Optional argument
parser.add_argument("--ep", "-e", type=int, help="Episode number. Default is the latest episode.")
parser.add_argument("--url", "-u", type=str, help="Optional kickass anime url")
parser.add_argument(
"--opt",
"-o",
type=int,
help="Optional way to select search result number.",
)
parser.add_argument(
"--ext",
action="store_true",
help="Optional switch to play only from ext servers (its faster if it works). Needs no arguments",
)
parser.add_argument(
"--stop",
"-s",
action="store_true",
help="Optional switch to stop the script after searching without playing anything. Will also display the url of the anime.",
)
parser.add_argument(
"--encode",
action="store_true",
help="Optional switch to print ffmpeg command to encode the stream",
)
def parse_server_name(arg):
if arg:
try:
index = int(arg)
if index < len(server_names):
return server_names[index]
else:
print('Priority Index out of range')
return ''
except:
return arg.upper()
else:
return ''
parser.add_argument(
"--custom_server",
"-c",
help="Name of the player/server you want or the INDEX number in the watch_config priority dictionary. Overrides the current priority.",
type = parse_server_name,
nargs='?',
# default=''
)
args = parser.parse_args()
episode = args.ep
link = args.url
query = " ".join(args.name) if args.name else None
opt = args.opt
ext_only = args.ext
custom_server = args.custom_server
to_list = args.list
stop = args.stop
encode = args.encode
if to_list:
print('Possible player servers are:')
for j, i in enumerate(server_names):
print(j, i)
exit()
if __name__ == '__main__':
try:
asyncio.run(
watch(episode, link=link, query=query, option_number=opt, ext_only=ext_only, custom_server=custom_server, stop=stop, encode=encode)
)
except RuntimeError:
print('Exit')