Skip to content

Commit

Permalink
youtube-dl-* => ytd-helper
Browse files Browse the repository at this point in the history
/close #101
  • Loading branch information
balupton committed Jan 3, 2022
1 parent e2480b1 commit 0a7a6ae
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 125 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ The [`podcast` command](https://github.com/bevry/dorothy/tree/master/commands/po

The [`podvideo` command](https://github.com/bevry/dorothy/tree/master/commands/podvideo) will convert a video file to a new file with h264+aac encoding.

The [`youtube-dl-archive` command](https://github.com/bevry/dorothy/tree/master/commands/youtube-dl-archive) will download something from youtube, with all the necessary extras such that you know you got everything.
The [`ytd-helper` command](https://github.com/bevry/dorothy/tree/master/commands/ytd-helper) provides some additional flags to make using `youtube-dl` easier.

The [`video-merge` command](https://github.com/bevry/dorothy/tree/master/commands/video-merge) will merge multiple video files in a directory together into a single video file.

Expand Down
29 changes: 0 additions & 29 deletions commands/youtube-dl-archive

This file was deleted.

6 changes: 0 additions & 6 deletions commands/youtube-dl-audio

This file was deleted.

8 changes: 0 additions & 8 deletions commands/youtube-dl-best

This file was deleted.

8 changes: 0 additions & 8 deletions commands/youtube-dl-embed

This file was deleted.

15 changes: 0 additions & 15 deletions commands/youtube-dl-free

This file was deleted.

8 changes: 0 additions & 8 deletions commands/youtube-dl-license

This file was deleted.

11 changes: 0 additions & 11 deletions commands/youtube-dl-native

This file was deleted.

26 changes: 0 additions & 26 deletions commands/youtube-dl-native-multiple

This file was deleted.

13 changes: 0 additions & 13 deletions commands/youtube-dl-native-playlists

This file was deleted.

153 changes: 153 additions & 0 deletions commands/ytd-helper
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env bash
source "$DOROTHY/sources/strict.bash"

# FOR THUMBNAILS
# AVIF is successor to WebP and the closed-source HEIF, however lacks wide support.
# WebP is successor to the below, and offers wide support.
# https://en.wikipedia.org/wiki/WebP
# JPEG patent expired in 2006
# JPEG-2000 is free to use
# PNG is an open-standard

# FOR CONTAINER
# https://en.wikipedia.org/wiki/Comparison_of_video_container_formats
# MKV is living, open-source and royalty free.
# WebM is VP9+Verbos only, it is royalty free, subset of MKV, wider support for ios, mac, and web browsers
# MP4 is royalty free with expired patents, supported by absolutely everything, but less featured than MKV and a bit outdated.
# https://en.wikipedia.org/wiki/ISO/IEC_base_media_file_format

# FOR FORMAT
# AV1 is royalty free and successor to VP9 and HEVC/H265, but no widespread hardware support
# VP9 is royalty free and successor to VP8 and H264, with moderate hardware support
# MP4/M4A is an affordable format which patents are still valid until 2023, with ubiquitous hardware support
# https://meta.wikimedia.org/wiki/Have_the_patents_for_MPEG-4_Visual_expired_yet%3F
# https://video.stackexchange.com/a/14699
#
# AV1 playlist:
# https://www.youtube.com/playlist?list=PLyqf6gJt7KuHBmeVzZteZUlNUQAVLwrZS
#
# AV1 is not viable without widespread hardware support:
# https://en.wikipedia.org/wiki/AV1#Hardware
# Running `ytd-helper --av1 BCmB-otRDeo` which is a 1 minute video, takes DAYS on a 2017 MacBook Pro.
# Use `ytd-helper --vp9` instead until AV1 has widespread hardware support sometime in 2023-2025.

# youtube-dl --help
# --no-overwrites Do not overwrite files
# --continue Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.
# --all-formats Download all available video formats
# --all-subs Download all the available subtitles of the video
# --geo-bypass Bypass geographic restriction via faking X-Forwarded-For HTTP header
# --write-all-thumbnails Write all thumbnail image formats to disk
# --write-annotations Write video annotations to a .annotations.xml file
# --write-auto-sub Write automatically generated subtitle file (YouTube only)
# --write-description Write video description to a .description file
# --write-info-json Write video metadata to a .info.json file
# --write-sub Write subtitle file

# dependencies
env QUIET=yes setup-util-jq

# arguments
args=()
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--embed')
args+=(
--embed-subs
--embed-thumbnail
--add-metadata
)
;;
'--archive')
# get all formats, bt don't use embed as many formats don't support embedding
args+=(
--no-overwrites
--continue
--all-formats
--all-subs
--geo-bypass
--write-all-thumbnails
--write-annotations
--write-auto-sub
--write-description
--write-info-json
--write-sub
)
;;
'--audio')
args+=(
--extract-audio
--format
'bestaudio[ext=m4a]'
)
;;
'--audio+video')
ytd --audio "${args[@]}" "$@"
ytd "${args[@]}" "$@"
return "$?"
;;
'--best')
args+=(
--format
'best'
)
;;
'--mp4')
args+=(
--recode-video
'mp4'
--merge-output-format
'mp4'
--format
'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
)
;;
'--free')
# `--prefer-free-formats` only prefers, it doesn't guarantee
args+=(
--format
'(bestvideo[vcodec^=av01]/bestvideo[vcodec^=vp9])+bestaudio[acodec=opus]'
)
;;
'--vp9')
args+=(
--recode-video
'webm'
--merge-output-format
'webm'
--format
'(bestvideo[vcodec^=vp9]/bestvideo)+bestaudio[acodec=opus]'
--postprocessor-args
'-c:a libopus -c:v vp9 -strict experimental'
)
;;
'--av1')
args+=(
--recode-video
'mkv'
--merge-output-format
'mkv'
--format
'(bestvideo[vcodec^=av01]/bestvideo)+bestaudio[acodec=opus]'
--postprocessor-args
'-c:a libopus -c:v av1 -strict experimental'
)
;;
'--playlist')
args+=(
--playlist-reverse
--ignore-errors
--output
'%(playlist_id)s -- %(playlist_title)s/%(playlist_index)s/%(id)s -- %(title)s.%(ext)s'
)
;;
*)
args+=("$item")
;;
esac
done

# action
echo-eval youtube-dl "${args[@]}"

0 comments on commit 0a7a6ae

Please sign in to comment.