-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt.py
66 lines (52 loc) · 1.43 KB
/
yt.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
import youtube_dl
from tkinter import messagebox
def errorGUI(str):
messagebox.showerror('Error', str)
def info(str):
messagebox.showinfo('Info', str)
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
errorGUI(msg)
def my_hook(d):
if d['status'] == 'finished':
info('Done Downloading!!')
print('Done downloading, now converting ...')
mp3_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
mp4_opts = {
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'
}
def mp3(link):
info('Download has been started!')
with youtube_dl.YoutubeDL(mp3_opts) as ydl:
ydl.download([link])
print(MyLogger)
def mp4(link):
info('Download has been started!')
with youtube_dl.YoutubeDL(mp4_opts) as ydl:
ydl.download([link])
print(MyLogger)
def vidInfo(link):
ydl = youtube_dl.YoutubeDL({'skip_download': True, 'noplaylist': True})
info = ydl.extract_info(link, download=False)
vidData = {
'id': info['id'],
'title': info['title'],
'thumbnail': info['thumbnail']
}
print(info)
return vidData
mp4('https://www.youtube.com/_hBswwpLAkY')