Feature Request: MultiCD MediaInfo summary support

All your suggestions, requests and ideas for future development
Post Reply
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Feature Request: MultiCD MediaInfo summary support

Post by kim »

Say you need the combined (summary) "Duration" not just the part 1 e.g. cd1
(same with "FileSize", "OverallBitRate" and "BitRate")

Use:
rename of folder / filename
or
what I need it for... in the movie.nfo
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

Update 1:
Show complete duration in minutes (only tested in GUI):

Code: Select all

{
package net.filebot.mediainfo; 
def durationinMS = []; 
def videoFiles = []; 

	def files = folder.listFiles();
	files.each{if (it.isVideo()) {durationinMS += new BigDecimal(MediaInfo.snapshot(it).values()[0]['Duration'].join('')) }};
	def durationinMINsum = Math.round((durationinMS.sum())/60000); 
	durationinMINsum 
}
FileSize in MB:
just change ['Duration'] --> ['FileSize']
durationinMS.sum())/60000) --> durationinMS.sum())/1000/1000 (why not 1024?)

OverallBitRate in Kbps:
['OverallBitRate']
(durationinMS.sum())/1000)/durationinMS.size()

Video BitRate in Kbps:
values()[1]['BitRate']
(durationinMS.sum()/1000)/durationinMS.size()

btw (MediaInfo):
General = values()[0]
Video = values()[1]
Audio = values()[2]
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

Since we're talking about the format, I'd use the {model} binding for this on ;)

Sum {minutes} is easy:

Code: Select all

{model.findAll{ it.n == n }.minutes.sum()}
Sum {megabytes} is tricky because it'll yield String values:

Code: Select all

{model.findAll{ it.n == n }.megabytes.sum{ it as int }}
No convenient avg function in Groovy... oh well...

Code: Select all

{def r = model.findAll{ it.n == n }.bitrate; r.sum()/r.size()}
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

got any idea how / where to do this in the movie.nfo ?

1. maybe pass all files from amc to htpc ("fs") ?

2. something with " def mi = tryLogCatch{ movieFile ? MediaInfo.snapshot(movieFile) : null }" ?

