-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyt
More file actions
executable file
·76 lines (59 loc) · 2.08 KB
/
yt
File metadata and controls
executable file
·76 lines (59 loc) · 2.08 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
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
#!/usr/bin/env python3
"""yt_dlp wrapper to cleanup some URLs"""
from urllib.parse import urlparse, urlunsplit
import argparse
import sys
import yt_dlp as ytdl
VERSION = f"0.0.7+{ytdl.version.__version__}({ytdl.__name__})"
def clean_url(url):
"""cleans rutube url"""
parsed = urlparse(url)
if parsed.netloc != 'rutube.ru' and not parsed.netloc.endswith('.rutube.ru'):
return url
return urlunsplit(parsed[:3] + ('', ''))
class YDLLogger(object):
"""YDL Logger object."""
def debug(self, msg):
"""Outputs debug messages"""
ends = '\r' if '[download]' in msg else '\n'
print("DEBUG: %s" % msg, end=ends, flush=True)
def warning(self, msg):
"""Outputs warnings"""
print("WARNING: %s" % msg)
def error(self, msg):
"""Outputs errors"""
print("ERROR: %s" % msg)
def info(self, msg):
"""Outputs info messages"""
print("INFO: %s" % msg)
def main(args):
cleaned_urls = list([clean_url(u) for u in args.url])
ydl_opts = {
'retries': 5,
'restrict-filenames': 'yes',
'logger': YDLLogger(),
'no-playlist': 'yes',
'ffmpeg-location': '/usr/bin/ffmpeg',
'proxy': args.proxy,
'outtmpl': args.output,
'verbose': args.verbose,
}
try:
with ytdl.YoutubeDL(ydl_opts) as ydl:
rc = ydl.download(cleaned_urls)
except ytdl.utils.YoutubeDLError as excp:
print("EXCEPTION: %s" % excp)
return 1
else:
print("DEBUG: No exception.")
return rc
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version',
version='%(prog)s ' + VERSION)
parser.add_argument('url', nargs='+', help='url to parse')
parser.add_argument('--proxy', help='proxy server')
parser.add_argument('-o', '--output', help="destination filename", default=ytdl.utils.DEFAULT_OUTTMPL)
parser.add_argument('-v', '--verbose', action='store_true', help="verbose output")
args = parser.parse_args()
sys.exit(main(args))