-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdl.py
executable file
·60 lines (44 loc) · 1.67 KB
/
dl.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
#!/usr/bin/env python3
import argparse
import csv
import multiprocessing
import shutil
import os
import subprocess
err = subprocess.Popen(['pip', 'install', 'youtube-dl'],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE).communicate()[1]
if len(err) != 0:
print(err)
exit(1)
def download(name, link, outfile):
import subprocess
print('Downloading', name, 'from', link + '...')
process = subprocess.Popen(['youtube-dl',
'--extract-audio',
'--audio-format', 'wav',
'-o', outfile, link],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
_, err = process.communicate()
if err != b'':
import sys
print('Error downloading', name, 'from', link, file=sys.stderr)
print(err.decode('utf-8'), file=sys.stderr)
if __name__ == '__main__':
tracks_path = os.path.join(os.path.curdir, 'tracks')
name_index = 0
link_index = 1
if os.path.exists(tracks_path):
shutil.rmtree(tracks_path)
os.mkdir(tracks_path)
with multiprocessing.Pool() as p:
with open('klub.csv', 'rt') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for i, row in enumerate(reader, 1):
name = row[name_index]
link = row[link_index]
outfile = os.path.join(tracks_path, str(i) + '.wav')
p.apply_async(download, (name, link, outfile))
p.close()
p.join()