From a262414157a7551752605506d7c9b0fc9fc8a331 Mon Sep 17 00:00:00 2001 From: Taras Terletskyi <888784+tropicoo@users.noreply.github.com> Date: Thu, 6 Jul 2023 23:27:43 +0300 Subject: [PATCH] Version 1.4.2 --- README.md | 4 +++- RELEASES.md | 20 ++++++++++++++++++++ app_worker/cookies/cookies.txt | 0 app_worker/worker/utils.py | 14 ++++++++++++++ app_worker/ytdl_opts/default.py | 2 ++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app_worker/cookies/cookies.txt diff --git a/README.md b/README.md index cf9018f..b78410f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Simple and reliable self-hosted YouTube Download Telegram Bot. -Version: 1.4.1. [Release details](RELEASES.md). +Version: 1.4.2. [Release details](RELEASES.md). ![frames](.assets/download_success.png) @@ -92,6 +92,8 @@ or something went wrong. is the premium user, you're allowed to upload files up to 4GB (4294967296 bytes) and can change the default value stored in the `upload_video_max_file_size` config variable. +5. If the website you want to download from requires authentication you can use your cookies by putting them into + the `app_worker/cookies/cookies.txt` file in the Netscape format. ## 🛑 Failed download diff --git a/RELEASES.md b/RELEASES.md index 48e58a4..39a5261 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,23 @@ +## Release 1.4.2 + +Release date: July 06, 2023 + +## New Features + +- Use cookies for website auth for download by putting them into the `app_worker/cookies/cookies.txt` file in Netscape + format. + +## Important + +- If you are using the customized yt-dlp options in the `app_worker/ytdl_opts/user.py` you must reconfigure them from + the updated `app_worker/ytdl_opts/default.py`. + +## Misc + +N/A + +--- + ## Release 1.4.1 Release date: March 29, 2023 diff --git a/app_worker/cookies/cookies.txt b/app_worker/cookies/cookies.txt new file mode 100644 index 0000000..e69de29 diff --git a/app_worker/worker/utils.py b/app_worker/worker/utils.py index 9e5afbc..d86d5c8 100644 --- a/app_worker/worker/utils.py +++ b/app_worker/worker/utils.py @@ -1,5 +1,9 @@ +import os + import yt_dlp +_COOKIES_FILEPATH = '/app/cookies/cookies.txt' + def cli_to_api(opts: list) -> dict: """Convert yt-dlp CLI options to internal API ones.""" @@ -12,3 +16,13 @@ def cli_to_api(opts: list) -> dict: pp for pp in diff['postprocessors'] if pp not in default['postprocessors'] ] return diff + + +def is_file_empty(filepath: str) -> bool: + """Check whether the file is empty.""" + return os.path.isfile(filepath) and os.path.getsize(filepath) == 0 + + +def get_cookies_opts_if_not_empty() -> list[str]: + """Return yt-dlp cookies option with cookies filepath.""" + return [] if is_file_empty(_COOKIES_FILEPATH) else ['--cookies', _COOKIES_FILEPATH] diff --git a/app_worker/ytdl_opts/default.py b/app_worker/ytdl_opts/default.py index 609a37f..e75fe7e 100644 --- a/app_worker/ytdl_opts/default.py +++ b/app_worker/ytdl_opts/default.py @@ -6,6 +6,7 @@ More here https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/options.py or 'yt- If you want to change any of these values or add new ones, copy all content to the `user.py` in the same directory as this file, and edit the values. """ +from worker.utils import get_cookies_opts_if_not_empty FINAL_AUDIO_FORMAT = 'mp3' FINAL_THUMBNAIL_FORMAT = 'jpg' @@ -20,6 +21,7 @@ DEFAULT_YTDL_OPTS = [ '5', '--ignore-errors', '--verbose', + *get_cookies_opts_if_not_empty(), ] AUDIO_YTDL_OPTS = [