mirror of
https://github.com/ihabunek/twitch-dl
synced 2024-08-30 18:32:25 +00:00
Fix a crash when downloading clips
This commit is contained in:
parent
789d3d1939
commit
42f7a9a1a5
@ -2,6 +2,7 @@
|
||||
date: TBA
|
||||
changes:
|
||||
- "Add `clips --target-dir` option. Use in conjunction with `--download` to specify target directory."
|
||||
- "Fix a crash when downloading clips (#160)"
|
||||
|
||||
2.3.1:
|
||||
date: 2024-05-19
|
||||
|
@ -2,12 +2,13 @@ import re
|
||||
import sys
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from typing import Callable, Generator, Optional
|
||||
from typing import Callable, Generator, List, Optional
|
||||
|
||||
import click
|
||||
|
||||
from twitchdl import twitch, utils
|
||||
from twitchdl.commands.download import get_clip_authenticated_url
|
||||
from twitchdl.entities import VideoQuality
|
||||
from twitchdl.http import download_file
|
||||
from twitchdl.output import green, print_clip, print_clip_compact, print_json, print_paged, yellow
|
||||
from twitchdl.twitch import Clip, ClipsPeriod
|
||||
@ -47,8 +48,8 @@ def clips(
|
||||
return _print_all(generator, print_fn, all)
|
||||
|
||||
|
||||
def _target_filename(clip: Clip):
|
||||
url = clip["videoQualities"][0]["sourceURL"]
|
||||
def _target_filename(clip: Clip, video_qualities: List[VideoQuality]):
|
||||
url = video_qualities[0]["sourceURL"]
|
||||
_, ext = path.splitext(url)
|
||||
ext = ext.lstrip(".")
|
||||
|
||||
@ -74,7 +75,12 @@ def _download_clips(target_dir: Path, generator: Generator[Clip, None, None]):
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for clip in generator:
|
||||
target = target_dir / _target_filename(clip)
|
||||
# videoQualities can be null in some circumstances, see:
|
||||
# https://github.com/ihabunek/twitch-dl/issues/160
|
||||
if not clip["videoQualities"]:
|
||||
continue
|
||||
|
||||
target = target_dir / _target_filename(clip, clip["videoQualities"])
|
||||
|
||||
if target.exists():
|
||||
click.echo(f"Already downloaded: {green(target)}")
|
||||
|
@ -60,7 +60,7 @@ class Clip(TypedDict):
|
||||
viewCount: int
|
||||
durationSeconds: int
|
||||
url: str
|
||||
videoQualities: List[VideoQuality]
|
||||
videoQualities: Optional[List[VideoQuality]]
|
||||
game: Game
|
||||
broadcaster: User
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user