INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Script to save cover art size  (Read 11443 times)

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Script to save cover art size
« on: April 18, 2009, 04:52:41 am »

I've created a c# script which will save the cover art height and widths to a field of your choice.

The script is attached to this post and you can use it standalone without any plugins.  (You will need .NET Framework 2.0)

To run the script simply place some files into Playing Now then run the 'Run Script.bat' file.

I believe there is a bug in MC when getting images from multiple Mp3's with embedded cover art, which means some files maybe missed.
It shouldn't cause any damage however.


You can edit the script in notepad to meet your requirements.  To find more about scripting take a look at the .NET Script Plugin avaialble here:
http://yabb.jriver.com/interact/index.php?topic=38693.msg263177

The script can be seen as plain text here:
http://yabb.jriver.com/interact/index.php?topic=33020.msg351860#new


Obviously it would be better if MC could generate the cover art size itself, but this is a good interim soloution.

---------Current Version 1.52
History:
1.52 - Fixed Embedded art broken by previous changes
1.51 - Support Added for Images sat sideline music files.
1.42 Defaulted back to not overwriting tags
1.41 Changed default fields to Image "Image File (height)" and "Image File (width)"
1.4 - Changed Script now works with both embedded and external cover art

1.3 - Improved console output using batch file.

1.2 - Not Released

1.1 - Added ability to choose to overwrite tags or not

1.0 Issue with Width being saved to both width and height

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Script to save cover art size
« Reply #1 on: April 18, 2009, 08:31:59 am »

Thanks Chriz, I installed the Scripting Plugin, but it didn't work:

Quote
Compiling Script...

Failure Compiling Script :-

c:\Program Files\MCScriptPlugin\Scripts\Cover Art Size.cs(33,5) : error CS1002: ; expected


 The Failure Occured
 In Class Object CSScriptLibrary
 when calling Method System.String Compile(System.String)
 
 The following Inner Exception was caused
 
 Everything that follows forms the stack Trace:

   at csscript.CSExecutor.Compile(String scriptFileName)
   at csscript.CSExecutor.Compile(String scriptFile, String assemblyFile, Boolean debugBuild)
   at CSScriptLibrary.CSScript.CompileWithConfig(String scriptFile, String assemblyFile, Boolean debugBuild, String cssConfigFile)
   at ScriptRunner.ScriptRunner.Main(String[] args)

I changed the field names as instructed. It was logical to create the Image File (width) and Image File (height) fields because I already have the Image File column in my view schemes. Here's how I changed the code:

Code: [Select]
       //Change the following to variables to change where the script places the image size'
        string fieldToUseForCoverArtHeight = "Image File (height)" ;
        string fieldToUseForCoverArtWidth = "Image File (width)";   
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Script to save cover art size
« Reply #2 on: April 18, 2009, 08:46:56 am »

You 3rd edit works a bit better. Now I get this:

Quote
Compiling Script...
Script Compiled Successfully!
Running Script...
Script Completed Successfully

Unfortunately the library fields remain empty after running the script.
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Script to save cover art size
« Reply #3 on: April 18, 2009, 08:57:20 am »

hmm strange it's filling them here ok.
What type did you give the fields?
Also what file types are you running it on, and is cover art embedded?

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Script to save cover art size
« Reply #4 on: April 18, 2009, 09:02:24 am »

both int and string appear to be working here...

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Script to save cover art size
« Reply #5 on: April 18, 2009, 09:05:09 am »

I suspect your art isn't Embedded and as a result MC doesn't return art for these files.
Try the attached version.
This will output a console string indicating MC didn't return any cover art.

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Script to save cover art size
« Reply #6 on: April 18, 2009, 09:20:14 am »

What type did you give the fields?

The fields are default (string). I just quickly created two new fields - typed the names and saved without changing anything.

I suspect your art isn't Embedded and as a result MC doesn't return art for these files.

Correct, I never use embedded art.

Quote
Try the attached version.
This will output a console string indicating MC didn't return any cover art.

-Script removed pending investigation - Please don't use for the minute... -

 :)

I attached a screenshot of the fields in PN and cover art in AW > Tag > Image:

