Advertisement
Guest User

YouTube downloader

a guest
Jul 16th, 2023
1,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.93 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. if [ ! -f "/input/feeds.txt" ]
  4. then
  5.     >&2 echo "Failed to open file /input/feeds.txt. Exiting."
  6.     exit 1
  7. fi
  8.  
  9. if [ ! -d "/output" ]
  10. then
  11.     >&2 echo "Failed to switch to directory /output. Exiting."
  12.     exit 1
  13. fi
  14.  
  15. cd /output
  16.  
  17. grep "^[^#;]" /input/feeds.txt | while read feed
  18. do
  19.     echo "[ytdl-pvr] Downloading feed: $feed"
  20.     # Grab the RSS feed from YouTube, grab the recent video URLs, and use yt-dlp to download the video
  21.     # The following arguments are used to download 1080p H.264 videos with AAC audio,
  22.     # such that they can be natively played on devices released within the last 10 years while still having
  23.     # good quality:
  24.     # --format, --remux-video, --merge-output-video
  25.     # The following arguments are used to write thumbnail and metadata to be compatible with Jellyfin.
  26.     # --write-thumbnail, --convert-thumbnails, --embed-thumbnail, --embed-metadata, --embed-subs
  27.     # To help Jellyfin sorting videos by release date, --no-mtime is set to prevent e.g. edits to
  28.     # video comments from making a video seem to be released more recently
  29.     # To prevent the script failing when feeds include a future video, --datebefore now is set
  30.     curl --fail-with-body -L -s "$feed" | xq -r '.feed.entry[0:5] | .[].link."@href"' | yt-dlp \
  31.         --batch-file - \
  32.         --output="%(channel)s/%(upload_date)s %(title)s [%(id)s].%(ext)s" \
  33.         --download-archive .ytdl-pvr-archive.txt  \
  34.         --continue \
  35.         --no-progress \
  36.         --format 'bestvideo[vcodec^=avc1]+bestaudio[acodec^=mp4a]' \
  37.         --remux-video "mp4" \
  38.         --merge-output-format "mp4" \
  39.         --no-mtime \
  40.         --no-cache-dir \
  41.         --write-thumbnail \
  42.         --convert-thumbnails jpg \
  43.         --embed-thumbnail \
  44.         --embed-metadata \
  45.         --embed-subs \
  46.         --sub-lang en,en.* \
  47.         --datebefore now
  48.     # Continue processing in case of a processing error
  49.     continue
  50. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement