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

Check for empty playlists after filtering, and after downloading videos #376

Merged
merged 1 commit into from
Nov 1, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Check for empty playlists after filtering, and after downloading videos (#375)

## [3.2.1] - 2024-11-01

### Deprecated
Expand Down
30 changes: 21 additions & 9 deletions scraper/src/youtube2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,19 @@
# we only return video_ids that we'll use later on. per-playlist JSON stored
for playlist in self.playlists:
videos_json = get_videos_json(playlist.playlist_id)
if len(videos_json) == 0:
logger.warning(
f"Playlist '{playlist.playlist_id}' is empty, will be ignored"
)
empty_playlists.append(playlist)
# filter in videos within date range and filter away deleted videos
skip_outofrange = functools.partial(
skip_outofrange_videos, self.dateafter
)
filter_videos = filter(skip_outofrange, videos_json)
filter_videos = filter(skip_deleted_videos, filter_videos)
filter_videos = filter(skip_non_public_videos, filter_videos)
filter_videos = list(filter_videos)

Check warning on line 575 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L575

Added line #L575 was not covered by tests
if len(filter_videos) == 0:
logger.warning(

Check warning on line 577 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L577

Added line #L577 was not covered by tests
f"Playlist '{playlist.playlist_id}' is empty, will be ignored"
)
empty_playlists.append(playlist)

Check warning on line 580 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L580

Added line #L580 was not covered by tests
all_videos.update(
{v["contentDetails"]["videoId"]: v for v in filter_videos}
)
Expand Down Expand Up @@ -1154,10 +1155,21 @@
home_playlist_list = []

main_playlist_slug = None
if len(self.playlists) > 0:
main_playlist_slug = get_playlist_slug(
self.playlists[0]
) # set first playlist as main playlist
empty_playlists = list(
filter(lambda playlist: len(get_videos_list(playlist)) == 0, self.playlists)
)
for empty_playlist in empty_playlists:
logger.warning(

Check warning on line 1162 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L1162

Added line #L1162 was not covered by tests
f"Removing finally empty playlist {empty_playlist.playlist_id}"
)
self.playlists.remove(empty_playlist)

Check warning on line 1165 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L1165

Added line #L1165 was not covered by tests

if len(self.playlists) == 0:
raise Exception("No playlist succeeded to download")

Check warning on line 1168 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L1168

Added line #L1168 was not covered by tests

main_playlist_slug = get_playlist_slug(

Check warning on line 1170 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L1170

Added line #L1170 was not covered by tests
self.playlists[0]
) # set first playlist as main playlist

for playlist in self.playlists:
playlist_slug = get_playlist_slug(playlist)
Expand Down