Filenotfound exception when fetching movie info

All your suggestions, requests and ideas for future development
Post Reply
Raphy
Posts: 4
Joined: 20 Mar 2012, 16:30

Filenotfound exception when fetching movie info

Post by Raphy »

hello,

I'm using the command-line for fetching movie info, with the script "artwork.tmdb.db":

Code: Select all

filebot -script [...]/filebot/artwork.tmdb.groovy -trust-script -non-strict Films
It does find some movies, but quickly run into this error:

Code: Select all

/home/raphy/Films/./2012 => 2012 (2011)
Fetch nfo and artwork for 2012 (2011)
FileNotFoundException: http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/5a6edae568130bf10617b6d45be99f13/
java.io.FileNotFoundException: http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/5a6edae568130bf10617b6d45be99f13/
at net.sourceforge.filebot.web.WebRequest.getReader(Unknown Source)
at net.sourceforge.filebot.web.CachedPage.openConnection(Unknown Source)
at net.sourceforge.filebot.web.CachedPage.fetchData(Unknown Source)
at net.sourceforge.filebot.web.CachedResource.get(Unknown Source)
at net.sourceforge.filebot.web.TMDbClient.fetchResource(Unknown Source)
at net.sourceforge.filebot.web.TMDbClient.getMovieInfoByIMDbID(Unknown Source)
at net.sourceforge.filebot.web.TMDbClient.getMovieInfo(Unknown Source)
at net.sourceforge.filebot.web.TMDbClient.call(Unknown Source)
at Script3.fetchMovieArtworkAndNfo(Script3.groovy:39)
at Script3.doCall(Script3.groovy:81)
at Script2.doCall(Script2.groovy:27)
at Script3.run(Script3.groovy:55)
at net.sourceforge.filebot.cli.ScriptShell.evaluate(Unknown Source)
at net.sourceforge.filebot.cli.ScriptShell.run(Unknown Source)
at net.sourceforge.filebot.cli.ScriptShell.run(Unknown Source)
at net.sourceforge.filebot.cli.ArgumentProcessor.process(Unknown Source)
at net.sourceforge.filebot.Main.main(Unknown Source)
I tried top get the xml file mentionned (http://api.themoviedb.org/2.1/Movie.get ... 45be99f13/) and there is a not found error. But how can filebot get around it and move on instead of exiting?

Thank you
Raphael
User avatar
rednoah
The Source
Posts: 19141
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Filenotfound exception when fetching movie info

Post by rednoah »

Oh? Looks like that happens when the API has no data for the given movie?

Just put that part into an an try {} catch {} block and it should catch those errors.
:idea: Please read the FAQ and How to Request Help.
Raphy
Posts: 4
Joined: 20 Mar 2012, 16:30

Re: Filenotfound exception when fetching movie info

Post by Raphy »

Seems to do the trick.

Thank you very much!

Here's is my modified script:

Code: Select all

// filebot -script "http://filebot.sf.net/scripts/artwork.tmdb.groovy" -trust-script /path/to/media/

/*
 * Fetch movie artwork. The movie is determined using the parent folders name.
 */

def fetchArtwork(outputFile, movieInfo, artworkType, artworkSize) {
	// select and fetch artwork
	def artwork = movieInfo.images.find { it.type == artworkType && it.size == artworkSize }
	if (artwork == null) {
		println "Artwork not found: $outputFile"
		return null
	}
	
	println "Fetching $outputFile => $artwork"
	return artwork.url.saveAs(outputFile)
}


def fetchNfo(outputFile, movieInfo) {
	movieInfo.applyXmlTemplate('''<movie>
			<title>$name</title>
			<year>$released.year</year>
			<rating>$rating</rating>
			<votes>$votes</votes>
			<plot>$overview</plot>
			<runtime>$runtime</runtime>
			<mpaa>$certification</mpaa>
			<genre>${!genres.empty ? genres[0] : ''}</genre>
			<id>tt${imdbId.pad(7)}</id>
		</movie>
	''').saveAs(outputFile)
}


def fetchMovieArtworkAndNfo(movieDir, movie) {
	println "Fetch nfo and artwork for $movie"
	
	try {
		def movieInfo = TheMovieDB.getMovieInfo(movie, Locale.ENGLISH)
		println movieInfo
		movieInfo.images.each {
			println "Available artwork: $it.url => $it"
		}
	
		// fetch nfo
		fetchNfo(movieDir['movie.nfo'], movieInfo)
	
		// fetch series banner, fanart, posters, etc
		fetchArtwork(movieDir['folder.jpg'], movieInfo, 'poster', 'original')
		fetchArtwork(movieDir['backdrop.jpg'], movieInfo, 'backdrop', 'original')
	}
	catch(FileNotFoundException) {
		println "Movie not found..."
		return null;
	}
	
}


args.eachMediaFolder { dir ->
	def videos = dir.listFiles{ it.isVideo() }
        if (dir.hasFile{it =~ /nfo$/} || ( dir.hasFile{it =~ /banner.jpg$/} && dir.hasFile{it =~ /folder.jpg$/})) {
                println "Already scanned, skipping..."
                return; 
        }	
	def query = _args.query ?: dir.name
	try {
		def options = TheMovieDB.searchMovie(query, _args.locale)
		if (options.isEmpty()) {
			println "Movie not found: $query"
			return null
		}
	
		// sort by relevance
		options = options.sortBySimilarity(query, { it.name })
	
		// auto-select series
		def movie = options[0]
	
		// maybe require user input
		if (options.size() != 1 && !_args.nonStrict && !java.awt.GraphicsEnvironment.headless) {
			movie = javax.swing.JOptionPane.showInputDialog(null, "Please select Movie:", dir.path, 3, null, options.toArray(), movie);
			if (movie == null) return null
		}
	
		println "$dir => $movie"
		fetchMovieArtworkAndNfo(dir, movie)
	}
	catch(FileNotFoundException) {
		println "Movie not found: $query"
		return null;
	}
}
Post Reply