Need help with report script...

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

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

Need help with report script...

Post by wbss26 » Wed Aug 24, 2005 4:24 pm

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: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Thu Aug 25, 2005 1:18 am

Code: Select all

... see below ...
Last edited by onkel_enno on Mon Aug 29, 2005 1:07 am, edited 1 time in total.
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

rk
Posts: 104
Joined: Mon Jul 25, 2005 2:18 am
Location: Germany

Post by rk » Thu Aug 25, 2005 3:25 am

Hey onkel_enno,
is there any kind of script you not have already written or somehow at hand? :wink:
Quite impressive!

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Thu Aug 25, 2005 3:39 am

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:
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

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

Script

Post by wbss26 » Thu Aug 25, 2005 11:22 am

Onkel,

This is great. Thank you very much.

Brian A.
Better to Burn out than to fade away....

Peke
Posts: 10943
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Post by Peke » Thu Aug 25, 2005 4:37 pm

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,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
How to add Images to forum

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Fri Aug 26, 2005 12:44 am

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?
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Peke
Posts: 10943
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Post by Peke » Fri Aug 26, 2005 5:21 am

Core App yes. Other parts as I know are in MSVC and C. Plugins I've made are also in Delphi.
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
How to add Images to forum

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

Getting overflow error

Post by wbss26 » Fri Aug 26, 2005 4:52 pm

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 » Fri Aug 26, 2005 4:58 pm

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: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Sat Aug 27, 2005 4:29 am

Ups :lol:
I will have a look at it, but maybe not until Monday. OK?
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Topic Moved

Post by psyXonova » Sat Aug 27, 2005 4:58 am

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: 227
Joined: Tue Aug 31, 2004 6:01 pm

Re: Topic Moved

Post by Al_G » Sun Aug 28, 2005 12:05 am

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 » Sun Aug 28, 2005 9:00 am

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: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Mon Aug 29, 2005 1:06 am

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>"
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Post Reply