Jump to content

[Linux Script] Download YT Trailers from .nfo to local movie folder


sualfred

Recommended Posts

sualfred

I faced a lot of broken trailer links in my movie collection these days so I decided to switch over to store the trailers locally in my media folders.

To save a lot of time I've made this small bash script, which downloads the YT Trailer by fetching the TheMovieDB ID right out the existing movie nfo.

 

Link:

https://raw.githubusercontent.com/sualfred/personal_scripts/master/trailerdl/trailerdl.sh

 

Requirements:

  • Linux KnowHow
  • A own TheMovieDB API (see https://developers.themoviedb.org/3 )
  • youtube-dl / curl / jq
  • Adjustment of the paths inside of the script
  • A clean folder structure without additional and unnecessary nfo's

 

The trailers are going to be stored next to the movie with the prefix "-trailer".

 

You will get a trailerdl.log after each run to check which movies don't have a YT ID or if the download has failed.

Please visit https://themoviedb.org and edit or add new trailer links so other users can benefit. (I spent the last 2 hours adding 100< updated trailer url's)

 

And before I forget it:

The script is quick'n'dirty,  but it's working. Feel free to adjust it if you want, but don't hope for support from my side -> Just sharing it.

If you want to say thanks: A beer is appreciated ;)

Edited by sualfred
  • Like 6
Link to comment
Share on other sites

sualfred

Reworked the script to use the themoviedb API.

Link to comment
Share on other sites

  • 2 months later...
  • 4 months later...
vze22jjw

I just ran across this and works great with minimal effort! Yes you need some linux skill, but with a firetv and no access to youtube trailers this is a great workaround.  Respect!

  • Like 1
Link to comment
Share on other sites

Thanks for that share! I'm actually running Server 2012, would that still work?

 

Hi @@nagetech, I have a similar setup, emby are running in windows

so the setup I did is

1. Share your drive in Windows for network accesss

2. Install Linux in Hyper-V

3. connect your share drive in linux

4. Run the scripts in Linux using your share windows access

5. then at the bottom of the script add 

 

curl --data '' "http://[emby_local_ip]:[emby_local_port]/Emby/Library/Refresh?api_key=[emby_api]"

Link to comment
Share on other sites

  • 3 months later...
neik

Thanks a lot for sharing your work, very much appreciated. :-)

Hoppefully I can give both a try in the next couple of days. 

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
neik

Fyi, for all who want use the script with a flat folder structure, that does not work.

I had to move my files to a more "complex" structure: /movies/moviename (year)/moviename.ext

Thanks @@sualfred for clarifying this. :-)

 

@@syralk, right know the script is downloading one trailer, would it be possible to download a trailer for each season?

@@Luke, does Emby support multiple trailers (one for each season) at all?

Link to comment
Share on other sites

  • 3 weeks later...
syralk

Hi @@neik

I think it could be possible I will do some testing and come back to you on this :)

 

 

Fyi, for all who want use the script with a flat folder structure, that does not work.
I had to move my files to a more "complex" structure: /movies/moviename (year)/moviename.ext
Thanks @@sualfred for clarifying this. :-)

@@syralk, right know the script is downloading one trailer, would it be possible to download a trailer for each season?
@@Luke, does Emby support multiple trailers (one for each season) at all?

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
syralk

Hi @@neik

I think it could be possible I will do some testing and come back to you on this :)

Hi @@Luke

I was working on the trailer download script to download the season trailer.

So I can see the trailer if I put the trailer in ~/videos/Legion (2017)/trailers/video.mp4

 

but I cannot see the trailer if I put it on 

~/videos/Legion (2017)/Season 1/trailers/video.mp4

 

I cannot see the button trailers appear in the screen of the specific Season 1

 

Do I miss something?

Link to comment
Share on other sites

syralk

We haven't added support for that yet.

Ha ok :)

This is the way how themoviedb.org works, so I tough to use the same way as well :)

will it be possible to add it on the next update?

Link to comment
Share on other sites

  • 3 months later...
RobsterUK

@@sualfred Just wanted to post my gratitude for this script.

Works really well.
I run my server on an XPENology (Synology) NAS. Wasn't able to get the script runing natively on there - it has an ash shell and the bash commands wouldn't run.
But I installed a Debian docker container and got it up & running on there!

I've also had to edit a few entries on TMDB so hope others benefit from that!

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
guardianali

I installed the windows 10 bash option. 

In an elevated powershell, i run the script but the below happens. 

 

V:\test>bash trailerdl.sh
tee: //trailerdl.log: Permission denied
 
tee: //trailerdl.log: Permission denied
Movie Path: Movies/Arena
tee: //trailerdl.log: Permission denied
Processing file: Arena (1989).nfo
tee: //trailerdl.log: Permission denied
trailerdl.sh: line 93: jq: command not found
trailerdl.sh: line 93: jq: command not found
(23) Failed writing body
tee: //trailerdl.log: Permission denied
YouTube: n/a
Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...
plaidstallion
On 5/16/2018 at 9:51 AM, sualfred said:

...

The script is quick'n'dirty,  but it's working. Feel free to adjust it if you want, but don't hope for support from my side -> Just sharing it.

If you want to say thanks: A beer is appreciated ;)

I really like this script. I have modified it to start a youtube-dl-server container in docker, download the file and the stop/rm the container. I have started to get it to work but it stops after the first successful trailer download. I don't see why though as there is the

for i in "${PATHS[@]}"

Also it seems to read the name of the movie from the name of the nfo file. My nfo files are "movie.nfo" but the folder names (the movie names) have (year) in them. Any ideas for another way to name the trailer appropriately? Really cool and thanks for the effort. If I get the re-write working I will post it for here for peeps.

 

I have gotten a script that mostly works for me. I was not able to figure out how to use youtube-dl in a docker container as it stops after the first action. I left it in the comments though in case anyone wants to tinker with it. I am reading the name of the movie from the contents of the first nfo file it encounters in the directory instead of taking the name from the title of the *.nfo file itself. As I have multiple .nfo files in some directories and some are named movie.nfo, due to diffferent programs with their fingers in the metadata, I needed to make some adjustments.

Another thing is I can't figure out how to format this string properly at line 89:
 

if ! [ -f "$DIR/$OUTFILENAME-trailer.mp4" ] || [ $OVERWRITE = "true" ]; then

I would like to have it proceed ONLY if it doesn't find ANY files in the current target $DIR that have *trailer* in the name. As there are spaces in the directory structure names, I am not quite sure how to format that with the variable and the glob. The script still works though as it will just take the next steps and then tell you there is already a file there by that name. It adds unnecessary run time to the script though.

So I am posting this here in case anyone is interested in taking it to the next level.

https://raw.githubusercontent.com/Plaidstallion/Personal-Scripts/main/youtube-trailer-downloader.sh

Edited by plaidstallion
Added content
  • Like 1
Link to comment
Share on other sites

  • 1 year later...
K22R8CT

Handy script, thanks.

I found one minor bug.

To fix, replace:

FILENAME=$(ls "$DIR" | egrep '\.nfo$' | sed s/".nfo"//g | sed "\/-trailer$/d")

with:

FILENAME=$(ls "$DIR" | egrep '\.nfo$' | sed s/"\.nfo"//g | sed "\/-trailer$/d")

(escaped ".")

You won't trigger it unless you happen to have a movie with the character string "nfo" in its title.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...