-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnrk-dl.py
More file actions
51 lines (40 loc) · 1.2 KB
/
nrk-dl.py
File metadata and controls
51 lines (40 loc) · 1.2 KB
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
from __future__ import unicode_literals
import youtube_dl
from sys import stdin, stdout
from math import floor
links = stdin.readlines()
previous = ''
class MyLogger(object):
def __init__(self):
self.newline = False
def debug(self, msg):
pass
def warning(self, msg):
print(msg)
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print('\tDone!')
if d['status'] == 'downloading':
filename = d['filename']
speed = d['_speed_str']
percentage = d['_percent_str']
if percentage != 'Unknown' and percentage != 'Unknown ':
progress = '='*floor(float(percentage.strip('%'))/2)
left = ' '*(50-len(progress))
stdout.write('\r')
stdout.write("Downloading '{}'\t[{}] {}".format(filename, progress + left, percentage))
stdout.flush()
else:
stdout.write('\r')
stdout.write(d)
stdout.flush()
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(links)