Calculate Cover Size 1.7 - Updated 23/10/2012

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Calculate Cover Size 1.7 - Updated 23/10/2012

Post by trixmoto » Thu Sep 07, 2006 4:59 am

This script, as requested here, calculates the cover size (width multiplied by height) for all the selected tracks and stores the value in the string field of your choice. You can choose to calculate average/maximum/minimum/first/total/etc.

In order for you to be able to sort in MM (which is alphabetical) you need to add leading zeros, which you can specify on the confirmation screen that is presented.

The installer can be downloaded from my website. Remember, your feedback is essential! :)

Code: Select all

'
' MediaMonkey Script
'
' NAME: CalculateCoverSize 1.7
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE: 22/10/2012
'
' NOTE: Additional Field (Total followed by Dimensions) added 01/06/08 by Seeker
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
'          Don't forget to remove comments (') and set the order appropriately   
'
' [CalculateCoverSize]
' FileName=CalculateCoverSize.vbs
' ProcName=CalculateCoverSize
' Order=10
' DisplayName=Calculate Cover Size
' Description=Calculates cover size for selected tracks
' Language=VBScript
' ScriptType=0
'
' FIXES: Fixed "Don't populate..." option not working in some modes (thanks to Nanya)
'

Option Explicit

Sub CalculateCoverSize
  'create list
  Dim list : Set list = SDB.SelectedSongList
  If list.Count = 0 Then
     Set list = SDB.AllVisibleSongList
  End If
  If list.Count = 0 Then
    Call SDB.MessageBox("CalculateCoverSize: Select tracks to be processed.", mtError, Array(mbOk))
    Exit Sub
  End If
  Dim changelist : Set changelist = SDB.NewSongList
 
  'create progress bar
  Dim prog : Set prog = SDB.Progress
  prog.Value = 0
  prog.MaxValue = list.Count
  prog.Text = "CalculateCoverSize: Initialising..."
 
  'get settings 
  Dim ini : Set ini = SDB.IniFile
  If ini.StringValue("CalcCoverSize","Sum") = "" Then
    ini.IntValue("CalcCoverSize","Sum") = 1 '0=total 1=average 2=first 3=minimum 4=maximum 5=count 6=diskspace 7=WidthxHeight 8=Special (example: Total; WidthxHeight)
  End If
  Dim Sum : Sum = ini.IntValue("CalcCoverSize","Sum")
  If ini.StringValue("CalcCoverSize","Fld") = "" Then
    ini.IntValue("CalcCoverSize","Fld") = 3 'Custom field number (1,2,3,4,5)
  End If
  Dim Fld : Fld = ini.IntValue("CalcCoverSize","Fld")
  If ini.StringValue("CalcCoverSize","Pad") = "" Then
    ini.IntValue("CalcCoverSize","Pad") = 9 'Number of characters (zero padded from left)
  End If 
  Dim Pad : Pad = ini.IntValue("CalcCoverSize","Pad")
  If ini.StringValue("CalcCoverSize","Tag") = "" Then
    ini.BoolValue("CalcCoverSize","Tag") = True 'Include embedded images
  End If 
  Dim Tag : Tag = ini.BoolValue("CalcCoverSize","Tag")   
  If ini.StringValue("CalcCoverSize","Lnk") = "" Then
    ini.BoolValue("CalcCoverSize","Lnk") = True 'Include linked images
  End If 
  Dim Lnk : Lnk = ini.BoolValue("CalcCoverSize","Lnk")
  If ini.StringValue("CalcCoverSize","Pop") = "" Then
    ini.BoolValue("CalcCoverSize","Pop") = False 'Don't populate rracks without cover art?
  End If   
  Dim Pop : Pop = ini.BoolValue("CalcCoverSize","Pop") 
  If ini.StringValue("CalcCoverSize","Wrt") = "" Then
    ini.BoolValue("CalcCoverSize","Wrt") = False 'Only update database (not files)?
  End If 
  Dim Wrt : Wrt = ini.BoolValue("CalcCoverSize","Wrt")  
 
  'create confirmation screen
  Dim Form : Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 360, 245
  Form.BorderStyle  = 3   ' Non-Resizable
  Form.FormPosition = 4   ' Screen Center
  Form.SavePositionName = "CalcCoverSizePos"
  Form.Caption = "Calculate Cover Size"
 
  Dim Label : Set Label = SDB.UI.NewLabel(Form)
  Label.Caption = "Populate the "&list.Count&" selected tracks with the"
  Label.Common.Left = 10
  Label.Common.Top = 15
 
  Dim EdtSum : Set EdtSum = SDB.UI.NewDropdown(Form)
  EdtSum.Common.Left = 10
  EdtSum.Common.Top = Label.Common.Top + Label.Common.Height +10
  EdtSum.AddItem("Total")
  EdtSum.AddItem("Average")
  EdtSum.AddItem("First")
  EdtSum.AddItem("Minimum")
  EdtSum.AddItem("Maximum")
  EdtSum.AddItem("Count")
  EdtSum.AddItem("Diskspace (kb)")
  EdtSum.AddItem("Width x Height")
  EdtSum.AddItem("Total; W x H")
  EdtSum.ItemIndex = Sum 
  EdtSum.Style = 2
 
  Dim Label2 : Set Label2 = SDB.UI.NewLabel(Form)
  Label2.Caption = "(size) of the artwork, stored in"
  Label2.Common.Left = EdtSum.Common.Left + EdtSum.Common.Width +5
  Label2.Common.Top = EdtSum.Common.Top +3
 
  Dim EdtFld : Set EdtFld = SDB.UI.NewDropdown(Form)
  EdtFld.Common.Left = 10
  EdtFld.Common.Top = EdtSum.Common.Top + EdtSum.Common.Height +10
  EdtFld.AddItem("Please select...")
  EdtFld.AddItem("1. "&ini.StringValue("CustomFields","Fld1Name"))
  EdtFld.AddItem("2. "&ini.StringValue("CustomFields","Fld2Name"))
  EdtFld.AddItem("3. "&ini.StringValue("CustomFields","Fld3Name"))
  EdtFld.AddItem("4. "&ini.StringValue("CustomFields","Fld4Name"))
  EdtFld.AddItem("5. "&ini.StringValue("CustomFields","Fld5Name"))
  EdtFld.AddItem("Comment")
  EdtFld.AddItem("Encoder")
  EdtFld.AddItem("Genre")
  EdtFld.AddItem("Grouping")
  EdtFld.AddItem("ISRC")
  EdtFld.AddItem("Lyrics")
  EdtFld.AddItem("Mood")
  EdtFld.AddItem("Occasion")
  EdtFld.AddItem("Publisher")
  EdtFld.AddItem("Quality")
  EdtFld.AddItem("Tempo")  
  EdtFld.ItemIndex = Fld
  EdtFld.Style = 2
 
  Dim Label3 : Set Label3 = SDB.UI.NewLabel(Form)
  Label3.Caption = "which will be zero padded from the left to"
  Label3.Common.Left = EdtFld.Common.Left + EdtFld.Common.Width +5
  Label3.Common.Top = EdtFld.Common.Top +3
 
  Dim EdtPad : Set EdtPad = SDB.UI.NewSpinEdit(Form)
  EdtPad.Common.Left = 10
  EdtPad.Common.Top = EdtFld.Common.Top + EdtFld.Common.Height +10
  EdtPad.MinValue = 0
  EdtPad.MaxValue = 250
  EdtPad.Value = Pad
 
  Dim Label4 : Set Label4 = SDB.UI.NewLabel(Form)
  Label4.Caption = "characters so I can sort alphabetically?"
  Label4.Common.Left = EdtPad.Common.Left + EdtPad.Common.Width +5
  Label4.Common.Top = EdtPad.Common.Top +3 
 
  Dim Label5 : Set Label5 = SDB.UI.NewLabel(Form)
  Label5.Caption = "Include images"
  Label5.Common.Left = 10
  Label5.Common.Top = EdtPad.Common.Top + EdtPad.Common.Height +10 
 
  Dim EdtTag : Set EdtTag = SDB.UI.NewCheckbox(Form)
  EdtTag.Common.Left = 90
  EdtTag.Common.Top = Label5.Common.Top -5
  EdtTag.Caption = "in tags?"
  EdtTag.Checked = Tag

  Dim EdtLnk : Set EdtLnk = SDB.UI.NewCheckbox(Form)
  EdtLnk.Common.Left = 90
  EdtLnk.Common.Top = Label5.Common.Top +11
  EdtLnk.Caption = "linked?" 
  EdtLnk.Checked = Lnk
 
  Dim EdtPop : Set EdtPop = SDB.UI.NewCheckbox(Form)
  EdtPop.Common.Left = 10
  EdtPop.Common.Top = EdtPad.Common.Top + EdtPad.Common.Height +40
  EdtPop.Common.Width = 300
  EdtPop.Caption = "Don't populate tracks without cover art?"
  EdtPop.Checked = Pop
  
  Dim EdtWrt : Set EdtWrt = SDB.UI.NewCheckbox(Form)
  EdtWrt.Common.Left = 10
  EdtWrt.Common.Top = EdtPop.Common.Top +17
  EdtWrt.Common.Width = 300
  EdtWrt.Caption = "Only update database (not files)?"
  EdtWrt.Checked = Pop  
 
  Dim BtnCancel : Set BtnCancel = SDB.UI.NewButton(Form)
  BtnCancel.Caption = "&Cancel"
  BtnCancel.Cancel = True
  BtnCancel.ModalResult = 2
  BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width -25
  BtnCancel.Common.Top = EdtPad.Common.Top + EdtPad.Common.Height +10
 
  Dim BtnOk : Set BtnOk = SDB.UI.NewButton(Form)
  BtnOk.Caption = "&Ok"
  BtnOk.Default = True
  BtnOk.ModalResult = 1
  BtnOk.Common.Left = BtnCancel.Common.Left - BtnOk.Common.Width -10
  BtnOk.Common.Top = BtnCancel.Common.Top   
 
  'show confirmation screen
  If Not (Form.ShowModal = 1) Then
    Exit Sub
  End If 
 
  'save settings
  Sum = EdtSum.ItemIndex
  ini.IntValue("CalcCoverSize","Sum") = Sum
  Fld = EdtFld.ItemIndex
  ini.IntValue("CalcCoverSize","Fld") = Fld
  Pad = EdtPad.Value
  ini.IntValue("CalcCoverSize","Pad") = Pad
  Tag = EdtTag.Checked
  ini.BoolValue("CalcCoverSize","Tag") = Tag
  Lnk = EdtLnk.Checked
  ini.BoolValue("CalcCoverSize","Lnk") = Lnk
  Pop = EdtPop.Checked
  ini.BoolValue("CalcCoverSize","Pop") = Pop
  Wrt = EdtWrt.Checked
  ini.BoolValue("CalcCoverSize","Wrt") = Wrt  

  'loop through tracks
  Dim i,j,str,ipop
  For i = 0 To list.Count-1
    'update progress bar
    prog.Increase
    prog.Text = "CalculateCoverSize: Processing track "&prog.Value&"/"&prog.MaxValue&"..."
    SDB.ProcessMessages
	ipop = Pop
	
    'check for artwork
    Dim itm : Set itm = list.Item(i)
    Dim res : res = 0   
    Dim art : Set art = itm.AlbumArt
    If Not (art Is Nothing) Then
      'calculate dimensions
      Dim tot : tot = 0
      Dim avg : avg = 0
      Dim one : one = -1
      Dim min : min = 9999999999
      Dim max : max = 0
      Dim cnt : cnt = 0
      Dim act : act = ""
      For j = 0 To art.Count-1
        Dim inc : inc = False
        Select Case art.Item(j).ItemStorage
          Case 0
            inc = Tag
          Case 1
            inc = Lnk
        End Select
        If inc Then
          Dim img : Set img = art.Item(j).Image
          If Not (img Is Nothing) Then       
            cnt = cnt+1
            Select Case Sum
              Case 6
                tot = tot + (img.ImageDataLen\1000)
              Case 7, 8
                If act = "" Then
                  act = img.Width&"x"&img.Height
                Else
                  act = act&";"&img.Width&"x"&img.Height
                End If
                If Sum = 7 Then
                  tot = tot +1 
                Else
                  Dim siz8 : siz8 = img.Width*img.Height
                  tot = tot + siz8
                  If one = -1 Then
                    one = siz
                  End If
                  If siz < min Then
                    min = siz
                  End If
                  If siz > max Then
                    max = siz
                  End If
                End If
              Case Else
                Dim siz : siz = img.Width*img.Height
                tot = tot + siz
                If one = -1 Then
                  one = siz
                End If
                If siz < min Then
                  min = siz
                End If
                If siz > max Then
                  max = siz
                End If
            End Select
          End If
        End If
      Next
      If cnt > 0 Then
        avg = tot \ cnt
      Else
        one = 0
        min = 0
      End If
	  
      'choose result
      Select Case Sum
        Case 1
          res = avg
        Case 2
          res = one
        Case 3
          res = min
        Case 4
          res = max
        Case 5
          res = cnt
        Case Else
          res = tot
      End Select
    End If
	
    'update track
    If (ipop) And (res > 0) Then
      ipop = False
    End If
    If Not ipop Then
      If Sum = 7 Then
        str = act
      Else
        If res < 0 Then
          res = 0
        End If   
        str = ""&res
        Do While Len(str) < Pad
          str = "0"&str
        Loop
        If Sum = 8 Then
          str = str&"; "&act
        End If
      End If
      Select Case Fld
        Case 1
          ipop = (itm.Custom1 = str)
          itm.Custom1 = str
        Case 2
          ipop = (itm.Custom2 = str)
          itm.Custom2 = str
        Case 3
          ipop = (itm.Custom3 = str)
          itm.Custom3 = str
        Case 4
          ipop = (itm.Custom4 = str)
          itm.Custom4 = str
        Case 5
          ipop = (itm.Custom5 = str)
          itm.Custom5 = str          
        Case 6
          ipop = (itm.Comment = str)
          itm.Comment = str
        Case 7
          ipop = (itm.Encoder = str)
          itm.Encoder = str
        Case 8
          ipop = (itm.Genre = str)
          itm.Genre = str
        Case 9
          ipop = (itm.Grouping = str)
          itm.Grouping = str
        Case 10
          ipop = (itm.ISRC = str)
          itm.ISRC = str
        Case 11
          ipop = (itm.Lyrics = str)
          itm.Lyrics = str
        Case 12
          ipop = (itm.Mood = str)
          itm.Mood = str
        Case 13
          ipop = (itm.Occasion = str)
          itm.Occasion = str
        Case 14
          ipop = (itm.Publisher = str)
          itm.Publisher = str
        Case 15
          ipop = (itm.Quality = str)
          itm.Quality = str
        Case 16
          ipop = (itm.Tempo = str)
          itm.Tempo = str            
        Case Else
          prog.Terminate = True
      End Select
    End If
    If Not ipop Then
      itm.UpdateDB
	  If Not Wrt Then
        Call changelist.Add(itm)
	  End If
    End If
	
    'check next track
    If prog.Terminate Then
      Exit For
    End If
  Next
 
  'save all
  prog.Value = prog.MaxValue
  prog.Text = "CalculateCoverSize: Finalising..."
  SDB.ProcessMessages 
  If Not Wrt Then
    Call changelist.UpdateAll() 
  End If
End Sub

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("CalculateCoverSize","Filename") = "CalculateCoverSize.vbs"
    inif.StringValue("CalculateCoverSize","Procname") = "CalculateCoverSize"
    inif.StringValue("CalculateCoverSize","Order") = "10"
    inif.StringValue("CalculateCoverSize","DisplayName") = "Calculate Cover Size"
    inif.StringValue("CalculateCoverSize","Description") = "Calculates cover size for selected tracks"
    inif.StringValue("CalculateCoverSize","Language") = "VBScript"
    inif.StringValue("CalculateCoverSize","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Mon Jun 02, 2008 4:05 am, edited 6 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

teemac
Posts: 30
Joined: Sun Apr 02, 2006 1:09 am

Post by teemac » Thu Sep 07, 2006 9:23 pm

Works perfect for me - this is the second script you have written in the last few days I am not going to be able to do without now.

Great stuff - and thankyou very much.

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Fri Sep 08, 2006 4:03 am

Glad you like it. I didn't realise how much I'd use it until I found out just how small some of my artwork is using it!! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

junglemonkey

Post by junglemonkey » Fri Sep 08, 2006 4:35 am

the only thing i can think of is that this script might make it more pixelated by stretching it to fit.?

does the script do that? i have seen some embeded covers the size of 50 x 50 pixels and they look bad when stretched.

8) :-?

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Fri Sep 08, 2006 7:36 am

Where does my description mention editing the image in any way? The script calculates the size and puts this value in one of the custom fields. Please try the script before providing feedback on it.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

Sammy20
Posts: 110
Joined: Thu Feb 17, 2005 5:42 am

Post by Sammy20 » Wed Sep 27, 2006 8:28 am

umm how did I overlook this script?

Very handy, me thinks.

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Wed Sep 27, 2006 8:42 am

Well, it's fairly new. Glad you like it! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

nojac
Posts: 517
Joined: Tue Dec 19, 2006 12:23 pm
Location: Norway

Post by nojac » Tue Jan 23, 2007 6:36 pm

Another nice script from you. (Your Art Tagger and Art Finder are GREAT!) And this one is of great help in cleaning my collection.

But what I really need is a script which tells me how many art files are included in each track, and how much space they occupy in the file.

Can that be done?

pah68
Posts: 1496
Joined: Wed Apr 07, 2004 5:26 pm
Location: Sydney, Australia

Post by pah68 » Tue Jan 23, 2007 6:47 pm

There was a script somewhere on here that counted album art for tracks. Sorry I can't be of more use, maybe someone can recall?
Image
Image

paulmt
Posts: 1170
Joined: Tue Jul 18, 2006 6:06 pm

Post by paulmt » Wed Jan 24, 2007 1:28 am

It's not this one is it??

pah68
Posts: 1496
Joined: Wed Apr 07, 2004 5:26 pm
Location: Sydney, Australia

Post by pah68 » Wed Jan 24, 2007 3:25 am

That's the one...2nd post from the top :wink:
Image
Image

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Wed Jan 24, 2007 4:39 am

I'm glad you like the script. I will add these two options to a new version, sometime! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Wed Feb 28, 2007 9:24 am

New version (1.1) is now available from my website. Changes include...

- Added option to count the number of images for each track
- Added option to calculate total filesize of images
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

Eyal
Posts: 3105
Joined: Sun Jun 26, 2005 9:27 am
Location: Québec

Post by Eyal » Sat Mar 03, 2007 4:15 pm

Took me a while to figure out what that script really do, and how I could use it. Now my 3rd personal field in MM is named "Art Size (kb)" and is been updated every time the script was ran.

It's cool. :D

But is it possible to have it doing it automatically?
At least having a button on the toolbar would be nice,
it will prevent the long and fastidious menus.

Thanks a lot!

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK
Contact:

Post by trixmoto » Mon Mar 05, 2007 4:07 am

What do you mean by "automatically" - whenever a track is added?

If you edit Scripts.ini (with MM closed) and find the [CalculateCoverSize] section you can add "Shortcut=Alt+C" or whatever shortcut you like at the bottom. Then when you run MM you'll find you can run the script without traversing the menus. I can add a button if you really want though?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

Post Reply