(Log in to the forum if you can't see the attachment.)
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #7 on: April 18, 2009, 10:09:15 am »

OK Take 4!

This ones more intelligent and will try first external cover art, then if that doesn't exist internal embedded cover art.
With embedded cover art MC saves a temporary image to the temp directory.  The script has the option to delete these temporary files after use, but this is defaulted to turned off and should be used with care.

Top Post Updated.

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #8 on: April 18, 2009, 10:27:45 am »

4 taken:

Quote
Compiling Script...
Script Compiled Successfully!
Running Script...
Media Center Returned No Image
Media Center Returned No Image
Media Center Returned No Image
Media Center Returned No Image
Media Center Returned No Image
Media Center Returned No Image
Media Center Returned No Image
Script Completed Successfully

It's now doing a bit more, but...

I am testing with the files in my screenshot. The 7 audio files and external cover art file are in X:\Steely Dan\Aja\
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #9 on: April 18, 2009, 10:37:54 am »

That's strange.   What does the "Image File" tag read for one of those?

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #10 on: April 18, 2009, 10:43:47 am »

It's in the screenshot. MC doesn't store the path when the image is "next to file".

As a test, I moved the image file to another folder and relinked from there. The script works fine when the full path is in the Image File field.

Would it be possible to combine the value of the Filename (path) field with the value of the Image File field in case the Image File field does not contain a path?
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #11 on: April 18, 2009, 10:47:38 am »

Ah that would explain it, I didn't know MC done that.
So just to confirm what would the actual image filename be?

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #12 on: April 18, 2009, 10:49:29 am »

Ah sorry, been staring at the screen too long, as you explained.
OK V1.5 coming up!

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #13 on: April 18, 2009, 11:00:58 am »

The pathless filename in the Image File field is a very nice thing because it is valid even when the folder is moved.

MC stores always either the complete filename path including the filename or just the plain filename without any path. It does not use relative paths. The filename itself can be anything when a cover art file is linked manually so it must be read from the Image File field.
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #14 on: April 18, 2009, 11:29:02 am »

Top Post Updated, give that one a whirl!

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #15 on: April 18, 2009, 12:06:59 pm »

Thanks,

The v.1.51 works with my test album. The Scripting Plugin and also the "Run Script.bat" file worked fine and created correct dimension values.

Also the new field names are nice.   ;)
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #16 on: April 18, 2009, 12:26:46 pm »

Thanks,

The v.1.51 works with my test album. The Scripting Plugin and also the "Run Script.bat" file worked fine and created correct dimension values.

Also the new field names are nice.   ;)

That's good to hear! =)

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #17 on: April 18, 2009, 12:51:16 pm »

I added a new calculated field: "Image File (kilopixel)".

It uses the FormatNumber(Math([Image File (width)]*[Image File (height)]/1000),2) expression.

It shows the calculated image size in a single column that can be used for sorting. I can now remove the other two columns from the view (the view already had about 50 columns).

