WIP, BROKEN

This commit is contained in:
Ivan Habunek 2024-04-29 09:12:44 +02:00
parent 47d62bc471
commit d0543bbebe
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
2 changed files with 9 additions and 15 deletions

View File

@ -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()

View File

@ -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