Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
feat: allow playlist urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Jan 4, 2024
1 parent e85d586 commit 81b1805
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ def process_issue_update(database_url: Optional[str] = None, youtube_url: Option
def check_youtube(data: dict) -> str:
url = data['youtube_theme_url'].strip()

# determine if playlist
# https://www.youtube.com/watch?v=<video_id>&list=<list_id>&index=<1-based-index>
if '&list=' in url or '?list=' in url:
url = url.split('&list=')[0]

# url provided, now process it using youtube_dl
youtube_dl_params = dict(
outmpl='%(id)s.%(ext)s',
Expand All @@ -477,8 +482,12 @@ def check_youtube(data: dict) -> str:
exception_writer(error=e, name='youtube')
else:
if 'entries' in result:
# Can be a playlist or a list of videos
video_data = result['entries'][0]
exception_writer(

Check warning on line 485 in src/updater.py

View check run for this annotation

Codecov / codecov/patch

src/updater.py#L485

Added line #L485 was not covered by tests
error=Exception(
"Error processing YouTube url: multiple videos found, but URL doesn't indicate a playlist"),
name='youtube',
end_program=True
)
else:
# Just a video
video_data = result
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_issue_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ def test_process_issue_update(db_url, db_type, issue_update_args, igdb_auth, tmd
assert data == db_type


def test_check_youtube(youtube_url):
@pytest.mark.parametrize('url_suffix', [
'',
'&list=PLE0hg-LdSfycrpTtMImPSqFLle4yYNzWD',
])
def test_check_youtube(youtube_url, url_suffix):
"""Tests if the provided YouTube url is valid and returns a valid url."""
yt_url = updater.check_youtube(data=dict(youtube_theme_url=youtube_url))
yt_url = updater.check_youtube(data=dict(youtube_theme_url=f'{youtube_url}{url_suffix}'))

host = urlparse(yt_url).hostname
scheme = urlparse(yt_url).scheme
Expand Down

0 comments on commit 81b1805

Please sign in to comment.