Guest User

grab-youtube-list

a guest
May 5th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. #!/bin/bash -x
  2. yt=https://www.youtube.com
  3. ytl=$1
  4. shift
  5. fmt=${1:-136+140/bestvideo[height<=?720][vcodec^=?avc1]+140/bestvideo[height<=?720][vcodec^=?avc1]+bestaudio/bestvideo+bestaudio/best}
  6. shift
  7. opt=("$@")
  8.  
  9. youtube-dl "$yt/$ytl" "${opt[@]}" --flat-playlist --dump-json |
  10. jq -r '"\(.id)\t\(.title)"' |
  11. nl -w1 |
  12. while IFS=$'\t' read -r n id title
  13. do
  14.     printf '\n\n-----\n\n\n'
  15.     name=$(printf '%03d %s (%s)' "$n" "${title//[\/:?*]/-}" "$id")
  16.     set -- *[-\(]"$id"[\).][^f]*
  17.     if test -e "$1" && test -z "$2"
  18.     then
  19.         name+=.${1##*.}
  20.         test "$1" = "$name" || mv -v "$1" "$name"
  21.     else
  22.         sleep 10
  23.         stderr=$(
  24.             youtube-dl "$yt/watch?v=$id" \
  25.                 --format "$fmt" \
  26.                 -o "${name//%/%%}.%(ext)s" \
  27.                 3>&1 1>&2 2>&3
  28.         ) || echo "$stderr" | tee "$name.txt"
  29.     fi
  30. done
Add Comment
Please, Sign In to add comment