Page 1 of 2
Need help with report script...
Posted: Wed Aug 24, 2005 4:24 pm
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.
Posted: Thu Aug 25, 2005 1:18 am
by onkel_enno
Posted: Thu Aug 25, 2005 3:25 am
by rk
Hey onkel_enno,
is there any kind of script you not have already written or somehow at hand?
Quite impressive!
Posted: Thu Aug 25, 2005 3:39 am
by onkel_enno
Thx
I'm programming the whole day and so it's quite easy for me to solve such easy things quickly for my MM-Friends

Script
Posted: Thu Aug 25, 2005 11:22 am
by wbss26
Onkel,
This is great. Thank you very much.
Brian A.
Posted: Thu Aug 25, 2005 4:37 pm
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).
Posted: Fri Aug 26, 2005 12:44 am
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
If have to program in Delphi - I believe MM is made with Delphi too., right?
Posted: Fri Aug 26, 2005 5:21 am
by Peke
Core App yes. Other parts as I know are in MSVC and C. Plugins I've made are also in Delphi.
Getting overflow error
Posted: Fri Aug 26, 2005 4:52 pm
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.
Script
Posted: Fri Aug 26, 2005 4:58 pm
by wbss26
On closer look, the total songslength is coming out with AM after it.
Help....Thanks
Posted: Sat Aug 27, 2005 4:29 am
by onkel_enno
Ups
I will have a look at it, but maybe not until Monday. OK?
Topic Moved
Posted: Sat Aug 27, 2005 4:58 am
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....
Re: Topic Moved
Posted: Sun Aug 28, 2005 12:05 am
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
Script
Posted: Sun Aug 28, 2005 9:00 am
by wbss26
Onkel,
No problem for me to wait. Really appreciate the help.
Thanks,
Brian A.
Posted: Mon Aug 29, 2005 1:06 am
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 = " "
end if
Dim year
year = itm.year
if year<=0 then
year = " "
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 = " "
end if
Dim songtitle
songtitle = MapXML(itm.title)
if songtitle="" then
songtitle = " "
end if
Dim albumname
albumname = MapXML(itm.AlbumName)
if albumname="" then
albumname = " "
end if
Dim songlength
songlength = itm.SongLengthString
SongsLength = SongsLength + itm.SongLength
if songlength="" then
songlength = " "
end if
Dim songgenre
songgenre = MapXML(itm.Genre)
if songgenre="" then
songgenre = " "
end if
Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = " "
elseif trackorder = "0" then
trackorder = " "
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 = " "
Case -1
ratingCal = " "
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 = " "
End Select
Dim medialabel
medialabel = MapXML(itm.MediaLabel)
if medialabel="" then
medialabel = " "
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>"