Calculate Cover Size 1.4 [MM2+3]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Calculate Cover Size 1.4 [MM2+3]

Postby trixmoto on Thu Sep 07, 2006 9: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 custom field of your choice. You can choose to calculate average/maximum/minimum/first/total.

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.4
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE: 02/06/2008
'
' NOTE: Additional Field (Total followed by Dimensions) added 01/06/08 by Seeker
'       Use searching for CHANGE YOURSELF if you want a different first field
'
' 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: Added option to show total and dimensions (thanks to Seeker)
'        Added option to not store zero values (thanks to Seeker)
'        Fixed only modified tracks are updated (thanks to Seeker)
'

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")
  Dim Pop : Pop = ini.BoolValue("CalcCoverSize","Pop")

  'create confirmation screen
  Dim Form : Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 350, 220
  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")
' Change text below if you want a different first field - CHANGE YOURSELF
  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.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 Label6 : Set Label6 = SDB.UI.NewLabel(Form)
  Label6.Caption = "Don't Populate Tracks without Cover Art?"
  Label6.Common.Left = 28
  Label6.Common.Top = EdtPad.Common.Top + EdtPad.Common.Height +40

  Dim EdtPop : Set EdtPop = SDB.UI.NewCheckbox(Form)
  EdtPop.Common.Left = 10
  EdtPop.Common.Top = EdtPad.Common.Top + EdtPad.Common.Height +37
  EdtPop.Caption = "Don't Populate Tracks without Cover Art?"
  EdtPop.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 -15
  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

  'loop through tracks
  Dim i,j,str, ipop
  For i = 0 To list.Count-1
    'reset populate value
    ipop = pop
    'update progress bar
    prog.Increase
    prog.Text = "CalculateCoverSize: Processing track "&prog.Value&"/"&prog.MaxValue&"..."
    SDB.ProcessMessages
    '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 = 8 Then
' If you want kb as first field - replace the two lines below with:  - CHANGE YOURSELF
'                  tot = tot + (img.ImageDataLen\1000)
                  Dim siz8 : siz8 = img.Width*img.Height
                  tot = tot + siz8
'Below is redundant for Total + WidthxHeight, but included if someone wants a different first field than total
                  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 Redundant for "Total + WidthxHeight
              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
'Below is redundant, but included if someone wants a different first field than total in Total+WidthxHeight
'Change res=tot under Case 8 to res = (avg/one/min/max/cnt) for different first value - CHANGE YOURSELF
'If you want thie first field to be (kb), change the area mentioned above rather than here and then leave this alone(res=tot will work)
        Case 8
          res = tot
'End redundant for Total+WidthxHeight
        Case Else
          res = tot
      End Select
    End If
    'update track
   If ipop and (not (res<=0)) and (not (act="")) 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 Else
      prog.Terminate = True
   End Select
   End If
   if not ipop Then
     itm.UpdateDB
     changelist.add(itm)
   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
  Call changelist.UpdateAll()
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 9:05 am, edited 6 times in total.
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby teemac on Fri Sep 08, 2006 2:23 am

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.
teemac
 
Posts: 30
Joined: Sun Apr 02, 2006 6:09 am

Postby trixmoto on Fri Sep 08, 2006 9: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!! :)
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby junglemonkey on Fri Sep 08, 2006 9: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) :-?
junglemonkey
 

Postby trixmoto on Fri Sep 08, 2006 12:36 pm

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.
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby Sammy20 on Wed Sep 27, 2006 1:28 pm

umm how did I overlook this script?

Very handy, me thinks.
Sammy20
 
Posts: 108
Joined: Thu Feb 17, 2005 10:42 am

Postby trixmoto on Wed Sep 27, 2006 1:42 pm

Well, it's fairly new. Glad you like it! :)
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby nojac on Tue Jan 23, 2007 11: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?
nojac
 
Posts: 504
Joined: Tue Dec 19, 2006 5:23 pm
Location: Norway

Postby pah68 on Tue Jan 23, 2007 11: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
pah68
 
Posts: 1479
Joined: Wed Apr 07, 2004 10:26 pm
Location: Sydney, Australia

Postby paulmt on Wed Jan 24, 2007 6:28 am

It's not this one is it??
paulmt
 
Posts: 1103
Joined: Tue Jul 18, 2006 11:06 pm

Postby pah68 on Wed Jan 24, 2007 8:25 am

That's the one...2nd post from the top :wink:
Image
Image
pah68
 
Posts: 1479
Joined: Wed Apr 07, 2004 10:26 pm
Location: Sydney, Australia

Postby trixmoto on Wed Jan 24, 2007 9:39 am

I'm glad you like the script. I will add these two options to a new version, sometime! :)
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby trixmoto on Wed Feb 28, 2007 2:24 pm

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
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Postby Eyal on Sat Mar 03, 2007 9: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!
Eyal
 
Posts: 2304
Joined: Sun Jun 26, 2005 2:27 pm
Location: Canada

Postby trixmoto on Mon Mar 05, 2007 9: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?
Loving the Monkey? - Get Gold
Check out my scripts at http://trixmoto.net including my top ten
Subscribe to my rss feed for all the latest news
trixmoto
 
Posts: 7913
Joined: Fri Aug 26, 2005 8:28 am
Location: England

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: MSN [Bot] and 3 guests