Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

44 deal with files which are not part of the feed #45

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion e2e/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use_config,
podcast_directory,
)
from e2e.random import generate_random_string
from e2e.random import call_n_times, generate_random_mp3_file, generate_random_string


def test_configuration_hierarchy(
Expand Down Expand Up @@ -39,3 +39,39 @@ def test_configuration_hierarchy(

# Assert
assert len(podcast_directory.get_files_list()) == 1


def test_ignore_files_not_being_part_of_the_feed(
feed: FeedBuilder,
use_config: Callable[[Dict], None],
podcast_directory: PodcastDirectory,
):
# Arrange
feed.add_random_entries()
not_podcasts_files = call_n_times(generate_random_mp3_file)
for file_name in not_podcasts_files:
podcast_directory.add_file(file_name)

last_podcast_file = generate_random_mp3_file()
feed.add_entry(file_name=last_podcast_file)

use_config(
{
"podcasts": [
{
"if_directory_empty": "download_last",
"path": podcast_directory.path(),
"rss_link": feed.get_feed_url(),
}
],
}
)

# Act
run_podcast_downloader()

# Assert
podcast_directory.is_containing_only(
[file_name.lower() for file_name in not_podcasts_files]
+ [last_podcast_file.lower()]
)
32 changes: 20 additions & 12 deletions podcast_downloader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def configuration_to_function_rss_to_name(
to_name_function = configuration_to_function_rss_to_name(
rss_file_name_template_value, rss_source
)

on_directory_empty = configuration_to_function_on_empty_directory(
rss_if_directory_empty
)
Expand All @@ -216,6 +217,24 @@ def configuration_to_function_rss_to_name(
get_extensions_checker(rss_podcast_extensions), rss_source_path
)
)

allow_link_types = list(set(rss_podcast_extensions.values()))

all_feed_entries = compose(
list,
partial(filter, build_only_allowed_filter_for_link_data(allow_link_types)),
flatten_rss_links_data,
get_raw_rss_entries_from_web,
)(rss_source_link)

to_real_podcast_file_name = compose(
partial(limit_file_name, file_length_limit), to_name_function
)

all_feed_files = list(map(to_real_podcast_file_name, all_feed_entries))

downloaded_files = [feed for feed in all_feed_files if feed in downloaded_files]

last_downloaded_file = downloaded_files[0] if downloaded_files else None

download_limiter_function = (
Expand All @@ -224,22 +243,11 @@ def configuration_to_function_rss_to_name(
else on_directory_empty
)

allow_link_types = list(set(rss_podcast_extensions.values()))
missing_files_links = compose(
list,
download_limiter_function,
partial(filter, build_only_allowed_filter_for_link_data(allow_link_types)),
flatten_rss_links_data,
get_raw_rss_entries_from_web,
)(rss_source_link)
missing_files_links = compose(list, download_limiter_function)(all_feed_entries)

logger.info('Last downloaded file "%s"', last_downloaded_file or "<none>")

if missing_files_links:
to_real_podcast_file_name = compose(
partial(limit_file_name, file_length_limit), to_name_function
)

download_podcast = partial(
download_rss_entity_to_path,
rss_https_header,
Expand Down