A screenshot is attached. (Log in to the forum if you can't see it.)

EDIT

I added a screenshot of Mr ChriZ's Scripting Plugin interface. The plugin is available here: http://yabb.jriver.com/interact/index.php?topic=38693.0
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Torture Test (Re: Script to save cover art size)
« Reply #18 on: April 18, 2009, 03:01:33 pm »

I am now running a torture test.

I loaded about 50,000 audio files to Playing Now, and started the Scripting Plugin.

The test rig is an old 2.4 GHz Pentium 4 desktop (1 GB of RAM). I disabled the virus scanner and closed other programs before starting. The files are on a 1 TB external USB2 drive. The cover art files are external and mostly linked from the audio files' folders.

During the first 30 minutes it went through about 4,500 files. If it can maintain the same speed the total time should be about 5½ hours.

The processor usage is very close to 100% (it uses all available CPU) and the memory usage seems to be constantly about 200 MB (ScriptRunner.exe uses 100 MB and MC uses 100 MB).


EDIT

Even though it's a hungry beast it behaves nicely. I started playback on another zone using the same MC instance and I can't hear any problems. That's actually a bit surprising because the processor has only a single core and no Hyper-Threading.

Listening to: 'The Torture Never Stops' from 'Zoot Allures' by 'Frank Zappa' on Media Center 13


EDIT 2

I forgot to mention that I didn't set the new fields to write tags. I didn't want to invalidate my two backup sets (= 1.8 TB of data) by writing quite useless file tags. As an additional precaution, I disabled tagging completely in the general options before proceeding, though that was probably unnecessary.
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #19 on: April 18, 2009, 08:42:52 pm »

Just for reference, I think it's much faster running ScriptRunner standalone than in the script plugin.
I think the reason being that the feeding the output back into the script plugin textbox is very intensive for some reason.
If I get round to it (unlikely) I will investigate speeding that up.

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #20 on: April 19, 2009, 04:28:54 am »

I stopped my "torture test" at about 15k files. Until that it was stable, but I think it was gradually getting slower (possibly because of the increasing size of the log) and in addition the poor old PC was becoming quite warm after running a couple of hours at 100% CPU.

As you said, the stand-alone script is much faster. I started testing it with a batch of a few hundred files and increased the size of each following batch. The last batch had about 25,000 files and the processing time was only about 15 minutes.

I didn't notice any problems during the tests.
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #21 on: April 19, 2009, 06:34:21 am »

The pathless filename in the Image File field is a very nice thing because it is valid even when the folder is moved.

MC stores always either the complete filename path including the filename or just the plain filename without any paths. It does not use relative paths. The filename itself can be anything when a cover art file is linked manually so it must be read from the Image File field.

I like this idea, unfortunatley it doesn't seem to work well with portable install.  It would have been good for files where embedded art is not possible.

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #22 on: April 19, 2009, 11:44:04 am »

I think Matt fixed it partially. If there is cover art in the folder when the files are initially imported the links do not contain the path and the same is true also when the "quick find" tool is used, but there are still bugs. For instance, when cover art is dragged from the file folder to the image window the full path including the drive letter appears in the Image File value.

Also when a common folder is used the path in the Image File field does not start with something like "install drive" as it should. This happens even when the default location is used. In my case it happens be T:\MC13P\Application Data\J River\Media Center 13\Cover Art and if the drive letter is different on another PC the path is invalid.
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #23 on: April 19, 2009, 04:14:23 pm »

I was just trying to paste art in and it was failing.  I might just need to play more!

[Edit] If the Audio File's path is for example (Install Drive):\Media\Audio\DJ Shadow\Entroducing\Disc Unknown Disc #\16 - Transmission 3.ape
Then it won't work.  However by changing it to K:\Media\Audio\DJ Shadow\Entroducing\Disc Unknown Disc #\16 - Transmission 3.ape it does.

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #24 on: April 19, 2009, 04:32:51 pm »

Apparently "paste cover art" is another file location related feature that has not been adjusted to work with the portable install.

Maybe we should gather a list of all features that don't properly use or understand the "(Install Drive):\" path structure.
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

zxsix

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1753
Re: Script to save cover art size
« Reply #25 on: August 08, 2010, 04:09:05 pm »

Trying this with version 15.  Get the following error.  Any ideas?
Code: [Select]
Failure Compiling Script :-
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

 The Failure Occured
 In Class Object mscorlib
 when calling Method Void GetActiveObject(System.Guid ByRef, IntPtr, System.Object ByRef)
 
 The following Inner Exception was caused
 
 Everything that follows forms the stack Trace:

   at System.Runtime.InteropServices.Marshal.GetActiveObject(Guid& rclsid, IntPtr reserved, Object& ppunk)
   at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)
   at ScriptRunner.ScriptRunner.Main(String[] args)
Logged

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #26 on: August 09, 2010, 06:23:30 am »

The standalone script works for me on XP (32-bit).

The problem may not be caused by the changes in MC15. Have you tried the script with MC14?
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

zxsix

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1753
Re: Script to save cover art size
« Reply #27 on: August 09, 2010, 07:08:47 am »

No.  I never had 14 on this machine as it is fairly new.  Win-7 x64.
No internal art.  Files are flax with coverart in same folder as folder.jpg.
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Script to save cover art size
« Reply #28 on: August 09, 2010, 07:10:36 am »

No.  I never had 14 on this machine as it is fairly new.  Win-7 x64.

I've seen this a few times.  I don't know why but a clean install of MC seems to solve the problem.
I've got a feeling it's actually because of having old versions of MC installed.

I don't know an easier/cleaner solution at present.

For some reason sometimes MC doesn't get entered in the Running Object Table, that the scripts (and other out of proc plugins) attaches too....

zxsix

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1753
Re: Script to save cover art size
« Reply #29 on: August 09, 2010, 07:25:21 am »

It's working fine if I paste the script into your plugin.
I just can't get the standalone to run.
Doesn't matter, I can use the plugin.
Thanks for providing the script.
Logged

Alex B

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 10121
  • The Cosmic Bird
Re: Script to save cover art size
« Reply #30 on: August 09, 2010, 07:39:23 am »

I have all MC and MJ versions since MC11.1 installed on the XP PC.

I just tried the script on 32-bit Windows 7. It worked fine. On that PC I have MC14, MC15 & MJ12.


zxsix,

Did you create the two new library fields and place the files to be processed in Playing Now? (Edit: Forget this. I just read your reply.)

I am just guessing, but you could create a folder in C:\Program Files (x86)\ and try to run the script files from there (unless you are already doing that).
Logged
The Cosmic Bird - a triple merger of galaxies: http://eso.org/public/news/eso0755

zxsix

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1753
Re: Script to save cover art size
« Reply #31 on: August 09, 2010, 09:00:49 am »

I unzipped the script into c:\program files (x86)\J River\Cover Art Script

Doesn't matter, using the plugin is cranking away and should be done by the time I get home from work.
Logged
Pages: [1]   Go Up