3. or can I do it just by doing something under ?
fileinfo {
streamdetails {
mi?.each { kind, streams ->
def section = kind.toString().toLowerCase()
streams.each { s ->

4. all of the above ?
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

1.
Yes, the amc/htpc scripts don't accommodate for this use case at all right now.

2.
How you did it in your code sample (find sibling files, accumulate mediainfo data) is probably how you'd do it. Though passing the fileset instead of just the first video file in the amc script is probably a better solution.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

so I pass all files from amc and if I use e.g.
fileset.each{fileSizeINbytes += new BigDecimal(MediaInfo.snapshot(it).values()[0]['FileSize'].join('')) }}
and place e.g.
fileSizeINbytes.each{filesize(it)} in the fileinfo it works, but I don't think its the best way...


I want to use the existing "fileinfo..." part in htpc, but how...
I need to combine them into 1 set before I can use it...
make it unique and get sum... (best if done for all so I don't need to do something for every entry)

if I modify
def mi = tryLogCatch{ movieFile ? MediaInfo.snapshot(movieFile) : null
to e.g. fileset.each{(mi += MediaInfo.snapshot(it) ) }
(making it an Array with maps inside)

and add en extra "each" to "fileinfo..." it works but it writes separate sets in movie.nfo


I have tried and tried diff. things, but no luck :(


this is to complex for me, I need more to go on pls ?

you can use this as a sample:
def mi = [[General:[[FileName:'PUKKA.cd1', FileSize:731893308, Duration:2900390, OverallBitRate:2018543]],Video:[[Codec:'XVID', Duration:2900690, BitRate:1561146, Width:640, Height:272]],Audio:[[Codec:'AC3', Duration:2900666, BitRate:448000, Channel:6]]], [General:[[FileName:'PUKKA.cd2', FileSize:730903372, Duration:3472303, OverallBitRate:1683332]],Video:[[Codec:'XVID', Duration:3472303, BitRate:1226337, Width:640, Height:272]],Audio:[[Codec:'AC3', Duration:3472374, BitRate:448000, Channel:6]]]];
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

It's probably easier if you just calculate your values before you create the XML, and use the existing "mi" variables for everything where you don't need to sum/avg anything.

e.g.

Code: Select all

def value = 'test'

XML{
	tag(value)
}
Merging multiple nested maps is probably a lot more tricky. I'd stick to simple solutions.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

sounds a lot like my first try :)

I was hoping there was a smart way to do it :(

something like:
"def mapOne = [ [ id:1 , firstName : 'Jimmy'], [ id:2 , firstName : 'Robert'] ]
def mapTwo = [ [ id:1 , lastName: 'Page'], [ id:2 , lastName: 'Plant'] ]

def mergedMap = (mapOne + mapTwo).groupBy { it.id }.collect { it.value.collectEntries { it } }"

or

"def map1 = [p1:100, p2:200]
def map2 = [p3:300, p4:400]
def map3 = map1 + map2
println "${map3}" "

or

"assert [ a: true, b: false ] + [ a: false ] == [ a: false, b: false ]
Or left shift:
assert [ a: true, b: false ] << [ a: false ] == [ a: false, b: false ] "

but I can't get it to work...

the problem as I see it is the " += " ( same result = " << ")
fileset.each{(mi += MediaInfo.snapshot(it) ) }
(making it an Array with maps inside)

if I could just merge to a single set (like the org.) ?
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

You probably wanna use the findResults method to convert files to MediaInfo maps.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

like this ?
mi = fileset.findResults{MediaInfo.snapshot(it)}
I see no diff.
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

Now you have a list of mediainfo maps and you can do whatever you want with it.

e.g.

Code: Select all

def mis = fileset.findResults{MediaInfo.snapshot(it)}
def bitrate = mis.findResults{ ** get bitrate ** }.sum()
etc
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

thx but:
Script2.groovy: 493: expecting '}', found '{' @ line 493, column 31.
def Duration = mi.findResults{ ** get Duration ** }.sum()

same in Gui
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

Sorry, but the ** get bitrate ** is for you to figure out. I don't know that from the back of my head. ;)
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

It took way to long to find out, you where talking about:
"It's probably easier if you just calculate your values before you create the XML, and use the existing "mi" variables for everything where you don't need to sum/avg anything."

... and NOT a "smart" way to do it all in the XML :(

... but there is an e.g. of what I made:
pre XML:
def mis = fileset.findResults{MediaInfo.snapshot(it)}
def fileSizeinBYTES = mis.findResults{new BigDecimal(it.values()[0]['FileSize'].join('')) }

in XML:
(fileSizeinBYTES).each{filesize(it)}
if (fileSizeinBYTES[1] != null) {filesizesum(fileSizeinBYTES.sum())}

btw: "fileset" is "fs" from the AMC
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Feature Request: MultiCD MediaInfo summary support

Post by kim »

amc:
def movieFile = fs.findAll{ it.isVideo() || it.isDisk() }.sort{ it.length() }.reverse().findResult{ it }
I don't get why use ".sort{ it.length() }.reverse()" (now: only make nfo from the 1 file with highest filesize) ?
(if almost same filesize the order is a bit random, on first run, after that wrong way from the design...
tested in GUI and No I can't reproduce this on command)

I changed it to just ".sort()" ... now with my, make nfo with every files data, it is always cd1, cd2...
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Feature Request: MultiCD MediaInfo summary support

Post by rednoah »

That's probably to deal with samples or trailers and what not. The largest file is the actual movie file, usually.

CD123 multi-part movies are not considered or supported in this aspect, so behaviour might be somewhat random.
:idea: Please read the FAQ and How to Request Help.
Post Reply