Skip to content

Commit

Permalink
Fix -m download when no resolution metadata is available for some mp4…
Browse files Browse the repository at this point in the history
… formats
  • Loading branch information
ddelange committed Jan 13, 2021
1 parent 88b15e8 commit b508892
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/main.yml

This file was deleted.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ Easiest would be using the [Windows Subsystem for Linux (WSL)](https://docs.micr
- Put [`yt`](yt/yt) in your path.
## Usage
Some examples:
tl;dr:
- Type `yt -h` to print the following text and exit.
- Type `yt` to download audio files for the (space separated) URL(s) fetched from clipboard.
- Type `yt -v` for (max) 1080p mkv download.
- Type `yt` to download audio files for the (space separated) URL(s) fetched from clipboard (see also `-c`).
- Type `yt -vH -P 2160` do download best quality (4K HDR if available) into mkv.
```
NAME
Expand Down Expand Up @@ -118,8 +119,8 @@ OPTIONS
Enable video mode. Defaults to audio mode. Only mono and stereo are supported.
-c
Fetch space separated URLs from clipboard. Overwrites manually passed URLs.
Auto-enables when no URLs are manually passed.
Fetch space separated URLs from clipboard, additional to the manually passed
URLs. Auto-enables when no URLs are manually passed.
-D POSIX_PATH
Set the destination path. Used for both the (intermediate) output and for the
Expand All @@ -143,7 +144,7 @@ OPTIONS
-P PIXELS
Set the maximum height in pixels of the video output. Ignored when -v is not
specified. Defaults to 1080px.
specified. Defaults to 1080px. Constraint is dropped when no formats comply.
-m
Use MP4 when merging audio/video streams, keeping video codecs if possible and
Expand Down
26 changes: 16 additions & 10 deletions yt/yt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ OPTIONS
Enable video mode. Defaults to audio mode. Only mono and stereo are supported.
-c
Fetch space separated URLs from clipboard. Overwrites manually passed URLs.
Auto-enables when no URLs are manually passed.
Fetch space separated URLs from clipboard, additional to the manually passed
URLs. Auto-enables when no URLs are manually passed.
-D POSIX_PATH
Set the destination path. Used for both the (intermediate) output and for the
Expand All @@ -72,7 +72,7 @@ OPTIONS
-P PIXELS
Set the maximum height in pixels of the video output. Ignored when -v is not
specified. Defaults to 1080px.
specified. Defaults to 1080px. Constraint is dropped when no formats comply.
-m
Use MP4 when merging audio/video streams, keeping video codecs if possible and
Expand Down Expand Up @@ -264,22 +264,28 @@ All rights reserved."


# DOWNLOAD_OPTIONS
local audio_selector="bestaudio[acodec=opus]/bestaudio[container*=dash]/bestaudio"
local audio_selector='bestaudio[acodec=opus]/bestaudio[container*=dash]/bestaudio'
local px_spec="height<=${MAX_PIXELS}"
local hdr_selector="bestvideo[vcodec^=vp9][${px_spec}]/bestvideo[${px_spec}]/bestvideo"
local avc_selector="bestvideo[vcodec^=avc][${px_spec}]/bestvideo"'[vcodec!^=vp9]'"[${px_spec}]/bestvideo[ext=mp4]"
local av1_selector="bestvideo[vcodec^=av01][${px_spec}]/bestvideo[vcodec^=av][${px_spec}]/bestvideo"'[vcodec!^=vp9]'"[${px_spec}]/bestvideo[ext=mp4]"
local default_video_selector="bestvideo[vcodec=vp9][${px_spec}]/bestvideo[vcodec!=vp9.2][${px_spec}]/bestvideo[${px_spec}]/bestvideo"
local fallback_video_selector="best[${px_spec}]/best"
if $VIDEO_MODE; then
if $HDR; then
local DOWNLOAD_OPTIONS=(--merge-output-format mkv -f "(bestvideo[vcodec^=vp9][height<=${MAX_PIXELS}]/bestvideo[height<=${MAX_PIXELS}])+(${audio_selector})/best[height<=${MAX_PIXELS}]")
local DOWNLOAD_OPTIONS=(--merge-output-format mkv -f "(${hdr_selector})+(${audio_selector})/${fallback_video_selector}")
elif $MP4; then
local DOWNLOAD_OPTIONS=(--merge-output-format mp4 --postprocessor-args "-threads 0 -vcodec copy -acodec aac -b:a ${AUDIO_BITRATE}k -ar ${AUDIO_SAMPLING_RATE}")
if [ $MAX_PIXELS -gt 1080 ] && ! $SILENT; then
echo "Maximum resolution is set to ${MAX_PIXELS} and -m is present. Downloads will be limited to max 1080p on sites that don't provide higher resolution video streams in MP4 container (e.g. YouTube)."
echo "Maximum resolution is set to ${MAX_PIXELS}, and -m is present. Downloads will be limited to max 1080p on sites that don't provide higher resolution video streams in MP4 container (e.g. YouTube)."
fi
local DOWNLOAD_OPTIONS=(--merge-output-format mp4 --postprocessor-args "-threads 0 -vcodec copy -acodec aac -b:a ${AUDIO_BITRATE}k -ar ${AUDIO_SAMPLING_RATE}")
if $AVC; then
DOWNLOAD_OPTIONS+=(-f "(bestvideo[vcodec^=avc][height<=${MAX_PIXELS}]/bestvideo"'[vcodec!^=vp9]'"[height<=${MAX_PIXELS}])+(${audio_selector})/best[height<=${MAX_PIXELS}]")
DOWNLOAD_OPTIONS+=(-f "(${avc_selector})+(${audio_selector})/${fallback_video_selector}")
else
DOWNLOAD_OPTIONS+=(-f "(bestvideo[vcodec^=av01][height<=${MAX_PIXELS}]/bestvideo[vcodec^=av][height<=${MAX_PIXELS}]/bestvideo"'[vcodec!^=vp9]'"[height<=${MAX_PIXELS}])+(${audio_selector})/best[height<=${MAX_PIXELS}]")
DOWNLOAD_OPTIONS+=(-f "(${av1_selector})+(${audio_selector})/${fallback_video_selector}")
fi
else
local DOWNLOAD_OPTIONS=(--merge-output-format mkv -f "(bestvideo[vcodec=vp9][height<=${MAX_PIXELS}]/bestvideo[vcodec!=vp9.2][height<=${MAX_PIXELS}])+(${audio_selector})/best[height<=${MAX_PIXELS}]")
local DOWNLOAD_OPTIONS=(--merge-output-format mkv -f "(${default_video_selector})+(${audio_selector})/${fallback_video_selector}")
fi
else
local DOWNLOAD_OPTIONS=(--embed-thumbnail --audio-format m4a --audio-quality ${AUDIO_BITRATE}k --postprocessor-args "-ar ${AUDIO_SAMPLING_RATE}" -x -f "${audio_selector}/best")
Expand Down

0 comments on commit b508892

Please sign in to comment.