Difference between revisions of "YT-DLP Scripting"

From Da Nerd Mage Wiki
Jump to navigation Jump to search
m (Tinker moved page YT-DLB Scripting to YT-DLP Scripting)
Line 117: Line 117:
echo ">>>>>>>> " $videosURL
echo ">>>>>>>> " $videosURL
       cd Videos
       cd Videos
       yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $videosURL 2> >(/usr/bin/tee -a $ERRfile)
       /usr/local/bin/yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $videosURL 2> >(/usr/bin/tee -a $ERRfile)
       cd ..
       cd ..


echo ">>>>>>>> " $shortsURL
echo ">>>>>>>> " $shortsURL
       cd Shorts
       cd Shorts
       yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $shortsURL 2> >(/usr/bin/tee -a $ERRfile)
       /usr/local/bin/yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $shortsURL 2> >(/usr/bin/tee -a $ERRfile)
       cd ..
       cd ..


echo ">>>>>>>> " $livesURL
echo ">>>>>>>> " $livesURL
       cd Streams
       cd Streams
       yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $livesURL 2> >(/usr/bin/tee -a $ERRfile)
       /usr/local/bin/yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $livesURL 2> >(/usr/bin/tee -a $ERRfile)
       cd ..
       cd ..
     else
     else

Revision as of 20:53, 29 September 2025

YTchan

A script for downloading entire channels...

(assumes your base for downloading YouTube videos is at: /mnt/Download_Space/YTDL/)

For the potentially required cookie file, see Exporting YouTube cookies

#!/bin/bash

echo -e "~~~~~~~ " $0 $@ "~~~~~~~ "\\n

if [ $# -eq 0 ] || [ $1 = "-u" ] || [ $1 = "-?" ]; then
  echo -e USAGE: YTchan \[-s\] \[-c\] \[-r RATE\] ChannelName ChannelName ...
  echo
  echo -e \\t -s = simulate this run
  echo -e \\t -c = use a cookie file exported from your browser to identify yourself.
  echo -e \\t -r RATE = Limit bandwidth
  echo -e \\t\\t Maximum download rate in bytes per second,
  echo -e \\t\\t\\t e.g. 50K or 4.2M
  echo -e \\t -p MIN MAX = Sleep interval \(pause\) between downloads \(in seconds\)
  echo -e \\t -e DATE = Earliest video upload date to grab.
  echo -e \\t\\t see https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#video-selection for format info
  echo -e \\t\\t \(Simplest is YYYYMMDD but fancier options exist\)
  echo -e \\t ChannelName = The name of the channel \(as defined by YouTube\)
  echo -e \\t\\t You can specify multiple channels
  echo
  echo -e The following \"ERROR\"s will also appear in 00000000-ERRORS
  echo -e \(Unfortunately, without indications of which files caused them...\)
  echo
  echo -e  \"ERROR: \[youtube:tab\] \@ChannelName: This channel does not have a videos tab\"
  echo -e  \"ERROR: \[youtube:tab\] \@ChannelName: This channel does not have a shorts tab\"
  echo -e  \"ERROR: \[youtube:tab\] \@ChannelName: This channel does not have a streams tab\"
  echo -e \\t Is simply indicating that the channel doesn\'t have that type of content.
  echo -e \\t \(All 3 means the channel doesn\'t actually have any content... :P \)
  echo
  echo -e \"ERROR: unable to download video data: HTTP Error 403: Forbidden\"
  echo -e \\t Means you may need to supply cookies.
  echo -e \\t Often caused by things like age restrictions.
  echo -e \\t May also be caused by YouTube noticing you\'ve been downloading a bunch...
  echo

  exit
fi


COOKIEfile=/mnt/Download_Space/YTDL/www.youtube.com_cookies.txt

  SIMULATE=""
  WITHcookies=""
  LIMITrate=""
  PAUSEbetween=""
  TIMEspan=""

while (( "$#" ));
do
  if [ ${1} = "-c" ]; then
    echo Using Cookies: $COOKIEfile
    WITHcookies="--cookies "$COOKIEfile
    shift
  elif [ ${1} = "-s" ]; then
    echo Simulating
    SIMULATE="-s"
    shift
  elif [ ${1} = "-r" ]; then
    shift
    LIMITrate="-r $1"
    shift
    echo Rate Limiting $LIMITrate
  elif [ ${1} = "-p" ]; then
    shift
    Pmin=$1
    shift
    Pmax=$1
    PAUSEbetween="--sleep-interval $Pmin --max-sleep-interval $Pmax"
    shift
    echo Time Span $TIMEspan to current
  elif [ ${1} = "-e" ]; then
    shift
    TIMEspan="--dateafter $1"
    shift
    echo Time Span $TIMEspan to current
  else
    CHANNEL=$1
    shift
    echo
    echo Working on channel: $CHANNEL
    echo ========================================
    if wget --spider --quiet https://www.youtube.com/\@$CHANNEL > /dev/null 2>&1; then
      videosURL=https://www.youtube.com/\@$CHANNEL/videos
      shortsURL=https://www.youtube.com/\@$CHANNEL/shorts
      livesURL=https://www.youtube.com/\@$CHANNEL/streams

      DEST=/mnt/Download_Space/YTDL/$CHANNEL

      ERRfile=$DEST/00000000-ERRORS
      ARCHfile=$DEST/11111111-ARCHIVE

      echo
      echo $videosURL
      echo $shortsURL
      echo $livesURL
      echo

      if [ -d $DEST ]; then
        echo $DEST exists
      else
        echo no $DEST... Building it...
        mkdir $DEST $DEST/Videos $DEST/Shorts $DEST/Streams
      fi

      echo

      cd $DEST

echo ">>>>>>>> " $videosURL
      cd Videos
      /usr/local/bin/yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $videosURL 2> >(/usr/bin/tee -a $ERRfile)
      cd ..

echo ">>>>>>>> " $shortsURL
      cd Shorts
      /usr/local/bin/yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $shortsURL 2> >(/usr/bin/tee -a $ERRfile)
      cd ..

echo ">>>>>>>> " $livesURL
      cd Streams
      /usr/local/bin/yt-dlp $SIMULATE $LIMITrate $TIMEspan $WITHcookies $PAUSEbetween -w --download-archive $ARCHfile --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" $livesURL 2> >(/usr/bin/tee -a $ERRfile)
      cd ..
    else
      echo YouTube says this channel does not exist.
    fi   
  fi
done