Need help with report script...

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

wbss26
Posts: 20
Joined: Wed Jun 09, 2004 8:21 am

Need help with report script...

Post by wbss26 »

I am not that good with HTML and would like to have the reports display the total song length for all songs in the report.

Any help would be appreciated.
thanks,
Brian A.
Better to Burn out than to fade away....
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Code: Select all

... see below ...
Last edited by onkel_enno on Mon Aug 29, 2005 1:07 am, edited 1 time in total.
rk
Posts: 104
Joined: Mon Jul 25, 2005 2:18 am
Location: Germany

Post by rk »

Hey onkel_enno,
is there any kind of script you not have already written or somehow at hand? :wink:
Quite impressive!
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Thx 8)

I'm programming the whole day and so it's quite easy for me to solve such easy things quickly for my MM-Friends :lol:
wbss26
Posts: 20
Joined: Wed Jun 09, 2004 8:21 am

Script

Post by wbss26 »

Onkel,

This is great. Thank you very much.

Brian A.
Better to Burn out than to fade away....
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Post by Peke »

onkel_enno,
What do you use for programming?

BTW I do not know about you but sometimes solving some scripting problem looks like taking a nap from my regular jobs and problems (and keep me in shape).
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Peke wrote:BTW I do not know about you but sometimes solving some scripting problem looks like taking a nap from my regular jobs and problems (and keep me in shape).
That's exactly why I like to do this 8)

If have to program in Delphi - I believe MM is made with Delphi too., right?
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Post by Peke »

Core App yes. Other parts as I know are in MSVC and C. Plugins I've made are also in Delphi.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
wbss26
Posts: 20
Joined: Wed Jun 09, 2004 8:21 am

Getting overflow error

Post by wbss26 »

Onkel,

The code works great when I selct only a few songs but I get an overflow error when I select the 309 songs I want to list. Total time is over 14 hours.

Brian A.
Better to Burn out than to fade away....
wbss26
Posts: 20
Joined: Wed Jun 09, 2004 8:21 am

Script

Post by wbss26 »

On closer look, the total songslength is coming out with AM after it.

Help....Thanks
Better to Burn out than to fade away....
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

Ups :lol:
I will have a look at it, but maybe not until Monday. OK?
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Topic Moved

Post by psyXonova »

I have to move this post since it definetely belongs under the Scripts and Components Section.
Please pay attention where you post (wbss26) since posting under the corect section makes life easier for everyone....
Al_G
Posts: 228
Joined: Tue Aug 31, 2004 6:01 pm

Re: Topic Moved

Post by Al_G »

psyxonova wrote:I have to move this post since it definetely belongs under the Scripts and Components Section.
psyxonova,

Nothing to do with this topic; I notice that you've been added as a moderator to most groups but I must of missed the introduction. I'd like to extend my appreciation to you for taking on this role.

From a user's point of view, I hope this means the Jiri has more time to focus on MM development. Thanks again!

--
Alan
wbss26
Posts: 20
Joined: Wed Jun 09, 2004 8:21 am

Script

Post by wbss26 »

Onkel,

No problem for me to wait. Really appreciate the help.

Thanks,
Brian A.
Better to Burn out than to fade away....
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

That should work for every collection (I hope):

Code: Select all

