Thank you Trixmoto.
I upgraded to MM 3.0 this week and this script from 1.2.
Great job, I noticed that you have implemented Compilation albums.
details for Single vs Various Artists albums.
The title don't need to be different since AlbumArtist and AlbumName are the same.
field that can be added in the album mask. Now it's exactly what I need. Let me know what you think of it.
Code: Select all
'
' MediaMonkey Script
'
' NAME: JustListAlbums 1.5 - Modified by Eyal on June 22, 2008.
' Nouvelle version (j'avais 1.2) compatible avec MM3 modifié le 22 juin 2008.
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 25/05/2008
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' NOTE: Mask variable can include fields: <Artist><Album><Year><Rating><Length><Tot><Max><Discs><AvgBitrate>
' TrackMask and CompMask variables can include:
' <Track#><Artist><Title><Album><Album Artist><Genre><Year><Bitrate><BPM><Composer>
' <Custom 1><Custom 2><Custom 3><Filename><Length><Rating><Custom 4><Custom 5><Disc#><Comment>
'
' [JustListAlbums]
' FileName=JustListAlbums.vbs
' ProcName=JustListAlbums
' Order=1
' DisplayName=Just List Albums
' Description=Just List Albums
' Language=VBScript
' ScriptType=1
'
' FIXES: Fixed TrackMask should be blank by default
' Fixed compatibility with MM2
'
Option Explicit
Dim Mask : Mask = "<Artist> - <Album> (<Year>)"+vbCrLf+"<Tot> tracks, [<Length>] ~<AvgBitrate>"+vbCrLf + String(60,"-")
Dim TrackMask : TrackMask = "<Track#>. <Title> [<Length>]" '(*) blank mask means no tracks are displayed
Dim CompMask : CompMask = "<Track#>. <Artist> / <Title> [<Length>]" 'mask for compilation albums
Dim FirstMask : FirstMask = "" 'mask for first track in an album
Dim Comp 'Déplacé en public par Eyal
Sub JustListAlbums
Dim list : Set list = SDB.CurrentSongList
If list.Count = 0 Then
Call SDB.MessageBox( SDB.Localize("Please select tracks to be exported."), mtError, Array(mbOk))
Exit Sub
End If
If SDB.VersionHi < 3 Then
Set list = list.Albums
End If
Dim fso : Set fso = SDB.Tools.FileSystem
Dim path : path = Script.ScriptPath&".txt"
Dim fout : Set fout = fso.CreateTextFile(path,True)
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
Dim Progress : Set Progress = SDB.Progress
Progress.MaxValue = list.Count
Progress.Text = SDB.Localize("Exporting...")
' Iterate through the list and export all songs
Dim i,itm,iter,str,theyear,rating,length,tot,max,discs,sql,alb,art,itmID,avgbitrate 'avgbitrate ajouté par Eyal
For i = 0 To list.Count-1
Set itm = list.Item(i)
If SDB.VersionHi > 2 Then
itmID = itm.Album.ID
If dic.Exists("#"&itmID) Then
itmID = 0
Else
dic.Item("#"&itmID) = itm.AlbumName
End If
Else
itmID = itm.ID
End If
If itmID > 0 Then
'calculate field values
If SDB.VersionHi > 2 Then
'Ajouté Avg(Bitrate) dans les 2 cas:
sql = "SELECT Max(CAST(TrackNumber AS INTEGER)) AS vMax, Count(*) AS vTot, Sum(SongLength) AS vLen, " + _
"Avg(Year/10000) AS vYea, Avg(Rating) AS vRat, Avg(Bitrate) As vBit, " + _
"Max(CAST(DiscNumber AS INTEGER)) AS vDis, Count(DISTINCT CASE WHEN INSTR(Artist,';')>0 THEN " + _
"SUBSTR(Artist,1,INSTR(Artist,';')-1) WHEN INSTR(Artist,';')=0 THEN Artist END) AS vArt " + _
"FROM Songs WHERE IDAlbum="&itmID
Else
sql = "SELECT Max(SongOrder) AS vMax, Count(*) AS vTot, Sum(SongLength) AS vLen, Avg(Year) AS vYea, " + _
"Avg(Rating) AS vRat, Avg(Bitrate) As vBit FROM Songs WHERE IDAlbum="&itmID
End If
Set iter = SDB.Database.OpenSQL(sql)
theyear = getval(iter,"vYea")
If theyear = "0" Then
theyear = "????"
End If
rating = getval(iter,"vRat")/20
length = gettime(getval(iter,"vLen")/1000)
tot = getval(iter,"vTot")
max = getval(iter,"vMax")
avgbitrate = Int(iter.ValueByName("vBit") / 1000) & " Kbps" 'Ajouté par Eyal
If SDB.VersionHi > 2 Then
art = itm.AlbumArtistName
alb = itm.AlbumName
Else
art = itm.Artist.Name
alb = itm.Name
End If
comp = False
If SDB.VersionHi > 2 Then
discs = getval(iter,"vDis")
If discs = 0 Then
discs = 1
End If
If getval(iter,"vArt") > 1 Then
comp = True 'Album Various Artists
End If
Else
max = max+1
discs = 1
End If
'build string from mask
Str = Mask
str = Replace(str,"<Artist>",SDB.toAscii(art))
str = Replace(str,"<Album>",SDB.toAscii(alb))
str = Replace(str,"<Year>",theyear)
str = Replace(str,"<Rating>",rating)
str = Replace(str,"<Length>",length)
str = Replace(str,"<Tot>",tot)
str = Replace(str,"<Max>",max)
str = Replace(str,"<Discs>",discs)
Str = Replace(Str,"<AvgBitrate>",avgbitrate) 'Ajouté par Eyal
fout.WriteLine str
'display album tracks
If Not (TrackMask = "") Then
If SDB.VersionHi > 2 Then
str = "AND (Songs.IDAlbum="&itmID&") ORDER BY CAST(Songs.DiscNumber AS INTEGER), " + _
"CAST(Songs.TrackNumber AS INTEGER)"
Else
str = "AND (Songs.IDAlbum="&itmID&") ORDER BY Songs.SongOrder"
End If
Dim j : j = 0
Set iter = SDB.Database.QuerySongs(str)
Do While Not iter.EOF
j = j + 1
Call fout.WriteLine(gettrack(iter.Item,j))
iter.Next
If Progress.Terminate Then
Exit Do
End If
Loop
Call fout.WriteLine("")
End If
End If
Progress.Increase
SDB.ProcessMessages
If Progress.Terminate Then
Exit For
End If
Next
fout.Close
If Not Progress.Terminate Then
Dim WShell : Set WShell = CreateObject("WScript.Shell")
i = WShell.Run(Chr(34)&path&Chr(34),1,0)
End If
End Sub
Function gettime(sec)
Dim min : min = 0
sec = Int(sec)
Do While sec > 59
sec = sec - 60
min = min + 1
Loop
If sec < 10 Then
gettime = min&":0"&sec
Else
gettime = min&":"&sec
End If
End Function
Function getval(iter,nam)
Dim s : s = iter.StringByName(nam)
If IsNumeric(s) Then
getval = s*1
Else
getval = 0
End If
End Function
Function gettrack(itm,i)
Dim temp,track,title,artist,album,albumartist,genre,theyear
Dim bitrate,bpm,composer,cust1,cust2,cust3,cust4,cust5,path,length,rating,disc,comment
track = CStr(itm.TrackOrder)
title = SDB.toAscii(itm.Title)
artist = SDB.toAscii(itm.ArtistName)
album = SDB.toAscii(itm.AlbumName)
albumartist = SDB.toAscii(itm.AlbumArtistName)
genre = SDB.toAscii(itm.Genre)
theyear = itm.Year
bitrate = Int(itm.Bitrate/1000) &" Kbps"
bpm = itm.BPM
composer = SDB.toAscii(itm.Author)
cust1 = SDB.toAscii(itm.Custom1)
cust2 = SDB.toAscii(itm.Custom2)
cust3 = SDB.toAscii(itm.Custom3)
path = SDB.toAscii(itm.Path)
length = gettime(itm.SongLength/1000)
temp = itm.Rating
If temp < 0 Then
rating = "?"
Else
temp = temp / 20
If temp = Int(temp) Then
rating = temp
Else
rating = FormatNumber(temp,1)
End If
End If
If SDB.VersionHi > 2 Then
theyear = Left(itm.Year,4)
disc = itm.DiscNumberStr
track = itm.TrackOrderStr
cust4 = SDB.toAscii(itm.Custom4)
cust5 = SDB.toAscii(itm.Custom5)
Else
disc = "1"
End If
Do While Len(track)<2
track = "0"&track
Loop
If theyear = "0" Then
theyear = "????"
End If
comment = itm.Comment
If (i = 1) And Not (FirstMask = "") Then
gettrack = FirstMask
Else
If Comp Then
gettrack= CompMask
Else
gettrack = TrackMask
End If
End If
gettrack = Replace(gettrack,"<Track#>",track)
gettrack = Replace(gettrack,"<Artist>",artist)
gettrack = Replace(gettrack,"<Title>",title)
gettrack = Replace(gettrack,"<Album>",album)
gettrack = Replace(gettrack,"<Album Artist>",albumartist)
gettrack = Replace(gettrack,"<Genre>",genre)
gettrack = Replace(gettrack,"<Year>",theyear)
gettrack = Replace(gettrack,"<Bitrate>",bitrate)
gettrack = Replace(gettrack,"<BPM>",bpm)
gettrack = Replace(gettrack,"<Composer>",composer)
gettrack = Replace(gettrack,"<Custom 1>",cust1)
gettrack = Replace(gettrack,"<Custom 2>",cust2)
gettrack = Replace(gettrack,"<Custom 3>",cust3)
gettrack = Replace(gettrack,"<Filename>",path)
gettrack = Replace(gettrack,"<Length>",length)
gettrack = Replace(gettrack,"<Rating>",rating)
If SDB.VersionHi > 2 Then
gettrack = Replace(gettrack,"<Custom 4>",cust4)
gettrack = Replace(gettrack,"<Custom 5>",cust5)
gettrack = Replace(gettrack,"<Disc#>",disc)
End If
gettrack = Replace(gettrack,"<Comment>",comment)
End Function
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("JustListAlbums","Filename") = "JustListAlbums.vbs"
inif.StringValue("JustListAlbums","Procname") = "JustListAlbums"
inif.StringValue("JustListAlbums","Order") = "1"
inif.StringValue("JustListAlbums","DisplayName") = "Just List Albums"
inif.StringValue("JustListAlbums","Description") = "Just List Albums"
inif.StringValue("JustListAlbums","Language") = "VBScript"
inif.StringValue("JustListAlbums","ScriptType") = "1"
SDB.RefreshScriptItems
End If
End Sub