[BUGFIX] Use proper extractor key for download archive (#840)

For less popular sites, ytdl-sub's custom download archive was not working. This was because we weren't using the right extraction key (though it still worked for YouTube, Bandcamp, Soundcloud, and others). This bugfix should now exactly match yt-dlp's and never be a problem again.

Huge thanks to @Svagtlys for root-causing this 🤝
This commit is contained in:
Jesse Bannon 2023-12-14 17:04:03 -08:00 committed by GitHub
parent 8998861b49
commit 4d9a30779c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 4 deletions

View file

@ -13,7 +13,6 @@ from yt_dlp.utils import sanitize_filename
from ytdl_sub.entries.variables.kwargs import DESCRIPTION
from ytdl_sub.entries.variables.kwargs import EPOCH
from ytdl_sub.entries.variables.kwargs import EXTRACTOR
from ytdl_sub.entries.variables.kwargs import IE_KEY
from ytdl_sub.entries.variables.kwargs import TITLE
from ytdl_sub.entries.variables.kwargs import UID
@ -100,12 +99,12 @@ class BaseEntryVariables:
Returns
-------
str
The ytdl extractor name
The ytdl extractor name used in the download archive
"""
# pylint: disable=line-too-long
# Taken from https://github.com/yt-dlp/yt-dlp/blob/e6ab678e36c40ded0aae305bbb866cdab554d417/yt_dlp/YoutubeDL.py#L3514
# pylint: enable=line-too-long
return self.kwargs_get(EXTRACTOR) or self.kwargs(IE_KEY)
return str(self.kwargs_get("extractor_key") or self.kwargs(IE_KEY)).lower()
@property
def epoch(self: "BaseEntry") -> int:

View file

@ -1,7 +1,9 @@
import pytest
from conftest import assert_logs
from expected_download import assert_expected_downloads
from expected_transaction_log import assert_transaction_log_matches
from ytdl_sub.downloaders.ytdlp import YTDLP
from ytdl_sub.subscriptions.subscription import Subscription
@ -48,3 +50,19 @@ class TestSoundcloudDiscography:
dry_run=dry_run,
expected_download_summary_file_name="soundcloud/test_soundcloud_discography.json",
)
# Ensure another invocation will hit ExistingVideoReached
if not dry_run:
with assert_logs(
logger=YTDLP.logger,
expected_message="ExistingVideoReached, stopping additional downloads",
log_level="debug",
):
transaction_log = discography_subscription.download()
assert transaction_log.is_empty
assert_expected_downloads(
output_directory=output_directory,
dry_run=dry_run,
expected_download_summary_file_name="soundcloud/test_soundcloud_discography.json",
)

View file

@ -1,5 +1,5 @@
{
".ytdl-sub-Sithu Aye-download-archive.json": "0c58919b660f699f6aea2ec523c812c5",
".ytdl-sub-Sithu Aye-download-archive.json": "ca37a404a860a2a6b6b0f38b659c9f17",
"Sithu Aye/[2021] 10 Years Remixes and Reimaginings/01 - Double Helix Reimagined.mp3": "56f7ee579031f4795230e68b63b15f6b",
"Sithu Aye/[2021] 10 Years Remixes and Reimaginings/02 - Skye Reimagined.mp3": "dfb24e0ef03e203d471bb81f854f5cd3",
"Sithu Aye/[2021] 10 Years Remixes and Reimaginings/03 - Baryofusion.mp3": "95bd9ab2238e5372f445c59daafd0138",

View file

@ -68,6 +68,7 @@ def mock_entry_dict_factory(mock_downloaded_file_path) -> Callable:
PLAYLIST_INDEX: playlist_index,
PLAYLIST_COUNT: playlist_count,
EXTRACTOR: "mock-entry-dict",
"extractor_key": "mock-entry-dict",
TITLE: f"Mock Entry {uid}",
EXT: "mp4",
UPLOAD_DATE: upload_date,

View file

@ -163,6 +163,7 @@ def mock_entry_kwargs(
"id": uid,
"epoch": 1596878400,
"extractor": extractor,
"extractor_key": extractor,
"title": title,
"ext": ext,
"upload_date": upload_date,