Find Protected 1.0 [MM2+3]
Posted: Thu Nov 29, 2007 7:47 am
This script, as requested here, runs through the entire library finding tracks which are protected with DRM. Like a few of my scripts, there is a report to run which populates the node in the background, then you can click on the node to few the results.
The installers are available to download from my website, as always!
The installers are available to download from my website, as always!
Code: Select all
'
' MediaMonkey Script
'
' NAME: FindProtected 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 29/11/2007
'
' INSTALL: Copy to Scripts\Auto directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately'
'
' [FindProtected]
' FileName=Auto\FindProtected.vbs
' ProcName=FindProtected
' Order=10
' DisplayName=Find Protected
' Description=Populates Find Protected node
' Language=VBScript
' ScriptType=1
'
Option Explicit
Sub onStartUp
'create node and add to tree
Dim node : Set node = SDB.Objects("FindProtectedNode")
If node Is Nothing Then
Dim tree : Set tree = SDB.MainTree
Set node = tree.CreateNode
node.Caption = "Find Protected"
node.IconIndex = 32
node.UseScript = Script.ScriptPath
node.OnFillTracksFunct = "ShowProtected"
node.SortCriteria = 2
tree.AddNode tree.Node_FilestoEdit,node,3
Set SDB.Objects("FindProtectedNode") = node
End If
End Sub
Sub ShowProtected(node)
'check for list
Dim list : Set list = SDB.Objects("FindProtectedList")
If list Is Nothing Then
'warn node not yet populated
Call SDB.MessageBox("FindProtected: You need to select 'File|Create Reports|Find Protected' from the menu before this node will be populated.",mtInformation,Array(mbOk))
Else
'add list to main window
Dim trax : Set trax = SDB.MainTracksWindow
Dim i : i = 0
For i = 0 To list.Count-1
Call trax.AddTrack(list.Item(i))
SDB.ProcessMessages
Next
'finish off
trax.FinishAdding
End If
End Sub
Sub FindProtected
'reset list
Set SDB.Objects("FindProtectedList") = Nothing
Dim list : Set list = SDB.NewSongList
Dim fso : Set fso = SDB.Tools.FileSystem
'create progress bar
Dim prog : Set prog = SDB.Progress
prog.Value = 0
Dim iter : Set iter = SDB.Database.OpenSQL("SELECT Count(1) AS SongCount FROM Songs")
prog.MaxValue = iter.ValueByName("SongCount")
prog.Text = "FindProtected: Initialising..."
'get protected column
Dim app : Set app = CreateObject("Shell.Application")
Dim fol : Set fol = app.Namespace(SDB.ApplicationPath)
Dim i : i = 0
For i = 0 To 34
If fol.GetDetailsOf(fol.Items,i) = "Protected" Then
Exit For
End If
Next
If i = 35 Then
Call SDB.MessageBox("FindProtected: Cannot find protected column!",mtError,Array(mbOk))
Exit Sub
End If
'loop through tracks
Set fol = Nothing
Dim loc : loc = ""
Set iter = SDB.Database.QuerySongs("")
Do While Not iter.EOF
'update progress bar
prog.Increase
prog.Text = "FindProtected: Checking track "&prog.Value&"/"&prog.MaxValue&" (found: "&list.Count&")..."
SDB.ProcessMessages
'check details
Dim pat : pat = iter.Item.Path
Dim pos : pos = InStrRev(pat,"\")
If Not (loc = Left(pat,pos-1)) Then
loc = Left(pat,pos-1)
Set fol = app.Namespace(loc)
End If
If Not (fol Is Nothing) Then
Dim fil : Set fil = fol.ParseName(Mid(pat,pos+1))
If Not (fil Is Nothing) Then
If fol.GetDetailsOf(fil,i) = "Yes" Then
list.Add(iter.Item)
End If
End If
End If
'check next track
If prog.Terminate Then
Exit Sub
Else
iter.Next
End If
Loop
'finish off
Set SDB.Objects("FindProtectedList") = list
If list.Count = 0 Then
Call SDB.MessageBox("FindProtected: You have no protected files!",mtInformation,Array(mbOk))
Exit Sub
End If
'show results
i = SDB.MessageBox("FindProtected: Do you want to see the "&list.Count&" results now?",mtConfirmation,Array(mbYes,mbNo))
If i = mrYes Then
Dim tree : Set tree = SDB.MainTree
Dim node : Set node = SDB.Objects("FindProtectedNode")
tree.CurrentNode = tree.Node_Library
tree.Node_Library.Expanded = True
tree.CurrentNode = tree.Node_FilestoEdit
tree.Node_FilestoEdit.Expanded = True
tree.CurrentNode = node
End If
End Sub
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("FindProtected","Filename") = "FindProtected.vbs"
inif.StringValue("FindProtected","Procname") = "FindProtected"
inif.StringValue("FindProtected","Order") = "10"
inif.StringValue("FindProtected","DisplayName") = "Find Protected"
inif.StringValue("FindProtected","Description") = "Populates Find Protected node"
inif.StringValue("FindProtected","Language") = "VBScript"
inif.StringValue("FindProtected","ScriptType") = "1"
SDB.RefreshScriptItems
End If
Call onStartUp()
End Sub