I’ve been wanting to get some youtube series onto my plex server for a while for archival purposes, and, cause, fuck ads amirite?

I pieced together some various scripts I found to mostly automate the process on my QNAP nas, that also houses my Plex server.

Most of everything I found was for youtube-dl which doesn’t appear to work as well as the fork yt-dl so I opted to use that for this.

Read on below for how to do this for yourself.

How to grab Youtube series for Plex on your QNAP using YT-DL

  1. First, you want to visit the web interface of your QNAP to create a directory, and install Python3. Open your favourite browser (firefox??) and visit the URL of your NAS.

     https://0.0.0.0/cgi-bin/
    
  2. Now click File Station then navigate to your Plex share, and create a YouTube directory you can use in the following steps.

  1. Then, install Python3 by going to APP Center and click All Apps under the QNAP Store then search for Python3 and install it.

  1. Now, you’re going to want to open up a terminal, and ssh to your QNAP NAS.

     $ ssh -l user@ip.of.the.qnap
    
  2. Now we want to su to root

     $ sudo /bin/bash 
     <password> 
    
  3. Then, we want to enter the YouTube directory we created earlier through filestation. For my setup, this is located on CACHEDEV1_DATA but yours may be different.

     # cd /share/CACHEDEV1_DATA/Plex/YouTube
    
  4. Now we want to make a couple directories

     # mkdir Scripts
    
  5. Now let’s touch the files we’ll be editing

     # touch Scripts/channel_list.txt
     # touch Scripts/downloaded_list.txt
    
  6. Now let’s upgrade pip as root, and, the user, this is ghetto and not sure if it’s required but it seemed to be required for me for some reason.

     # cd /opt/python3/bin 
     # ./python3.10 -m pip install --upgrade pip
     # exit 
     $ cd /opt/python3/bin
     $ ./python3.10 -m pip install --upgrade pip
    
  7. Now, as the user, let’s install yt_dlp

    $ /opt/python3/bin/python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
    
  8. On QNAP you’ll receive this warning, but it seems fine for everything to work for me. We’ll fix this in the script.

    WARNING: The scripts mid3cp, mid3iconv, mid3v2, moggsplit, mutagen-inspect and mutagen-pony are installed in '/share/homes/USERNAME/.local/bin' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    WARNING: The script yt-dlp is installed in '/share/homes/USERNAME/.local/bin' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    
  9. Now let’s edit our channels list file to add some subscriptions. Note, this is by ‘playlist’ so if your channel doesn’t have playlists you’d have to download the whole channel which would make organization wonky so I don’t recommend it.

    $ sudo vi /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/channel_list.txt
    
  10. I’m not going to write a tutorial on vi here, but just hit i then middle click on your mouse to paste the following into the file. Note I manually placed the season numbers after the URLs with the format 01 or 20 and etc.

    ## FORMAT: PLAYLIST_URL TWO_DIGIT_SEASON_NUMBER
    
    ## Gilly and Keeves
    # Gilly and Keeves - S01
    https://www.youtube.com/playlist?list=PL2KJJamF98zjDh1KGAZsSb0p5THVDshAi 01
    
    ## Townsends
    # Townsends - S20
    https://www.youtube.com/playlist?list=PL4e4wpjna1vxW8QUnMjdymH0I2Mhu6wO8 20
    # Townsends - S19
    https://www.youtube.com/playlist?list=PL4e4wpjna1vx_CGGgEh6WynWBxouhlsRZ 19
    # Townsends - S18
    https://www.youtube.com/playlist?list=PL4e4wpjna1vx3DFU7r7gjDtdPzEeCsL2l 18
    
    ## YLAB RADIO COURSES
    # YLAB - HAM Course
    https://www.youtube.com/playlist?list=PLBvGKh7QyUL9fCm6IeHdaxEx9Crh-S4Ot 01
    
    # important - leave here - eof 
    
  11. Now hit esc then :wq to exit and save the file

  12. You can verify the contents with. This should show what you just pasted above, naturally.

    $ cat /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/channel_list.txt
    
  13. Now, let’s create our script for grabbing our shows

    $ sudo vi /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/yt_dlp.sh
    
  14. Paste this in, changing your USERNAME and CACHEDEV1_DATA and PLEX paths if you need to

    #!/bin/bash
    
    export PATH="/share/homes/USERNAME/.local/bin:$PATH"
    clear 
    echo " "
    echo "starting youtube playlist downloads --->" 
    echo " "
    while read var1 var2; do
    case $var1 in
    ''|\#*) continue ;;         # skip blank lines and lines starting with #
    esac
    echo "$var1 $var2"
    
            cd /share/CACHEDEV1_DATA/Plex/YouTube/Channels
            yt-dlp --yes-playlist \
                    --dateafter now-72months \
                    --download-archive /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/downloaded_list.txt \
                    -f 'best[ext=mp4]/best' \
                    -i \
                    -o "%(uploader)s/Season ${var2}/%(uploader)s - S${var2}E%(playlist_index)s - %(title)s.%(ext)s" \
                    --add-metadata \
                    --write-description \
                    --write-thumbnail \
                    --embed-thumbnail \
                    --write-info-json \
                    --sub-lang en \
                    --sub-format srt/vtt \
                    --write-auto-sub \
                    --quiet \
                    --progress \
                    $var1
    
    
    # stuff with var1, etc.
    done < /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/channel_list.txt
    echo " "
    echo "done! check plex!" 
    echo " "
    
  15. Now run it

    $ chmod +x /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/yt_dlp.sh
    $ /share/CACHEDEV1_DATA/Plex/YouTube/Scripts/yt_dlp.sh
    
  16. If you see output like this, you’re up and running!!

  1. Now you want to add the library to your plex server, which points to the Channels directory you created earlier.

  1. Now you should have the YouTube library to pick from on plex.

  1. Visit that library and see what’s been pulled in. You might have to manually rename the ‘seasons’ yourself or other modifications, but as long as the channel is on TVDB you should be good to go in terms of meta data. Should look something like this;

  1. Now just edit your channel_list.txt file whenever you want to add a new playlist, and then run your script again and voila!