Esempio n. 1
0
    def run(self):
        try:
            ydl_opts = {'quiet': True,
                        'progress_hooks': [self.progress_hook],
                        'format': 'bestaudio/best',
                        'outtmpl': '/tmp/smusic/%(title)s.%(ext)s',
                        'noplaylist': True,
                        'postprocessors': [{
                            'key': 'FFmpegExtractAudio',
                        }],
                        }

            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                ydl.download([self.url])
                for i in os.listdir("/tmp/smusic"):
                    if os.path.isfile(os.path.join("/tmp/smusic", i)) and \
                            i.startswith(join(self.__tmpfilename.split('.')[:-1], '.').split('/')[-1]):
                        self.__filename = "/tmp/smusic/" + i
                self.success = True
                self.__eta = 0
                self.__progress = 1
        except Exception as e:
            self.success = False
            self.ended = True
            logs.print_error(e)  # TODO: do something more proper with the exception
        self.ended = True
Esempio n. 2
0
    def start_download(self):
        if self.downloader is None:
            try:
                method = self.queue[0].url.split(';')[0]
                url = self.queue[0].url.split(';')[1]
                if method == "youtube-dl":
                    self.downloader = YoutubeDLDownloadThread(url)
                    logs.print_debug("Starting download of %s with youtube-dl" % url)
                else:
                    logs.print_error("Unknown download method %s" % method)
                    return
                self.downloader.start()
            except IndexError as e:
                logs.print_error("Syntax error in URL: %s" % e)

        else:
            logs.print_warning("Download thread already exists")
Esempio n. 3
0
def error(type, comment, cat):
    logs.print_error("FATAL ERROR {}".format(cat))
    raise EXCEPTIONS[type](comment)