Ejemplo n.º 1
0
def download(id):
    with app.app_context():
        d = Download.find(id)
        opts = {
            'outtmpl': '/downloads/%(title)s-%(id)s.%(ext)s',
            'progress_hooks': [d.set_details]
        }
        y = YoutubeDL(params=opts)
        y.download([d.url])
Ejemplo n.º 2
0
def ydl_download(self, download_id):
    with app.app_context():
        d = Download.query.filter_by(id=download_id).first()
        opts = {
            'noplaylist': not d.playlist,
            'outtmpl': d.outtmpl,
            'progress_hooks': [d.progress_hook],
            'format': d.df.ydl_format,
            'sleep_interval': 60,
            'max_sleep_interval': 300,
        }
        y = YoutubeDL(params=opts)
        try:
            y.download([d.url])
        except DownloadError:
            d.status = DownloadStatus.ERROR
            d.save()
Ejemplo n.º 3
0
def main():
    ns = parse_args()

    ydl = YoutubeDL({
        'quiet': True,
        'outtmpl': '%(title).%(ext)s',
        'simulate': ns.simulate,
    })

    ydl.add_info_extractor(YoutubeSearchIE())
    ydl.add_info_extractor(YoutubeIE())

    ydl.add_post_processor(FFmpegExtractAudioPP())

    artist = Artist(ns.artista)

    if not artist.found:
        print('ERROR: %s no existe' % artist.name)
        return 1

    print('Obteniendo información de %s...' % artist.name)
    artist.parse()

    if not ns.simulate and not os.path.exists(artist.name):
        os.mkdir(artist.name)

    if ns.disco is None:
        albums = artist.albums
    else:
        album = artist.get_album(ns.disco)

        if album is None or not album.found:
            print('ERROR: %s no tiene un disco %s' % (artist.name, ns.disco))
            return 1

        albums = [album]

    for album in albums:
        if not album.found:
            print('Ignorando %s' % album.name)
            continue

        fpath = os.path.join(artist.name, '%s - %s' % (album.year, album.name))

        if not ns.simulate and not os.path.exists(fpath):
            os.mkdir(fpath)

        if ns.disco is None:
            print('%s:' % album.name)
        else:
            print('Obteniendo lista de temas...')

        album.parse()

        for song in album.songs:
            fname = FILE_FORMAT % (album.songs.index(song) + 1, song)

            print(' %s' % fname)

            ydl.params['outtmpl'] = os.path.join(fpath, fname + '.%(ext)s')
            ydl.download(['ytsearch:%s %s' % (artist.name, song)])

    return 0