Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: keep reference to m3u8 source

NTFSvolume64cd38e9d7d5
diff --git a/cyberdrop_dl/crawlers/_hls.py b/cyberdrop_dl/crawlers/_hls.py
index dee7a463e..7187e47fb 100644
--- a/cyberdrop_dl/crawlers/_hls.py
+++ b/cyberdrop_dl/crawlers/_hls.py
@@ -92,7 +92,7 @@ class HLSMixin(ABC):
) -> m3u8.M3U8:
check_ffmpeg_is_installed()
content = await self.request_text(url, headers=headers)
- return m3u8.M3U8(content, url.parent, media_type)
+ return m3u8.M3U8(content, url.parent, media_type, source=url)
@dataclasses.dataclass(slots=True)
diff --git a/cyberdrop_dl/downloader/hls.py b/cyberdrop_dl/downloader/hls.py
index b30f753bf..c1e0679d0 100644
--- a/cyberdrop_dl/downloader/hls.py
+++ b/cyberdrop_dl/downloader/hls.py
@@ -83,7 +83,7 @@ def _create_media_segments(
def _segments(m3u8: M3U8) -> list[Segment | InitializationSection]:
segments = m3u8.segment_map + m3u8.segments
if not segments:
- msg = f"{m3u8.media_type} m3u8 manifest ({m3u8.base_uri}) has no valid segments"
+ msg = f"{m3u8.media_type} m3u8 manifest ({m3u8.source}) has no valid segments"
raise DownloadError(HTTPStatus.NO_CONTENT, msg)
return segments
@@ -110,7 +110,13 @@ async def _download_m3u8(
download_folder=temp_dir / m3u8.media_type,
)
- logger.debug(f"Starting HLS download ({m3u8.media_type}, {len(segments):,} segments) for {media_item.real_url}")
+ logger.debug(
+ "Starting HLS download (%s, %s segments) for %s (%s)",
+ m3u8.media_type,
+ f"{len(segments):,}",
+ media_item.real_url,
+ m3u8.source,
+ )
results = await _download_segments(m_segments, m3u8.total_segments, download, sem)
await _merge_segments(tuple(result.item.path for result in results), output)
return output
diff --git a/cyberdrop_dl/utils/m3u8.py b/cyberdrop_dl/utils/m3u8.py
index 1f6dcacab..3963d78ef 100644
--- a/cyberdrop_dl/utils/m3u8.py
+++ b/cyberdrop_dl/utils/m3u8.py
@@ -11,10 +11,12 @@ from m3u8 import M3U8 as _M3U8
from m3u8 import Media, Playlist
from cyberdrop_dl.mediaprops import Codecs, Resolution
+from cyberdrop_dl.signature import simple_repr
from cyberdrop_dl.utils import parse_url
if TYPE_CHECKING:
from collections.abc import Generator, Iterable, Iterator
+ from pathlib import Path
from cyberdrop_dl.url_objects import AbsoluteHttpURL
@@ -157,20 +159,19 @@ class M3U8(_M3U8):
content: str,
base_uri: AbsoluteHttpURL | None = None,
media_type: Literal["video", "audio", "subtitle"] | None = None,
+ source: AbsoluteHttpURL | Path | None = None,
) -> None:
if base_uri and base_uri.suffix.casefold() == ".m3u8":
base_uri = base_uri.parent
self.media_type: Literal["video", "audio", "subtitle"] | None = media_type
+ self.source: AbsoluteHttpURL | Path | None = source
super().__init__(content, base_uri=str(base_uri) if base_uri else None)
@property
def total_segments(self) -> int:
return len(self.segment_map) + len(self.segments)
- def __repr__(self) -> str:
- return (
- f"{type(self)}(media_type={self.media_type!r}, base_uri={self.base_uri!r}, is_variant={self.is_variant!r})"
- )
+ __repr__ = simple_repr("media_type", "base_uri", "is_variant", "source")
@property
def total_duration(self) -> datetime.timedelta:
@@ -180,7 +181,7 @@ class M3U8(_M3U8):
class _LazyRenditionLog:
def __init__(self, groups: list[RenditionDetails]) -> None:
- self.groups = groups
+ self.groups: list[RenditionDetails] = groups
def __json__(self) -> tuple[dict[str, Any], ...]:
return tuple(rendition.__json__() for rendition in self.groups)