Skip to content

Instantly share code, notes, and snippets.

@jwmoss
Last active January 28, 2024 13:35
Show Gist options
  • Save jwmoss/41787d0f6b907e941226c7edc19f91e8 to your computer and use it in GitHub Desktop.
Save jwmoss/41787d0f6b907e941226c7edc19f91e8 to your computer and use it in GitHub Desktop.
Setup YouTube Agent for Plex

Setup YouTube and Plex

Requirements:

  1. Download https://raw.githubusercontent.com/ZeroQI/Absolute-Series-Scanner/master/Scanners/Series/Absolute%20Series%20Scanner.py
  2. Create a new folder called Scanners: .../Plex Media Server/Scanners
  3. Create a folder underneat that called Series: .../Plex Media Server/Scanners/Series
  4. Save python script to:
.../Plex Media Server/Scanners/Series/Absolute Series Scanner.py
  1. Make sure Absolute Series Scanner.py has read/write permissions (chmod +x Absolute Series Scanner.py)
  2. Download YouTube-Agent.Bundle and install to Plugin folder. Link to Plugin folders.
  3. Restart Plex.
  4. Create new TV Library called YouTube. I have it setup at the root of my Media:
/Movies
/YouTube <--- Folder here
/4KMovies
/4KTV
  1. Set Scanner as Absolute Series Scanner
  2. Set Agent as YouTubeSeries
  3. Create a YouTube Data API key and apply it under YouTube API Key: Link to creating YouTube API Key
  4. Create a file called youtube-dl-seen.conf anywhere that youtube-dl can read from. This will allow YouTube DL to skip already downloaded files. I placed mine at ~/.cache/youtube-dl/youtube-dl-seen.conf
  5. Using youtube-dl, create or use a script download to the appropriate place, assuming /youtube is the root of your YouTube media. Here's mine that I use to automatically download all videos from Blippi and BuySellshort channels uploaded within the last week
  6. Once done, re-scan Plex Library, and if all is well, you should see YouTube videos with metadata.

PowerShell:

$array = @( 
    ## Blippi
    "https://www.youtube.com/channel/UC5PYHgAzJ1wLEidB58SK6Xw",
    ## BuySellShort
    "https://www.youtube.com/channel/UCpamFkrGa5ePxhWsDyQs74w"
)

foreach ($u in $array) {
    Start-Process "youtube-dl" -ArgumentList @(
        $u,
        "-v",
        "-i",
        "--dateafter now-1week",
        "--merge-output-format mp4",
        "--write-info-json",
        '-f "bestvideo+bestaudio[ext=m4a]/best"',
        '--download-archive ~/.cache/youtube-dl/youtube-dl-seen.conf',
        '--output "/YouTube/%(uploader)s [%(channel_id)s]/%(playlist_index)s - %(title)s [%(id)s].%(ext)s"'
    )
}

Shell script:

array=( 
    "https://www.youtube.com/channel/UC5PYHgAzJ1wLEidB58SK6Xw"
    "https://www.youtube.com/channel/UCpamFkrGa5ePxhWsDyQs74w"
)

for i in "${array[@]}"
do
    youtube-dl "$i" \
    -v \
    -i \
    --dateafter now-1week \
    --merge-output-format mp4 \
    -f "bestvideo+bestaudio[ext=m4a]/best" \
    --write-info-json \
    --download-archive ~/.cache/youtube-dl/youtube-dl-seen.conf \
    --output "/YouTube/%(uploader)s [%(channel_id)s]/%(playlist_index)s - %(title)s [%(id)s].%(ext)s" \
    --batch-file=~/.cache/youtube-dl/Channels_to_DL.txt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment