-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYoutubeDlAriaSongDownloader.py
47 lines (37 loc) · 1.35 KB
/
YoutubeDlAriaSongDownloader.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
# ------------ YoutubeDlAriaSongDownloader ------------
from AbstractSongDownloader import *
from subprocess import call, Popen
import threading
class DownloadTask():
def __init__(self, command_line_arguments):
self.__args = command_line_arguments
def run(self):
child = Popen(self.__args)
child.wait()
#call(self.__args)
# This class is responsible for downloading song from
# youtube. current implementaion is using youtube-dl
class YoutubeDlAriaSongDownloader(AbstractSongDownloader):
def __init__(self, localStorage):
super().__init__(localStorage)
def __GetYoutubeDlOptions(self):
ydlOptions = [
'--no-playlist',
'--no-check-certificate',
'-x', '--audio-format', 'mp3',
'-o', self.GetLocalStorage().GetCacheDirectory() + '/%(id)s.%(ext)s',
'--external-downloader', 'aria2c',
#'--external-downloader-args','\"-x 16 -s 16 -k 1M\"',
'--'
]
return ydlOptions
# Download the song into local storage and return whether
# The song is available to acces via local storage (either if its already
# exist or successfully downloaded)
def DownloadSong(self, songId):
if self.GetLocalStorage().IsSongInLocalStorage(songId):
return True
#download the song
downloadTask = DownloadTask(['youtube-dl'] + self.__GetYoutubeDlOptions() + [songId])
downloadTask.run();
return self.GetLocalStorage().IsSongInLocalStorage(songId)