Trailer Grab for use with Plex
trailergrab is a command-line program that will scan your plex movie folders and find which movies are missing trailers. It will then try find trailers on YouTube and download them.
Don't forget to tell Plex to update your libraries once you get new trailers!
This was written in Python 3.7.1, and should work with Python 3.6+ (uses PEP 498). Install the latest Python 3 from the Python Software Foundation.
It uses BeautifulSoup and youtube-dl.
Clone the repository:
git clone https://github.com/teejo75/trailergrab.git
Make a python virtual environment for it:
cd trailergrab python3 -m venv env
Activate your virtual environment, and install needed packages:
.\env\Scripts\activate.bat pip install -r requirements.txt
source ./env/bin/activate pip install -r requirements.txt
At the moment, only binary releases for Windows will be made available. This may change in the future.
Extract the archive to a folder somewhere. The binaries are
urlgrab.exe. The binaries are made with pyinstaller and have a full python environment provided with them.
I know some antiviruses tend to flag binaries like this, so if you feel unsafe, rather use the python script directly.
For macos and *nix machines, ensure your media volumes are mounted locally. Windows machines can use UNC paths.
Assuming your media structure is something like this:
/media/movies/A Glorious Movie (1981) /Another Glorious Movie (1984) /Chuckles The Clown (1973) /The Friendly Borg (2001) /media/movies2/Some Other Movie (2014) /Yet Another Movie (2016) /Trailers /Zap! The Movie (2018)
\\nasserver\movieshare\A Glorious Movie (1981) \Another Glorious Movie (1984) \Chuckles The Clown (1973) \The Friendly Borg (2001) \\adifferentnas\moviesshare2\Some Other Movie (2014) \Yet Another Movie (2016) \Trailers \Zap! The Movie (2018)
E:\movies\A Glorious Movie (1981) \Another Glorious Movie (1984) \Chuckles The Clown (1973) \The Friendly Borg (2001) K:\moviesshare2\Some Other Movie (2014) \Yet Another Movie (2016) \Trailers \Zap! The Movie (2018)
You could execute
trailergrab like this:
- *nix source:
python trailergrab.py -p /media/movies -p /media/movies2
- Windows source:
python trailergrab.py -p \\nasserver\movieshare -p k:\movieshare2
- Windows binary:
trailergrab.exe -p E:\movies -p \\adifferentnas\movieshare2
At least one
-p option is required.
optional arguments: -h, --help show this help message and exit -p PATH, --path PATH Top level movie folder to scan. Use option more than once if you want to scan more paths. -s SUFFIX, --suffix SUFFIX Add additional trailer suffixes. Use option more than once if you want to add more suffixes to scan for. Default: ['mp4', 'mkv', 'webm', 'avi'] -l, --local Enables local folder trailer download. Download trailers to the local folder instead of to the movie folder. Use this if you don't have write permission to the movie folder. Disables the trailerfolder option. -f, --trailerfolder Enables the Trailers folder. Download trailers to the Trailers folder under the movie instead of the main movie folder. Disables the local option. -i, --interactive Enables interactive mode. This allows you to select which trailer you want to download. -g, --log Enables logging to trailergrab.log. -q, --quiet Enables quiet mode. It won't print anything. Disables interactive mode. -t TERMS, --terms TERMS Search terms. This will be in addition to the movie name. Default: "official trailer" -m MAX, --max MAX Maximum number of search results to show. Default: 3 -v, --version Prints version information.
By default, trailergrab attempts to download trailers directly to the movie folder that needs one.
If your media folders are read only, or you would rather put the trailers in place yourself, you can use the
-l option. This will cause trailergrab to download the trailers to the folder
trailergrab is executing from. You can use the
-f option if you would rather trailers download to a 'Trailers' folder underneath your movie folder.
Youtube's search algorithm thinks it knows better than you and will just ignore certain keywords in the search field. It also sometimes includes completely unrelated trailers, so it is quite likely that you may end up with an undesired trailer, especially if your movie is older than say 2014 (you will get better results the more recent your movie is). I've also found that you will get different results on subsequent searches with exactly the same keywords.
During testing, I was scanning for Aladdin (1992), of which no trailers were found. Suddenly, a while later, a trailer downloads. It turns out that the trailer for Aladdin (2019) had just dropped, and that's what was downloaded. Sigh.
-i flag to enable interactive mode, and you will be presented with a list of trailers of which you can choose to download one, or not. As you like.
Trailergrab searches your media for trailers in the following formats: mp4, mkv, webm and avi. If you know you have trailers in other formats use the
-s ext flag to add it to the list. You can add multiple formats by repeating the
-g to log to a file. There's more detail than what is output to the screen.
-q if you want to call it from scripts.
-t to adjust the search keywords from 'official trailer'. If you're having no luck, particularly on older movies, try using just 'trailer'.
Be warned that Youtube's search may return different results on subsequent calls.
If you're annoyed that trailergrab just isn't finding that darned trailer you KNOW exists on youtube, you can use urlgrab to download it. This is just a simpler interface to youtube-dl.
Find the trailer on youtube. Copy the URL. It will look something like
Paste it in as an argument to urlgrab:
- *nix and Windows source:
python urlgrab.py -u https://www.youtube.com/watch?v=HlULSKurtzg
- Windows binary:
urlgrab.exe -u https://www.youtube.com/watch?v=HlULSKurtzg
At least one
-u option is required. You can add as many as you want to download.
optional arguments: -u URL, --url URL Youtube URL to download. Use this option as many times as you want.