* include MediaInfo data when creating nfo files
This commit is contained in:
parent
28a7b4be34
commit
14e4b86344
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -34,7 +35,7 @@ public class MediaInfo implements Closeable {
|
||||||
|
|
||||||
private Pointer handle;
|
private Pointer handle;
|
||||||
|
|
||||||
|
|
||||||
public MediaInfo() {
|
public MediaInfo() {
|
||||||
try {
|
try {
|
||||||
handle = MediaInfoLibrary.INSTANCE.New();
|
handle = MediaInfoLibrary.INSTANCE.New();
|
||||||
|
@ -43,62 +44,62 @@ public class MediaInfo implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized boolean open(File file) {
|
public synchronized boolean open(File file) {
|
||||||
return file.isFile() && MediaInfoLibrary.INSTANCE.Open(handle, new WString(file.getAbsolutePath())) > 0;
|
return file.isFile() && MediaInfoLibrary.INSTANCE.Open(handle, new WString(file.getAbsolutePath())) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String inform() {
|
public synchronized String inform() {
|
||||||
return MediaInfoLibrary.INSTANCE.Inform(handle).toString();
|
return MediaInfoLibrary.INSTANCE.Inform(handle).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String option(String option) {
|
public String option(String option) {
|
||||||
return option(option, "");
|
return option(option, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String option(String option, String value) {
|
public synchronized String option(String option, String value) {
|
||||||
return MediaInfoLibrary.INSTANCE.Option(handle, new WString(option), new WString(value)).toString();
|
return MediaInfoLibrary.INSTANCE.Option(handle, new WString(option), new WString(value)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(StreamKind streamKind, int streamNumber, String parameter) {
|
public String get(StreamKind streamKind, int streamNumber, String parameter) {
|
||||||
return get(streamKind, streamNumber, parameter, InfoKind.Text, InfoKind.Name);
|
return get(streamKind, streamNumber, parameter, InfoKind.Text, InfoKind.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind) {
|
public String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind) {
|
||||||
return get(streamKind, streamNumber, parameter, infoKind, InfoKind.Name);
|
return get(streamKind, streamNumber, parameter, infoKind, InfoKind.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind, InfoKind searchKind) {
|
public synchronized String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind, InfoKind searchKind) {
|
||||||
return MediaInfoLibrary.INSTANCE.Get(handle, streamKind.ordinal(), streamNumber, new WString(parameter), infoKind.ordinal(), searchKind.ordinal()).toString();
|
return MediaInfoLibrary.INSTANCE.Get(handle, streamKind.ordinal(), streamNumber, new WString(parameter), infoKind.ordinal(), searchKind.ordinal()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(StreamKind streamKind, int streamNumber, int parameterIndex) {
|
public String get(StreamKind streamKind, int streamNumber, int parameterIndex) {
|
||||||
return get(streamKind, streamNumber, parameterIndex, InfoKind.Text);
|
return get(streamKind, streamNumber, parameterIndex, InfoKind.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String get(StreamKind streamKind, int streamNumber, int parameterIndex, InfoKind infoKind) {
|
public synchronized String get(StreamKind streamKind, int streamNumber, int parameterIndex, InfoKind infoKind) {
|
||||||
return MediaInfoLibrary.INSTANCE.GetI(handle, streamKind.ordinal(), streamNumber, parameterIndex, infoKind.ordinal()).toString();
|
return MediaInfoLibrary.INSTANCE.GetI(handle, streamKind.ordinal(), streamNumber, parameterIndex, infoKind.ordinal()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized int streamCount(StreamKind streamKind) {
|
public synchronized int streamCount(StreamKind streamKind) {
|
||||||
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), -1);
|
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized int parameterCount(StreamKind streamKind, int streamNumber) {
|
public synchronized int parameterCount(StreamKind streamKind, int streamNumber) {
|
||||||
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), streamNumber);
|
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), streamNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<StreamKind, List<Map<String, String>>> snapshot() {
|
public Map<StreamKind, List<Map<String, String>>> snapshot() {
|
||||||
Map<StreamKind, List<Map<String, String>>> mediaInfo = new EnumMap<StreamKind, List<Map<String, String>>>(StreamKind.class);
|
Map<StreamKind, List<Map<String, String>>> mediaInfo = new EnumMap<StreamKind, List<Map<String, String>>>(StreamKind.class);
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ public class MediaInfo implements Closeable {
|
||||||
return mediaInfo;
|
return mediaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> snapshot(StreamKind streamKind, int streamNumber) {
|
public Map<String, String> snapshot(StreamKind streamKind, int streamNumber) {
|
||||||
Map<String, String> streamInfo = new LinkedHashMap<String, String>();
|
Map<String, String> streamInfo = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
|
@ -134,13 +135,13 @@ public class MediaInfo implements Closeable {
|
||||||
return streamInfo;
|
return streamInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
MediaInfoLibrary.INSTANCE.Close(handle);
|
MediaInfoLibrary.INSTANCE.Close(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized void dispose() {
|
public synchronized void dispose() {
|
||||||
if (handle == null)
|
if (handle == null)
|
||||||
return;
|
return;
|
||||||
|
@ -150,24 +151,18 @@ public class MediaInfo implements Closeable {
|
||||||
handle = null;
|
handle = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() {
|
protected void finalize() {
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public enum StreamKind {
|
public enum StreamKind {
|
||||||
General,
|
General, Video, Audio, Text, Chapters, Image, Menu;
|
||||||
Video,
|
|
||||||
Audio,
|
|
||||||
Text,
|
|
||||||
Chapters,
|
|
||||||
Image,
|
|
||||||
Menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public enum InfoKind {
|
public enum InfoKind {
|
||||||
/**
|
/**
|
||||||
* Unique name of parameter.
|
* Unique name of parameter.
|
||||||
|
@ -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,
|
||||||
|
|
||||||
|
@ -213,32 +207,32 @@ public class MediaInfo implements Closeable {
|
||||||
Domain;
|
Domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String version() {
|
public static String version() {
|
||||||
return staticOption("Info_Version");
|
return staticOption("Info_Version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String parameters() {
|
public static String parameters() {
|
||||||
return staticOption("Info_Parameters");
|
return staticOption("Info_Parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String codecs() {
|
public static String codecs() {
|
||||||
return staticOption("Info_Codecs");
|
return staticOption("Info_Codecs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String capacities() {
|
public static String capacities() {
|
||||||
return staticOption("Info_Capacities");
|
return staticOption("Info_Capacities");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String staticOption(String option) {
|
public static String staticOption(String option) {
|
||||||
return staticOption(option, "");
|
return staticOption(option, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String staticOption(String option, String value) {
|
public static String staticOption(String option, String value) {
|
||||||
try {
|
try {
|
||||||
return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString();
|
return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString();
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue