MediaInfo within script

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

MediaInfo within script

Post by skchopperguy »

Hi,

I'm hacking together a couple of scripts here and stuck on a way to put <streamdetails> into an nfo. I have a snippet below that I scooped. It does not return anything though. Any ideas what I might be doing wrong?

Code: Select all

import groovy.xml.*
import net.sourceforge.filebot.mediainfo.*
import net.sourceforge.filebot.mediainfo.MediaInfo
import static net.sourceforge.filebot.WebServices.*
import static groovy.json.StringEscapeUtils.*
import static net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind.*

def fetchMovieNfo(outputFile, movieInfo, movieFile, override) {
	def i = movieInfo
	def mi = _guarded{ movieFile ? MediaInfo.snapshot(movieFile) : null }
	XML {
		movie {
			title(i.name)
			originaltitle(i.originalName)
			rating(i.rating)
			year(i.released?.year)
			votes(i.votes)
			plot(i.overview)
			tagline(i.tagline)
			runtime(i.runtime)
			mpaa(i.certification)
			genre(i.genres?.size() > 0 ? i.genres[0] : null)
			director(i.director)
			//Studio()
			//Trailer(link to youtube trailer from tmdb)
			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')
									//durationinseconds
								}
							}
							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')
								}
							}
						}
					}
				}
			}
			i.cast?.each{ a ->
				actor {
					name(a.name)
					role(a.character)
					//thumb(link to actor pic)
				}
			}
						
			imdbid("tt" + (i.imdbId ?: 0).pad(7))
			tmdbid(i.id)
		}
	}
	.saveAs(outputFile)
}

That returns:

<fileinfo>
<streamdetails></streamdetails>
</fileinfo>


You'll also notice some commented pieces, I'd like to pull 'Studio Information' (i.studio)? and 'Trailer' (i.trailers)? from tmdb and durationinseconds for the streamdetails section.

Mind pointing me in the right direction?! Thanks!
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

The artwork.tmdb and htpc work perfectly. Just tested. You can figure it out from there. println is your friend ;)

That extra information you'd like to add is not available to filebot internally so you can't use it in scripting neither.
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

Works for you, really? I run filebot -script fn:artwork.tmdb /media/Movies/test_movies/

I only get empty tags for streamdetails in the nfo. That's one of the reasons that prompted me to start that other thread in the first place. 200 files and all have empty streamdetails so something must not be working or my whole library doesn't have any MOOV data ... which is impossible lol.

No idea what you me by 'printIn' is your friend. I presume its to log some error? or do you mean that is what is missing and I need to add that. - newb

Those extra pieces are in the tmdb api, that's why I was wondering how to grab them. Just the Trailer even...?

[EDIT]
I saw this capability for v3 of tmdb API, but I think what your saying is ... its not built into filebot so it cannot be used ATM.
http://api.themoviedb.org/3/movie/19995 ... e=trailers

When I do a -r rename I can use {resolution} and that outputs the correct width, height on the same files.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

Have you tried running filebot -script fn:sysinfo? Probably just can't load the mediainfo dll for some reason. Though if {resolution} works that's weird.

Well, with println you can see what works and what doesnt. Like just a on liner println MediaInfo.snapshot(File) or something. Play with it. It either works or it'll tell you it doesn't and throw an error. These errors are silenced in the htpc script via _guarded{ ... }


I guess the added that at some point. I can probably easily add that before next release. Make sure to remind me! :D
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

~ $ filebot -script fn:sysinfo
FileBot 3.61 (r1646)
JNA Native: 3.5.0
MediaInfo: MediaInfoLib - v0.7.58
7-Zip-JBinding: OK
Extended Attributes: DISABLED
OpenJDK Runtime Environment 1.6.0_24
64-bit OpenJDK 64-Bit Server VM
Linux (amd64)
Done ヾ(@⌒ー⌒@)ノ

I will play around with println...and without _guarded{ ... } to see if any errors show up. Thanks.

[EDIT]
np on reminding you, just don't forget to tell me when yer about to do the next realease...then I'll step and do that for sure. :lol:

[EDIT 2]
Can you post the latest revision into portable on filebot downloads?
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

libmediainfo seems to get loaded just fine. You'll have to start debugging and narrow down the issue. It's in your code. ;)

EDIT: I only upload jars for the latest revision. Check FAQ.
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

rednoah wrote:libmediainfo seems to get loaded just fine. You'll have to start debugging and narrow down the issue. It's in your code. ;)

EDIT: I only upload jars for the latest revision. Check FAQ.

Can't be my script, artwork.tmdb is hosted on your web server. I don't have write access ;)

Using the latest revision....

scripts $ ./filebot.sh -script fn:sysinfo
FileBot 3.61 (r1675)
JNA Native: 3.5.0
MediaInfo: MediaInfoLib - v0.7.58
7-Zip-JBinding: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: Failed to load 7z-JBinding: no 7-Zip-JBinding in java.library.path
Extended Attributes: DISABLED
OpenJDK Runtime Environment 1.6.0_24
64-bit OpenJDK 64-Bit Server VM
Linux (amd64)
Done ヾ(@⌒ー⌒@)ノ

Code: Select all

 filebot -script fn:artwork.tmdb /media/Movies/test_movies/
Result: Inside movie.nfo, there is no streamdata.

<fileinfo>
<streamdetails></streamdetails>
</fileinfo>


[EDIT]
It occurred to me that maybe its my java version. So I updated, but same result with artwork.tmdb ... no streamdetails in movie.nfo

