-
Notifications
You must be signed in to change notification settings - Fork 21
/
cli.py
67 lines (55 loc) · 1.86 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
from datetime import datetime
import argparse
import config.plugins as plugins
from clases.log import log as l
from sanitize_filename import sanitize
def main(raw_args=None):
parser=argparse.ArgumentParser()
parser.add_argument('-m', '--media', help='Media platform')
parser.add_argument('-p', '--params', help='Params to media platform mode.')
parser.add_argument('-v', '--version', help='Show YTDLP2STRM version')
# Keep working for old version
parser.add_argument('--m', help='Media platform (old)')
parser.add_argument('--p', help='Params to media platform mode (old)')
# --
args=parser.parse_args(raw_args)
method = args.media if args.media != None else "error"
params = args.params.split(',') if args.params != None else None
# Keep working for old version
if method == "error":
method = args.m if args.m != None else None
if params == None:
params = args.p.split(',') if args.p != None else None
try:
if "plugins" in method:
method = method.split('.')[1]
if method == "make_files_strm":
method = "youtube"
except:
method = None
try:
if "twitch" in params:
params = [params[1]]
if 'redirect' in params:
params = ["direct"]
if 'stream' in params:
params = ["bridge"]
except:
params = None
# --
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
log_text = "Running {} with {} params".format(method, params)
l.log("CLI", log_text)
if args.version:
log_text = (
'ytdlp2STRM version: {}'.format(
'1.0.1'
)
)
l.log("CLI", log_text)
r = False
if params != None:
r = eval("{}.{}.{}".format("plugins",method,"to_strm"))(*params)
if __name__ == "__main__":
main()