Sub ExportHTML 
  ' initialize export 
  Call InitExport( ".htm", "HTML (*.htm)|*.htm|All files (*.*)|*.*", _ 
  "LastExportHTMLDir") 
  if fullfile="" then 
  Exit Sub 
  end if 

  ' Create the output file 
  Dim fout 
  Set fout = fso.CreateTextFile( fullfile, True) 

  ' Write header line 
  fout.WriteLine "<html>" 
  fout.WriteLine "<head><title>" & SDB.Localize("MediaMonkey Track List") & "</title>" 

  ' Code to format the document 
  fout.WriteLine "<style type=text/css>" 
  fout.WriteLine "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}" 
  fout.WriteLine "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-aligh:left}" 
  fout.WriteLine "P{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000;}" 
  fout.WriteLine "TH{font-family:'Verdana',sans-serif; font-size:10pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" 
  fout.WriteLine "TD{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}" 
  fout.Writeline "TD.dark{background-color:#EEEEEE}" 
  fout.WriteLine "</style>" 

  fout.WriteLine "</head><body>" 
  fout.WriteLine "<a href='http://www.mediamonkey.com'><h1>" & SDB.Localize("MediaMonkey Track List")&"</h1></a>" 

  ' Headers of table 
  fout.WriteLine "<table cellpadding=4 cellspacing=0>" 
  fout.WriteLine "<tr align=left>" 
  fout.WriteLine " <th id=dark>#</th>" 
  fout.WriteLine " <th>" & SDB.Localize("Artist") & "</th>" 
  fout.WriteLine " <th id=dark>" & SDB.Localize("Title") & "</th>" 
  fout.WriteLine " <th>" & SDB.Localize("Length") & "</th>" 
  fout.WriteLine " <th id=dark>" & SDB.Localize("Album") & "</th>" 
  fout.WriteLine " <th>" & SDB.Localize("Track #") & "</th>" 
  fout.WriteLine " <th id=dark>" & SDB.Localize("Year") & "</th>" 
  fout.WriteLine " <th>" & SDB.Localize("Genre") & "</th>" 
  fout.WriteLine " <th id=dark>" & SDB.Localize("Rating") & "</th>" 
  fout.WriteLine " <th>" & SDB.Localize("Bitrate") & "</th>" 
  fout.WriteLine " <th id=dark>" & SDB.Localize("Media") & "</th>" 
  fout.WriteLine "</tr>" 

  ' Use progress to notify user about the current action 
  Dim Progress 
  Set Progress = SDB.Progress 
  Progress.Text = SDB.Localize("Exporting...")

  ' Iterate through the list and export all songs 
  Progress.MaxValue = list.count 
  
  Dim SongsLength
  
  Dim i, itm 
  for i=0 to list.count-1 
    Set itm = list.Item(i) 
    Dim bitrate 
    bitrate = itm.bitrate 
    if bitrate>0 then 
      bitrate = CStr(Round( bitrate/1000)) 
    else 
      bitrate = "&nbsp;" 
    end if 
    Dim year 
    year = itm.year 
    if year<=0 then 
      year = "&nbsp;" 
    else 
      year = CStr( year) 
    end if 

    ' Add space to empty fields, so table is displayed correctly (Cell borders do not show up for empty cells) 
    Dim artistname 
    artistname = MapXML(itm.ArtistName)
    if artistname="" then 
      artistname = "&nbsp;" 
    end if 

    Dim songtitle 
    songtitle = MapXML(itm.title)
    if songtitle="" then 
      songtitle = "&nbsp;" 
    end if 

    Dim albumname 
    albumname = MapXML(itm.AlbumName)
    if albumname="" then 
      albumname = "&nbsp;" 
    end if 

    Dim songlength 
    songlength = itm.SongLengthString 
	SongsLength = SongsLength + itm.SongLength
    if songlength="" then 
      songlength = "&nbsp;" 
    end if 

    Dim songgenre 
    songgenre = MapXML(itm.Genre)
    if songgenre="" then 
      songgenre = "&nbsp;" 
    end if 

    Dim trackorder 
    trackorder = itm.TrackOrder 
    if trackorder="" then 
      trackorder = "&nbsp;" 
    elseif trackorder = "0" then 
      trackorder = "&nbsp;" 
    end if 

    ' These are added to get some decent display, all the others haven't, this script is just to demonstrate all the available options 

    Dim rating 
    Dim ratingCal
    rating = itm.Rating 
    
    Select Case rating
  Case ""
    ratingCal = "&nbsp;"
  Case -1
    ratingCal = "&nbsp;"
  Case 100
    ratingCal = 5
  Case 90
    ratingCal = 4.5
  Case 80
    ratingCal = 4
  Case 70
    ratingCal = 3.5
  Case 60
    ratingCal = 3
  Case 50
    ratingCal = 2.5
  Case 40
    ratingCal = 2
  Case 30
    ratingCal = 1.5
  Case 20
    ratingCal = 1
  Case 10
    ratingCal = 0.5
  Case 0
    ratingCal = 0
  Case Else
    ratingCal = "&nbsp;"
    End Select
  
    Dim medialabel
    medialabel = MapXML(itm.MediaLabel)
    if medialabel="" then 
      medialabel = "&nbsp;" 
    end if

    ' Body of the table 
    fout.WriteLine "<tr><td align=right class=dark>"&i+1&"</td><td>"&artistname&"</td><td class=dark>"&songtitle _ 
    &"</td><td align=right>"&songlength&"</td><td class=dark>"&albumname _ 
    &"</td><td align=right>"&trackorder&"</td><td align=right class=dark>"&Year _ 
    &"</td><td>"&songgenre&"</td><td class=Dark>"&ratingCal&"</td><td align=right>"&bitrate _ 
    &"</td><td align=right class=Dark>"&medialabel&"</td></tr>" 
    Progress.Value = i+1 
    if Progress.Terminate then 
      Exit For 
    end if 
  next 

  Dim Seconds
  Dim Mins
  Dim Hours
  Seconds = Fix(SongsLength / 1000)
  Mins = Fix(Seconds / 60)
  Seconds = Seconds mod 60
  Hours = Fix(Mins / 60)
  Mins = Mins mod 60
  
  Dim strTime
  strTime = Hours & ":" & Right("0" & Mins, 2) & ":" & Right("0" & Seconds, 2)
  
  ' Write some code to finish html document 
  fout.WriteLine "</table><p/><table width=100%><tr>"
  fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total Tracks:")&" </b>"&i&"</td>"
  fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total time:")&" </b>" & strTime & "</td>"
  fout.WriteLine "<td align=right style='border-bottom-width:0px'>Generated by <a href='http://www.mediamonkey.com'>MediaMonkey</a></td>"
  fout.WriteLine "</tr></table></body></html>"

  ' Close the output file and finish 
  fout.Close 

  ' Was it successfull? 
  Dim ok 
  if Progress.Terminate then 
    ok = False 
  else 
    ok = True 
  end if 

  ' hide progress 
  Set Progress = Nothing 

  FinishExport( ok) 
End Sub 
The Main Changes are these Lines:

Code: Select all

  songlength = itm.SongLengthString

  Dim Seconds
  Dim Mins
  Dim Hours
  Seconds = Fix(SongsLength / 1000)
  Mins = Fix(Seconds / 60)
  Seconds = Seconds mod 60
  Hours = Fix(Mins / 60)
  Mins = Mins mod 60
  
  Dim strTime
  strTime = Hours & ":" & Right("0" & Mins, 2) & ":" & Right("0" & Seconds, 2)

  fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total time:")&" </b>" & strTime & "</td>"
Post Reply