-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio2pk3.py
executable file
·65 lines (46 loc) · 1.72 KB
/
audio2pk3.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
#!/usr/bin/env python3
# z@xnz.me
import argparse
import re
import uuid
from xonotic_radio.objects import Track
from xonotic_radio.util import read_config
def main():
conf, endpoints = read_config('config/config.ini')
args = parse_args()
input_source = args.input_source
if re.match('^http(s)?://(www\.|m\.)?(youtube\.com|youtu\.be)/.*', input_source):
track = Track(youtube_url=input_source)
else:
if not args.title:
raise SystemExit('title is required as a second parameter')
else:
title = args.title
if re.match('^http(s)?://.*', input_source):
track = Track(source_url=input_source, title=title)
else:
track = Track(source_file=input_source, title=title)
if args.target:
if args.target in endpoints:
target = endpoints[args.target]
else:
raise SystemExit('target doesn\'t exist')
else:
target = endpoints['default']
if args.name:
name = args.name
else:
name = str(uuid.uuid1())
track.convert_to_ogg(name)
track.create_pk3(name)
track.write_to_endpoint_list(target)
print('done.')
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--target', '-t', nargs='?', help="target endpoint defined under [endpoints] in config", type=str)
parser.add_argument('--name', '-n', nargs='?', help="name your download", type=str)
parser.add_argument("input_source", help="A URL of a youtube video, a remote audio file or local a audio file", type=str)
parser.add_argument('title', nargs='?', help='title for the audio file', type=str)
return parser.parse_args()
if __name__ == "__main__":
main()