Skip to content

Commit

Permalink
Implement the download_delay
Browse files Browse the repository at this point in the history
  • Loading branch information
dplocki committed Apr 14, 2024
1 parent 8a58011 commit 3921f25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions podcast_downloader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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: [],
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions podcast_downloader/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3921f25

Please sign in to comment.