From 3921f25caee3872083f33146029d0cefe81bc106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20P=C5=82ocki?= Date: Sun, 14 Apr 2024 16:11:09 +0200 Subject: [PATCH] Implement the download_delay --- podcast_downloader/__main__.py | 18 ++++++++++++++++++ podcast_downloader/configuration.py | 1 + 2 files changed, 19 insertions(+) diff --git a/podcast_downloader/__main__.py b/podcast_downloader/__main__.py index 733b201..ea95f84 100644 --- a/podcast_downloader/__main__.py +++ b/podcast_downloader/__main__.py @@ -84,6 +84,13 @@ def build_parser() -> argparse.ArgumentParser: help="The path to configuration file", ) + parser.add_argument( + "--download_delay", + required=False, + type=int, + help="The waiting time (seconds) between downloads", + ) + return parser @@ -167,6 +174,7 @@ def configuration_to_function_rss_to_name( configuration.CONFIG_FILE_NAME_TEMPLATE: "%file_name%.%file_extension%", configuration.CONFIG_HTTP_HEADER: {"User-Agent": "podcast-downloader"}, configuration.CONFIG_FILL_UP_GAPS: False, + configuration.CONFIG_DOWNLOAD_DELAY: 0, configuration.CONFIG_PODCASTS: [], } @@ -222,6 +230,10 @@ def configuration_to_function_rss_to_name( CONFIGURATION[configuration.CONFIG_FILL_UP_GAPS], rss_source.get(configuration.CONFIG_FILL_UP_GAPS, False), ) + rss_download_delay = rss_source.get( + CONFIGURATION[configuration.CONFIG_DOWNLOAD_DELAY], + rss_source.get(configuration.CONFIG_DOWNLOAD_DELAY, 0), + ) if rss_disable: logger.info('Skipping the "%s"', rss_source_name or rss_source_link) @@ -295,7 +307,13 @@ def configuration_to_function_rss_to_name( to_real_podcast_file_name, ) + first_element = True for rss_entry in reversed(missing_files_links): + if rss_download_delay > 0: + if not first_element: + time.sleep(rss_download_delay) + first_element = False + wanted_podcast_file_name = to_name_function(rss_entry) if wanted_podcast_file_name in downloaded_files: continue diff --git a/podcast_downloader/configuration.py b/podcast_downloader/configuration.py index a7f680f..6c49df3 100644 --- a/podcast_downloader/configuration.py +++ b/podcast_downloader/configuration.py @@ -11,6 +11,7 @@ CONFIG_PODCAST_EXTENSIONS = "podcast_extensions" CONFIG_HTTP_HEADER = "http_headers" CONFIG_FILL_UP_GAPS = "fill_up_gaps" +CONFIG_DOWNLOAD_DELAY = "download_delay" CONFIG_PODCASTS = "podcasts" CONFIG_PODCASTS_NAME = "name"