* include MediaInfo data when creating nfo files

This commit is contained in:
Reinhard Pointner 2012-07-30 12:05:18 +00:00
parent 28a7b4be34
commit 14e4b86344
5 changed files with 100 additions and 57 deletions

View File

@ -328,7 +328,7 @@ def _defaults(args) {
def _guarded(c) { def _guarded(c) {
try { try {
return c.call() return c.call()
} catch (e) { } catch (Throwable e) {
_log.severe("${e.class.simpleName}: ${e.message}") _log.severe("${e.class.simpleName}: ${e.message}")
return null return null
} }
@ -340,7 +340,7 @@ def _guarded(c) {
def tryQuietly(c) { def tryQuietly(c) {
try { try {
return c.call() return c.call()
} catch (e) { } catch (Throwable e) {
return null return null
} }
} }

View File

@ -4,6 +4,7 @@ package net.sourceforge.filebot.mediainfo;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -158,13 +159,7 @@ public class MediaInfo implements Closeable {
public enum StreamKind { public enum StreamKind {
General, General, Video, Audio, Text, Chapters, Image, Menu;
Video,
Audio,
Text,
Chapters,
Image,
Menu;
} }
@ -202,8 +197,7 @@ public class MediaInfo implements Closeable {
Info, Info,
/** /**
* How this parameter is supported, could be N (No), B (Beta), R (Read only), W * How this parameter is supported, could be N (No), B (Beta), R (Read only), W (Read/Write).
* (Read/Write).
*/ */
HowTo, HowTo,
@ -247,4 +241,20 @@ public class MediaInfo implements Closeable {
} }
} }
/**
* Helper for easy usage
*/
public static Map<StreamKind, List<Map<String, String>>> snapshot(File file) throws IOException {
MediaInfo mi = new MediaInfo();
try {
if (mi.open(file)) {
return mi.snapshot();
} else {
throw new IOException("Failed to open file: " + file);
}
} finally {
mi.close();
}
}
} }

View File

@ -38,7 +38,7 @@ args.eachMediaFolder { dir ->
println "$dir => $movie" println "$dir => $movie"
try { try {
fetchMovieArtworkAndNfo(dir, movie) fetchMovieArtworkAndNfo(dir, movie, dir.getFiles{ it.isVideo() }.sort{ it.length() }.reverse().findResult{ it } )
} catch(e) { } catch(e) {
println "${e.class.simpleName}: ${e.message}" println "${e.class.simpleName}: ${e.message}"
} }

View File

@ -1,19 +1,19 @@
import static net.sourceforge.filebot.WebServices.* import static net.sourceforge.filebot.WebServices.*
import groovy.xml.*
import net.sourceforge.filebot.mediainfo.*
/** /**
* XBMC helper functions * XBMC helper functions
*/ */
def invokeScanVideoLibrary(host, port = 9090) { def invokeScanVideoLibrary(host, port = 9090) {
try { _guarded {
telnet(host, port) { writer, reader -> telnet(host, port) { writer, reader ->
writer.println('{"id":1,"method":"VideoLibrary.Scan","params":[],"jsonrpc":"2.0"}') // API call for latest XBMC release writer.println('{"id":1,"method":"VideoLibrary.Scan","params":[],"jsonrpc":"2.0"}') // API call for latest XBMC release
} }
return true
} catch(e) {
println "${e.class.simpleName}: ${e.message}"
return false
} }
} }
@ -23,7 +23,7 @@ def invokeScanVideoLibrary(host, port = 9090) {
* Plex helpers * Plex helpers
*/ */
def refreshPlexLibrary(server, port = 32400, files = null) { def refreshPlexLibrary(server, port = 32400, files = null) {
try { _guarded {
def sections = new URL("http://$server:$port/plex").getXml() def sections = new URL("http://$server:$port/plex").getXml()
def locations = sections.Directory.Location.collect{ [path:it.'@path', key:it.parent().'@key'] } def locations = sections.Directory.Location.collect{ [path:it.'@path', key:it.parent().'@key'] }
@ -35,10 +35,6 @@ def refreshPlexLibrary(server, port = 32400, files = null) {
locations*.key.unique().each{ key -> locations*.key.unique().each{ key ->
new URL("http://$server:$port/library/sections/$key/refresh/").get() new URL("http://$server:$port/library/sections/$key/refresh/").get()
} }
return true
} catch(e) {
println "${e.class.simpleName}: ${e.message}"
return false
} }
} }
@ -97,7 +93,7 @@ def fetchSeriesNfo(outputFile, series, locale) {
} }
def fetchSeriesArtworkAndNfo(seriesDir, seasonDir, series, season, locale = _args.locale) { def fetchSeriesArtworkAndNfo(seriesDir, seasonDir, series, season, locale = _args.locale) {
try { _guarded {
// fetch nfo // fetch nfo
fetchSeriesNfo(seriesDir['tvshow.nfo'], series, locale) fetchSeriesNfo(seriesDir['tvshow.nfo'], series, locale)
@ -123,8 +119,6 @@ def fetchSeriesArtworkAndNfo(seriesDir, seasonDir, series, season, locale = _arg
if (seasonDir != seriesDir) { if (seasonDir != seriesDir) {
fetchSeriesFanart(seasonDir['landscape.jpg'], series, 'seasonthumb', season, locale) fetchSeriesFanart(seasonDir['landscape.jpg'], series, 'seasonthumb', season, locale)
} }
} catch(e) {
println "${e.class.simpleName}: ${e.message}"
} }
} }
@ -155,7 +149,45 @@ def fetchMovieFanart(outputFile, movieInfo, type, diskType, locale) {
return fanart.url.saveAs(outputFile) return fanart.url.saveAs(outputFile)
} }
def fetchMovieNfo(outputFile, movieInfo) { def createFileInfoXml(file) {
_guarded {
def mi = MediaInfo.snapshot(file)
def out = new StringWriter()
def xml = new MarkupBuilder(out)
xml.fileinfo() {
streamdetails() {
mi.each { kind, streams ->
def section = kind.toString().toLowerCase()
streams.each { s ->
if (section == 'video') {
video() {
codec((s.'Encoded_Library/Name' ?: s.'CodecID/Hint' ?: s.'Format').replaceAll(/[ ].+/, '').trim())
aspect(s.'DisplayAspectRatio')
width(s.'Width')
height(s.'Height')
}
}
if (section == 'audio') {
audio() {
codec((s.'CodecID/Hint' ?: s.'Format').replaceAll(/\p{Punct}/, '').trim())
language(s.'Language/String3')
channels(s.'Channel(s)')
}
}
if (section == 'text') {
subtitle() {
language(s.'Language/String3')
}
}
}
}
}
}
return out.toString()
}
}
def fetchMovieNfo(outputFile, movieInfo, movieFile) {
movieInfo.applyXmlTemplate('''<movie xmlns:gsp='http://groovy.codehaus.org/2005/gsp'> movieInfo.applyXmlTemplate('''<movie xmlns:gsp='http://groovy.codehaus.org/2005/gsp'>
<title>$name</title> <title>$name</title>
<originaltitle>$originalName</originaltitle> <originaltitle>$originalName</originaltitle>
@ -176,18 +208,21 @@ def fetchMovieNfo(outputFile, movieInfo) {
<role>${it?.character}</role> <role>${it?.character}</role>
</actor> </actor>
<gsp:scriptlet> } </gsp:scriptlet> <gsp:scriptlet> } </gsp:scriptlet>
''' + (createFileInfoXml(movieFile) ?: '') + '''
<imdb id='tt${imdbId.pad(7)}'>http://www.imdb.com/title/tt${imdbId.pad(7)}/</imdb>
<tmdb id='$id'>http://www.themoviedb.org/movie/$id</tmdb>
</movie> </movie>
''') ''')
.replaceAll(/\t|\r|\n/, '') // xbmc can't handle leading/trailing whitespace properly .replaceAll(/\t|\r|\n/, '') // xbmc can't handle leading/trailing whitespace properly
.saveAs(outputFile) .saveAs(outputFile)
} }
def fetchMovieArtworkAndNfo(movieDir, movie, locale = _args.locale) { def fetchMovieArtworkAndNfo(movieDir, movie, movieFile = null, locale = _args.locale) {
try { _guarded {
def movieInfo = TheMovieDB.getMovieInfo(movie, locale) def movieInfo = TheMovieDB.getMovieInfo(movie, locale)
// fetch nfo // fetch nfo
fetchMovieNfo(movieDir['movie.nfo'], movieInfo) fetchMovieNfo(movieDir['movie.nfo'], movieInfo, movieFile)
// fetch series banner, fanart, posters, etc // fetch series banner, fanart, posters, etc
fetchMovieArtwork(movieDir['poster.jpg'], movieInfo, 'posters', locale.language) fetchMovieArtwork(movieDir['poster.jpg'], movieInfo, 'posters', locale.language)
@ -196,7 +231,5 @@ def fetchMovieArtworkAndNfo(movieDir, movie, locale = _args.locale) {
fetchMovieFanart(movieDir['clearart.png'], movieInfo, 'movieart', null, locale) fetchMovieFanart(movieDir['clearart.png'], movieInfo, 'movieart', null, locale)
fetchMovieFanart(movieDir['logo.png'], movieInfo, 'movielogo', null, locale) fetchMovieFanart(movieDir['logo.png'], movieInfo, 'movielogo', null, locale)
['bluray', 'dvd', null].findResult { diskType -> fetchMovieFanart(movieDir['disc.png'], movieInfo, 'moviedisc', diskType, locale) } ['bluray', 'dvd', null].findResult { diskType -> fetchMovieFanart(movieDir['disc.png'], movieInfo, 'moviedisc', diskType, locale) }
} catch(e) {
println "${e.class.simpleName}: ${e.message}"
} }
} }

View File

@ -107,7 +107,7 @@ groups.each{ group, files ->
if (dest && artwork) { if (dest && artwork) {
dest.mapByFolder().each{ dir, fs -> dest.mapByFolder().each{ dir, fs ->
println "Fetching artwork for $dir from TheMovieDB" println "Fetching artwork for $dir from TheMovieDB"
fetchMovieArtworkAndNfo(dir, group.mov) fetchMovieArtworkAndNfo(dir, group.mov, fs.findAll{ it.isVideo() }.sort{ it.length() }.reverse().findResult{ it })
} }
} }
if (dest == null && failOnError) { if (dest == null && failOnError) {