FileBot 3.61 (r1675)
JNA Native: 3.5.0
MediaInfo: MediaInfoLib - v0.7.58
7-Zip-JBinding: OK
Extended Attributes: DISABLED
Java(TM) SE Runtime Environment 1.7.0_25
64-bit Java HotSpot(TM) 64-Bit Server VM
Linux (amd64)
Done ヾ(@⌒ー⌒@)ノ
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

With testing I mean you start with something like this and then take it from there:

Code: Select all

import net.sourceforge.filebot.mediainfo.MediaInfo

def f = '''D:/在北外的生活.wmv''' as File
println MediaInfo.snapshot(f)
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

Ah, ok. So when I make that into a script, add my own file and run from cli I get...

[:]
Done ヾ(@⌒ー⌒@)ノ

When I load the same file into the gui, I can use {resolution} and that works great. I don't understand why there would be any difference as both gui and cli are being called from same jar file. There must be something that is not loading when I use the CLI to run a script. I've no idea what I could try, any suggestions?

Here is my bash file. Does it look normal?

Code: Select all

#!/bin/bash
java -Dunixfs=false -DuseGVFS=false -DuseExtendedFileAttributes=false -Djava.net.useSystemProxies=false -Dsun.net.client.defaultConnectTimeout=10000 -Dsun.net.client.defaultReadTimeout=60000 -Dapplication.deployment=deb -Dapplication.analytics=true -Dapplication.warmup=true -Dapplication.dir=$HOME/.filebot -Djava.io.tmpdir=$HOME/.filebot/temp -Djna.library.path=/usr/share/filebot -Djava.library.path=/usr/share/filebot -jar /usr/share/filebot/FileBot.3.61-r1675.jar "$@"
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

Even when I try with an empty file MediaInfo gets me some data:

Code: Select all

[General:[[Count:280, StreamCount:1, StreamKind:General, StreamKind/String:General, StreamKindID:0, CompleteName:D:\test.txt, FolderName:D:, FileName:test, FileExtension:txt, FileSize:0, FileSize/String:0.00 Byte, FileSize/String1: Byte0, FileSize/String2:0.0 Byte, FileSize/String3:0.00 Byte, FileSize/String4:0.000 Byte, StreamSize:0, StreamSize/String:0.00 Byte, StreamSize/String1: Byte0, StreamSize/String2:0.0 Byte, StreamSize/String3:0.00 Byte, StreamSize/String4:0.000 Byte, File_Created_Date:UTC 2013-07-31 19:49:14.573, File_Created_Date_Local:2013-08-01 03:49:14.573, File_Modified_Date:UTC 2013-07-31 19:49:14.573, File_Modified_Date_Local:2013-08-01 03:49:14.573]]]
Done ヾ(@⌒ー⌒@)ノ
In your case it doesn't throw an error. So mediainfo says it works but passes back empty data? No idea. Try with another computer. Nothing more I can do as it works flawlessly here.

You can try replacing the mediainfo.so native code with an older/newer version and see if that makes a difference.
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

Tried on another unit and a vm, same thing. Empty data. Doesn't filebot have mediainfo built-in to the binary? or does it need the mediainfo shared library installed? (http://packages.debian.org/wheezy/amd64 ... 0/filelist)

Both gui and cli work fine in windows 7. I think you might be looking for libs in the wrong directory? or I need to ls -n to...?
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

The deb packages bundle libmediainfo (as in libmediainfo.so in the install folder) and if it can't load it there should be some sort of error. There's more info on troubleshooting in the FAQ.
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

Ok, so I tested again. This time we have some errors (yay!). I did not install mediainfo package this time. I downloaded the latest filebot revision from HEAD and also download lib7-Zip-JBinding.so, libmediainfo.so and libzen.so from HEAD/trunk found on download page. All files are in same folder, here is what I see:

root@debian-wheezy:/var/test/scripts# ./filebot.sh -script fn:sysinfo
FileBot 3.61 (r1675)
JNA Native: 3.5.0
Aug 03, 2013 2:50:46 PM net.sourceforge.filebot.mediainfo.MediaInfo <clinit>
WARNING: Failed to preload libzen
MediaInfo: java.lang.UnsatisfiedLinkError: Unable to load library 'mediainfo': /var/test/scripts/libmediainfo.so: invalid ELF header
7-Zip-JBinding: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: Failed to load 7z-JBinding: /var/test/scripts/lib7-Zip-JBinding.so: /var/test/scripts/lib7-Zip-JBinding.so: invalid ELF header (Possible cause: endianness mismatch)
Extended Attributes: DISABLED
Java(TM) SE Runtime Environment 1.7.0_25 (headless)
64-bit Java HotSpot(TM) 64-Bit Server VM
Linux (amd64)
Done ヾ(@⌒ー⌒@)ノ
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

Try downloading the latest .so native libs for you platform from mediainfo and replace the once on the filebot install folder. Also you could try the latest Java 7 runtime from Oracle. For some incompatibility reason the process can't link in the native code.
:idea: Please read the FAQ and How to Request Help.
skchopperguy
Posts: 16
Joined: 21 Jul 2013, 12:59

Re: MediaInfo within script

Post by skchopperguy »

HI, k. I will try that tomorrow (sleep soon).

So just to confirm with you. Is Java(TM) SE Runtime Environment 1.7.0_25 (headless) ok? or should I look for a newer version? sorry its late or I'd look myself. Thanks for all you help here man...much appreciated.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: MediaInfo within script

Post by rednoah »

That should be fine. Certainly works for me. But You could try Oracle Java instead of OpenJDK Java.
:idea: Please read the FAQ and How to Request Help.
Post Reply