Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Sep 5, 2024
1 parent 970196c commit 1d85406
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
11 changes: 9 additions & 2 deletions changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
2.7.0:
date: 2024-09-05
changes:
- "Embed chapter metadata in video, allows skipping to chapter if video player supports it"
- "Increase default worker count to 10, seems to improve speeds"
- "Add `--json` option to `chat` command"
- "Improvements to chat renderer"

2.6.0:
date: 2024-08-30
changes:
- Add `chat` command for rendering twitch chat as a video which can then be
embedded into a downloaded stream using ffmpeg.
- "Add `chat` command for rendering twitch chat as a video which can then be embedded into a downloaded stream using ffmpeg."

2.5.0:
date: 2024-08-30
Expand Down
40 changes: 24 additions & 16 deletions twitchdl/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from twitchdl.exceptions import ConsoleError
from twitchdl.http import download_all, download_file
from twitchdl.naming import clip_filename, video_filename
from twitchdl.output import blue, bold, green, print_log, yellow
from twitchdl.output import blue, bold, green, print_error, print_log, yellow
from twitchdl.playlists import (
enumerate_vods,
get_init_sections,
Expand All @@ -38,16 +38,29 @@ def download(ids: List[str], args: DownloadOptions):
download_one(video_id, args)


def download_one(video: str, args: DownloadOptions):
video_id = utils.parse_video_identifier(video)
def download_one(id_or_slug: str, args: DownloadOptions):
video_id = utils.parse_video_identifier(id_or_slug)
if video_id:
return _download_video(video_id, args)
print_log("Looking up video...")
video = twitch.get_video(video_id)
if video:
_download_video(video, args)
else:
print_error(f"Video '{video_id}' not found")
return

slug = utils.parse_clip_identifier(id_or_slug)
if slug:
print_log("Looking up clip...")
clip = twitch.get_clip(slug)

clip_slug = utils.parse_clip_identifier(video)
if clip_slug:
return _download_clip(clip_slug, args)
if clip:
_download_clip(slug, args)
else:
print_error(f"Clip '{slug}' not found")
return

raise ConsoleError(f"Invalid input: {video}")
raise ConsoleError(f"Invalid input: {id_or_slug}")


def _join_vods(playlist_path: Path, metadata_path: Path, target: Path, overwrite: bool):
Expand Down Expand Up @@ -177,16 +190,11 @@ def _download_clip(slug: str, args: DownloadOptions) -> None:
click.echo(f"Downloaded: {blue(target)}")


def _download_video(video_id: str, args: DownloadOptions) -> None:
print_log("Looking up video...")
video = twitch.get_video(video_id)

if not video:
raise ConsoleError(f"Video {video_id} not found")
def _download_video(video: Video, args: DownloadOptions) -> None:
video_id = video["id"]
target = Path(video_filename(video, args.format, args.output))

click.echo(f"Found: {blue(video['title'])} by {yellow(video['creator']['displayName'])}")

target = Path(video_filename(video, args.format, args.output))
click.echo(f"Output: {blue(target)}")

overwrite = args.overwrite
Expand Down
4 changes: 4 additions & 0 deletions twitchdl/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def print_log(message: Any, *, nl: bool = True):
click.secho(message, err=True, dim=True, nl=nl)


def print_error(message: Any):
click.secho(message, err=True, fg="red")


_prev_transient = False


Expand Down

0 comments on commit 1d85406

Please sign in to comment.