Page 1 of 3

Find Protected 1.0 [MM2+3]

Posted: Thu Nov 29, 2007 7:47 am
by trixmoto
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! :)

Code: Select all

' MediaMonkey Script
' NAME: FindProtected 1.0
' AUTHOR: trixmoto (
' 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))
    '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))
    'finish off
  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
  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.Text = "FindProtected: Checking track "&prog.Value&"/"&prog.MaxValue&" (found: "&list.Count&")..."
    '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
        End If    
      End If
    End If
    'check next track
    If prog.Terminate Then 
      Exit Sub
    End If
  '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"
  End If
  Call onStartUp()
End Sub

Posted: Sun Dec 02, 2007 3:54 am
by Guest
Great Idea and thanks for a script.
I have an issue: after installing and clicking on create report option I am getting error message: FindProtected: Cannot find protected column!
It this meant I dont have protected mp3's or theres an error with the script?

Best regards,

Posted: Sun Dec 02, 2007 4:15 am
by Guest
Just want to add I have Vista 64 and it seems other scripts have also problem with working properly. Its something with admin rights or something in vista64.
I am running mediamonkey as an admin.
best regards,

Posted: Sun Dec 02, 2007 6:41 pm
by trixmoto
Strange, I've tested this on Vista and it worked for me. It means that it cannot work out where in the file the protected header is. I've seen it be different values on different operating systems, but I've not seen it not there. Although maybe it could be a language thing - is your Vista using a language other than english?

Posted: Mon Dec 17, 2007 9:46 pm
by gapcnet
A really DUMB question .... I used your auto-installer. Now how do I make us if it?



Posted: Tue Dec 18, 2007 4:01 am
by trixmoto
File > Create Report > Find Sync Dups

Posted: Tue Jan 15, 2008 8:42 pm
by Killjoy12
I love this script, but it only works for me the first time after install.

The installation script does not put it in the Scripts\Auto folder. Could this be the issue I am seeing?


Posted: Wed Jan 16, 2008 6:45 am
by trixmoto
Yes, you are right, sorry! I have rebuilt the installer so if you download it again it should work. :)

Posted: Wed Jan 16, 2008 10:29 am
by Killjoy12
Awesome! Thanks

Weird Error

Posted: Sat Feb 23, 2008 2:00 pm
by martialartsguy
Getting the following error after downloading and running:


Posted: Sun Feb 24, 2008 10:06 am
by trixmoto
Does the file exist where the message says it should? If no then the installation must have failed, if yes then something (maybe an anti virus program) must be blocking the script from running.

Posted: Sun Feb 24, 2008 1:25 pm
by martialartsguy

Looks like the installation failed. I moved the file to the proper place and all is well.

Posted: Mon Feb 25, 2008 3:42 pm
by Guest
also got the "FindProtected: Cannot find protected column!" problem...
but i work with a german version of winxp on my pc

Posted: Tue Feb 26, 2008 4:03 am
by trixmoto
In this case you might need to change line 77 which is...

Code: Select all

If fol.GetDetailsOf(fol.Items,i) = "Protected" Then
I'm not sure what this column would be called in German, but translating it should fix the problem.

Posted: Fri Mar 07, 2008 8:05 am
by nabuhonodozor
Hi Trix, first of all thanks for great contributions!
As for find protected - I also have same error.
Changing line 77 didnt solve it. Ive change it to actually reflect a nod-name , an autoinstaller created during installation. New node is: Library/Files to Edit/Find Protected. So Ive change line 77 of vbs script from "Protected" to "Find Protected" but issue persists.
I have polish vista64 and english MM runs with administrator rights.
Best regards,