Пример #1
0
def run_youtube_dl(video_link, options):
    with YoutubeDL(options) as ydl:
        info = ydl.extract_info(video_link, download=False)

    session['filename_stem'] = Path(ydl.prepare_filename(info)).stem
    
    try:
        ydl.download([video_link])
    except Exception as error:
        log.error(f'Error downloading {session["filename_stem"]}:\n{str(error)}')
        session['youtube_dl_error'] = str(error)
    else:
        log_downloads_per_day()
Пример #2
0
def run_youtube_dl(video_link, options):
    is_downloading = True
    download_start_time = time()
    try:
        with YoutubeDL(options) as ydl:
            ydl.download(video_link)
    except Exception as error:
        log.error(f'Error downloading file:\n{error}')
        session['youtube_dl_error'] = str(error)
    else:
        download_complete_time = time()
        log.info(f'Download took {round((download_complete_time - download_start_time), 1)}s')
        log_downloads_per_day()
    finally:
        is_downloading = False
Пример #3
0
def run_youtube_dl(video_link, options):
    try:
        with YoutubeDL(options) as ydl:
            info = ydl.extract_info(video_link, download=False)
        global filename
        # Remove the file extension and the 'downloads/' at the start.
        filename = os.path.splitext(ydl.prepare_filename(info))[0][10:]
        download_start_time = time()
        ydl.download([video_link])
    except Exception as error:
        log.error(f'Error downloading file:\n{error}')
        session['youtube_dl_error'] = str(error)
    else:
        download_complete_time = time()
        log.info(
            f'Download took {round((download_complete_time - download_start_time), 1)}s'
        )
        log_downloads_per_day()