Download init segments

These seem to occur in hd quality playlists like 1440p.
This commit is contained in:
Ivan Habunek 2024-08-30 11:42:54 +02:00
parent 2feef136ca
commit ac7cdba28e
No known key found for this signature in database
GPG Key ID: 01DB3DD0D824504C
2 changed files with 16 additions and 1 deletions

View File

@ -19,6 +19,7 @@ from twitchdl.naming import clip_filename, video_filename
from twitchdl.output import blue, bold, green, print_log, yellow
from twitchdl.playlists import (
enumerate_vods,
get_init_sections,
load_m3u8,
make_join_playlist,
parse_playlists,
@ -231,6 +232,11 @@ def _download_video(video_id: str, args: DownloadOptions) -> None:
click.echo(f"\nDownloading {len(vods)} VODs using {args.max_workers} workers to {target_dir}")
init_sections = get_init_sections(vods_m3u8)
for uri in init_sections:
print_log(f"Downloading init section {uri}...")
download_file(f"{base_uri}{uri}", target_dir / uri)
sources = [base_uri + vod.path for vod in vods]
targets = [target_dir / f"{vod.index:05d}.ts" for vod in vods]

View File

@ -4,7 +4,7 @@ Parse and manipulate m3u8 playlists.
from dataclasses import dataclass
from pathlib import Path
from typing import Generator, List, Optional, OrderedDict
from typing import Generator, List, Optional, OrderedDict, Set
import click
import m3u8
@ -169,3 +169,12 @@ def _playlist_key(playlist: Playlist) -> int:
pass
return MAX
def get_init_sections(playlist: m3u8.M3U8) -> Set[str]:
# TODO: we're ignoring initi_section.base_uri and bytes
return set(
segment.init_section.uri
for segment in playlist.segments
if segment.init_section is not None
)