Location Report 1.2 [MM2]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Location Report 1.2 [MM2]

Post by trixmoto » Mon Jun 04, 2007 9:38 am

This is a custom script designed by Hank. It lists all the tracks within the selected folder and subfolders. First click on the Location or My Computer node of the folder and then click "File, Create Report, Location Report". An HTML file will be created containing the list.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Mon Jun 04, 2007 9:39 am

Code: Select all

'
' MediaMonkey Script
'
' NAME: LocationReport 1.2
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 04/06/2007
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately 
'
' FIXES: Added stylesheet to align headers left
'        Added folder name to empty rows
'        Added track numbers to the first column
'
' [LocationReport]
' FileName=LocationReport.vbs
' ProcName=LocationReport
' Order=100
' DisplayName=&Location Report
' Description=Location Report
' Language=VBScript
' ScriptType=1 
'

Option Explicit

Sub LocationReport
  'get location
  Dim cur : Set cur = SDB.MainTree.CurrentNode
  If cur Is Nothing Then
    Call SDB.MessageBox("LocationReport: No node is selected.",mtError,Array(mbOk))
    Exit Sub
  End If
  
  'check location
  Dim loc : loc = ""
  Select Case cur.NodeType
    Case 64
      loc = SDB.MainTree.CurrentNode.Path&"%"
    Case 62
      loc = Mid(SDB.MainTree.CurrentNode.Path,2)&"%"
    Case Else
      Call SDB.MessageBox("LocationReport: Selected node is ("&cur.NodeType&") not a suitable type.",mtError,Array(mbOk))
      Exit Sub
  End Select
  
  'count tracks  
  Dim dit : Set dit = SDB.Database.OpenSQL("SELECT Count(1) FROM Songs WHERE Songs.SongPath LIKE '"&loc&"'")  
  If dit.ValueByIndex(0) = 0 Then
    Call SDB.MessageBox("LocationReport: Selected node contains no tracks.",mtError,Array(mbOk))
    Exit Sub
  End If  
   
  'select path
  Dim dlg : Set dlg = SDB.CommonDialog
  dlg.DefaultExt = ".htm"
  dlg.Filter = "Report (*.htm)|*.htm"
  dlg.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly + cdlOFNNoChangeDir
  dlg.InitDir = SDB.IniFile.StringValue("Scripts","LocationReportFile")
  dlg.ShowSave
  If (dlg.Ok = False) Or (dlg.FileName = "") Then 
    Exit Sub
  End If
  SDB.IniFile.StringValue("Scripts","LocationReportFile") = dlg.FileName
  
  'create report
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim htm : Set htm = fso.CreateTextFile(dlg.FileName,True)
  htm.WriteLine "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"
  htm.WriteLine "<html><head><title>Location Report</title><link rel=Stylesheet href='report.css' type='text/css'></head><body>" 
  htm.WriteLine "<h1>Location Report</h1><table width=100%><tr><th>Folder Name</th><th>Artist Name</th><th>Track Name</th><th>Time</th></tr>"    
  
  'get tracks
  Dim dic : Set dic = CreateObject("Scripting.Dictionary")
  Dim tmp : tmp = ""
  Set dit = SDB.Database.OpenSQL("SELECT Songs.ID,Songs.SongPath,Artists.Artist,Songs.SongTitle,Songs.SongLength FROM Songs LEFT JOIN Artists ON Songs.IDArtist = Artists.ID WHERE Songs.SongPath LIKE '"&loc&"' ORDER BY Artists.Artist")
  While (Not dit.EOF)
    tmp = Left(dit.StringByIndex(1),InStrRev(dit.StringByIndex(1),"\"))
    tmp = Left(tmp,Len(tmp)-1)
    loc = "<tr><td>##</td><td>"&dit.StringByIndex(2)&"</td><td>"&dit.StringByIndex(3)&"</td><td>"&gettime(dit.ValueByIndex(4)/1000)&"</td></tr>"
    If dic.Exists(tmp) Then
      dic.Item(tmp) = dic.Item(tmp)&loc
    Else
      dic.Item(tmp) = loc
    End If
    dit.Next
  WEnd
  
  'sort folders
  Dim arr : arr = dic.Keys
  Dim i : i = 0
  Dim b : b = False
  Do
    b = True
    For i = 0 To UBound(arr)-1
      If arr(i+1) < arr(i) Then
        b = False
        tmp = arr(i)
        arr(i) = arr(i+1)
        arr(i+1) = tmp
      End If
    Next
  Loop Until b   
  
  'write report
  For i = 0 To UBound(arr)
    tmp = Mid(arr(i),InStrRev(arr(i),"\")+1)
    Dim j : j = 0
    loc = dic(arr(i))
    While InStr(loc,"##") > 0 
      j = j + 1
      loc = Replace(loc,"##",lead2(j),1,1)
    WEnd
    htm.WriteLine "<tr><td colspan=4>"&tmp&"</td></tr>"&loc
  Next
  htm.WriteLine "</table><p>Created using 'Location Report' script by <a href='http://trixmoto.net'>Trixmoto</a>.</p></body></html>"
  htm.Close
  
  'show report
  If SDB.MessageBox("LocationReport: Report complete, display now?",mtConfirmation,Array(mbYes,mbNo)) = mrYes Then
    Dim wsh : Set wsh = CreateObject("WScript.Shell")
    Call wsh.Run(Chr(34)&dlg.FileName&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 lead2(num)
  If num < 10 Then
    lead2 = "0"&num
  Else
    lead2 = ""&num
  End If
End Function
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Vyper
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Post by Vyper » Mon Jun 04, 2007 11:18 am

Image
Stop Button Freak

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

Post by onkel_enno » Mon Jun 04, 2007 11:39 pm

And what it's good for? Can't I do the same with the Songlist-Report?
SansaMonkey - for SanDisk Sansa and Rockbox Users

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

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Tue Jun 05, 2007 4:57 am

"SongList Report"?

It lists all of the tracks in a certain folder and it's subfolders, so I guess it primarily depends on your file structure. :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Post Reply