From d0543bbebe624024f139b23774ecc36bc3632452 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Mon, 29 Apr 2024 09:12:44 +0200 Subject: [PATCH] WIP, BROKEN --- twitchdl/commands/download.py | 5 +++-- twitchdl/playlists.py | 19 ++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/twitchdl/commands/download.py b/twitchdl/commands/download.py index 75d5182..3380a3f 100644 --- a/twitchdl/commands/download.py +++ b/twitchdl/commands/download.py @@ -282,7 +282,8 @@ def _download_video(video_id: str, args: DownloadOptions) -> None: return base_uri = re.sub("/[^/]+$", "/", playlist.url) - target_dir = _crete_temp_dir(base_uri) + target_dir = f".twitch_dl_{video_id}_{playlist.group_id}" + os.makedirs(target_dir, exist_ok=True) # Save playlists for debugging purposes with open(path.join(target_dir, "playlists.m3u8"), "w") as f: @@ -296,7 +297,7 @@ def _download_video(video_id: str, args: DownloadOptions) -> None: targets = [os.path.join(target_dir, f"{vod.index:05d}.ts") for vod in vods] asyncio.run(download_all(sources, targets, args.max_workers, rate_limit=args.rate_limit)) - join_playlist = make_join_playlist(vods_m3u8, vods, targets) + join_playlist = make_join_playlist(vods, targets) join_playlist_path = path.join(target_dir, "playlist_downloaded.m3u8") join_playlist.dump(join_playlist_path) # type: ignore click.echo() diff --git a/twitchdl/playlists.py b/twitchdl/playlists.py index 3a27058..a2521c7 100644 --- a/twitchdl/playlists.py +++ b/twitchdl/playlists.py @@ -3,7 +3,8 @@ Parse and manipulate m3u8 playlists. """ from dataclasses import dataclass -from typing import Generator, List, Optional, OrderedDict +from os.path import basename +from typing import Generator, List, Optional import click import m3u8 @@ -78,23 +79,15 @@ def enumerate_vods( return vods -def make_join_playlist( - playlist: m3u8.M3U8, - vods: List[Vod], - targets: List[str], -) -> m3u8.Playlist: +def make_join_playlist(vods: List[Vod], targets: List[str]) -> m3u8.Playlist: """ Make a modified playlist which references downloaded VODs Keep only the downloaded segments and skip the rest """ - org_segments = playlist.segments.copy() + playlist = m3u8.M3U8() - path_map = OrderedDict(zip([v.path for v in vods], targets)) - playlist.segments.clear() - for segment in org_segments: - if segment.uri in path_map: - segment.uri = path_map[segment.uri] - playlist.segments.append(segment) + for vod, target in zip(vods, targets): + playlist.add_segment(m3u8.Segment(uri=basename(target), duration=vod.duration)) return playlist