Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -x
- yt=https://www.youtube.com
- ytl=$1
- shift
- fmt=${1:-136+140/bestvideo[height<=?720][vcodec^=?avc1]+140/bestvideo[height<=?720][vcodec^=?avc1]+bestaudio/bestvideo+bestaudio/best}
- shift
- opt=("$@")
- youtube-dl "$yt/$ytl" "${opt[@]}" --flat-playlist --dump-json |
- jq -r '"\(.id)\t\(.title)"' |
- nl -w1 |
- while IFS=$'\t' read -r n id title
- do
- printf '\n\n-----\n\n\n'
- name=$(printf '%03d %s (%s)' "$n" "${title//[\/:?*]/-}" "$id")
- set -- *[-\(]"$id"[\).][^f]*
- if test -e "$1" && test -z "$2"
- then
- name+=.${1##*.}
- test "$1" = "$name" || mv -v "$1" "$name"
- else
- sleep 10
- stderr=$(
- youtube-dl "$yt/watch?v=$id" \
- --format "$fmt" \
- -o "${name//%/%%}.%(ext)s" \
- 3>&1 1>&2 2>&3
- ) || echo "$stderr" | tee "$name.txt"
- fi
- done
Add Comment
Please, Sign In to add comment