-
Notifications
You must be signed in to change notification settings - Fork 26
/
DownloadMethods.py
66 lines (61 loc) · 2.37 KB
/
DownloadMethods.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
from __future__ import unicode_literals
import youtube_dl
class Download(object):
def __init__(self, url, save_path, quality, playlist=False):
self.url = url
self.save_path = save_path
self.qualities = {"Best": "1411",
"Semi": "320",
"Worst": "128"}
self.quality = self.qualities[quality]
self.playlist = playlist
def mp3_download(self):
print(self.quality)
# para m4 se usa 140 como calidad
if self.quality == "140":
print("Sera m4a")
opts = {
"verbose": True,
"fixup" : "detect_or_warn",
"format" : "bestaudio[ext=m4a]",
"postprocessors" : [{
"key": "FFmpegExtractAudio",
"preferredcodec" : "m4a",
"preferredquality" : self.quality
}],
"extractaudio": False,
"outtmpl" : self.save_path + "/%(title)s.%(ext)s",
"noplaylist" : self.playlist
}
download_object = youtube_dl.YoutubeDL(opts)
download_object.download([self.url])
else:
opts = {
"verbose": False,
"fixup" : "detect_or_warn",
"format" : "bestaudio/best",
"postprocessors" : [{
"key": "FFmpegExtractAudio",
"preferredcodec" : "mp3",
"preferredquality": self.quality
}],
"extractaudio": True,
"outtmpl" : self.save_path + "/%(title)s.%(ext)s",
"noplaylist" : self.playlist
}
download_object = youtube_dl.YoutubeDL(opts)
download_object.download([self.url])
def mp4_download(self):
opts = {
"verbose": False,
"fixup" : "detect_or_warn",
"format" : "bestaudio/best",
"postprocessors" : [{
"key": "FFmpegVideoConverter",
"preferredcodec" : "mp4",
}],
"outtmpl" : self.save_path + "/%(title)s.%(ext)s",
"noplaylist" : self.playlist
}
download_object = youtube_dl.YoutubeDL(opts)
download_object.download([self.url])