Fix Playlist Dups 4.6 - Update 08/02/2011

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

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

Fix Playlist Dups 4.6 - Update 08/02/2011

Post by trixmoto »

This script asks you to enter a playlist name. It then checks the entered playlist for duplicate tracks (using ID), removing any found (leaving the first one remaining). If you wish each removal to be confirmed you can set this confirmation in the MM options. This script can also be downloaded from my website.

Code: Select all

'
' MediaMonkey Script
'
' NAME: FixPlaylistDups 4.6
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 08/02/2011
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' FIXES: Fixed autoplaylists should be ignored
'        Fixed recursion not working properly
'
' [FixPlaylistDups]
' FileName=FixPlaylistDups.vbs
' ProcName=FixPlaylistDups
' Order=9
' DisplayName=Fix Playlist Dups
' Description=Fix Playlist Duplications
' Language=VBScript
' ScriptType=0 
'

Option Explicit

Function dup(track1,dupby,track2,cases)
  dup = False
  Select Case dupby
    Case 0
      If track1.ID = track2.ID Then 
        dup = true
      End If
    Case 1
      If cases Then
        If (track1.ArtistName = track2.ArtistName) And (track1.Title = track2.Title) Then 
          dup = true
        End If    
      Else
        If (UCase(track1.ArtistName) = UCase(track2.ArtistName)) And (UCase(track1.Title) = UCase(track2.Title)) Then 
          dup = true
        End If
      End If
    Case 2
      If (track1.LastPlayed = track2.LastPlayed) And (track1.LastPlayed <> "00:00:00") Then 
        dup = true
      End If
    Case 3
      If cases Then
        If track1.Path = track2.Path Then 
          dup = true
        End If
      Else
        If UCase(track1.Path) = UCase(track2.Path) Then 
          dup = true
        End If
      End If
    Case 4
      If cases Then
        If track1.ArtistName = track2.ArtistName Then 
          dup = true
        End If    
      Else
        If UCase(track1.ArtistName) = UCase(track2.ArtistName) Then 
          dup = true
        End If    
      End If
  End Select
End Function

Sub fixList(name,found,dupby,selname,recurse,cases)
  Dim list : Set list = SDB.PlaylistByTitle(name)
  Dim tracks : Set tracks = list.Tracks
  Dim i : i = 0
  Dim j : j = 0

  If name = selname Then 
    found = True
  End If

  If (found) And (tracks.Count > 1) Then 
    Dim progress : Set progress = SDB.Progress
    progress.MaxValue = tracks.Count 
    progress.Text = "Scanning playlist '"&name&"' for duplicates ("&tracks.Count&" tracks)"
    For i = 0 To tracks.Count-2
      For j = i+1 To tracks.Count-1
        If dup(tracks.Item(i),dupby,tracks.Item(j),cases) Then        
          Call list.RemoveTrack(tracks.Item(j))
        End If
        If progress.Terminate Then 
          Exit For
        End If
      Next    
      If progress.Terminate Then 
        Exit For
      End If
      progress.Value = i+1
    Next
    
    If progress.Terminate Then 
      Exit Sub
    End If
    Set progress = Nothing 
  End If

  If (recurse) Or (Not found) Then
    Dim children : Set children = list.ChildPlaylists
    For i = 0 To children.count-1
      Call fixList(children.Item(i).Title,found,dupby,selname,recurse,cases)
      If (found) And (Not recurse) Then
        Exit For
      End If
    Next
  End If
End Sub

Sub fixNP(dupby,cases)
  SDB.Player.Stop
  SDB.Player.CurrentSongIndex = 0

  Dim tracks : Set tracks = SDB.Player.CurrentSonglist
  Dim progress : Set progress = SDB.Progress
  Dim m : m = ","
  Dim i : i = 0
  Dim j : j = 0
 
  If tracks.Count > 1 Then 
    progress.MaxValue = tracks.Count 
    progress.Text = "Scanning Now Playing list for duplicates ("&tracks.Count&" tracks)"
    For i = 0 To tracks.Count-2
      For j = i+1 To tracks.Count-1
        If dup(tracks.Item(i),dupby,tracks.Item(j),cases) And (InStr(m,","&j&",") = 0) Then 
          m = m&j&","
        End If
        If progress.Terminate Then 
          Exit For
        End If
      Next    
      If progress.Terminate Then 
        Exit For
      End If
      progress.Value = i+1
    Next
  End If 

  If Not (progress.Terminate) Then
    If Len(m) > 1 Then
      m = Mid(m,2,Len(m)-2)     
      Dim a : a = Split(m,",")
      progress.MaxValue = UBound(a)+1
      progress.Value = 0
      progress.Text = "Removing "&(UBound(a)+1)&" tracks from Now Playing list"     
      
      Dim b : b = False
      Do
        b = True
        For i = 0 To UBound(a)-1
          If Int(a(i+1)) > Int(a(i)) Then
            b = False
            m = a(i)
            a(i) = a(i+1)
            a(i+1) = m
          End If
        Next
      Loop Until b      

      For i = 0 To UBound(a)   
        SDB.Player.PlaylistDelete(a(i))
        progress.Value = i+1
      Next
    Else
      Call SDB.MessageBox("Now Playing has no duplicates.",mtError,Array(mbOk))
    End If
  End If
End Sub

Sub FixPlaylistDups
  Dim Form : Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 350, 135
  Form.BorderStyle  = 3   ' Resizable
  Form.FormPosition = 4   ' Screen Center
  Form.Caption = "Fix Playlist Dups"

  Dim Label1 : Set Label1 = SDB.UI.NewLabel(Form)
  Label1.Caption = "Duplicates by:"
  Label1.Common.Left = 10
  Label1.Common.Top = 14
  
  Dim Drp1 : Set Drp1 = SDB.UI.NewDropdown(Form)
  Drp1.Common.Left = Label1.Common.Left + Label1.Common.Width +25
  Drp1.Common.Top = Label1.Common.Top -4
  Drp1.Common.Width = Form.Common.Width - Drp1.Common.Left -20
  Drp1.Common.ControlName = "Drop1"
  Drp1.Style = 2
  Drp1.AddItem("Track ID")
  Drp1.AddItem("Artist & Title")
  Drp1.AddItem("Last played")
  Drp1.AddItem("File path")
  Drp1.AddItem("Artist")
  Drp1.ItemIndex = SDB.IniFile.IntValue("Scripts","DupBy")  
  Drp1.UseScript = Script.ScriptPath
  Drp1.OnSelectFunc = "SelDupMode"        
  
  Dim Label2 : Set Label2 = SDB.UI.NewLabel(Form)
  Label2.Caption = "Playlist name:"
  Label2.Common.Left = 10
  Label2.Common.Top = 39  
  
  Dim Edt1 : Set Edt1 = SDB.UI.NewDropdown(Form)
  Edt1.Common.Left = Drp1.Common.Left
  Edt1.Common.Top = Label2.Common.Top -4
  Edt1.Common.Width = Form.Common.Width - Edt1.Common.Left -20
  Edt1.Common.ControlName = "Edit1"
  Edt1.Style = 2
  Edt1.AddItem("[Now Playing]")  
  Edt1.AddItem("[All]")
  Call AddPlaylists(Edt1)
  Edt1.ItemIndex = 0
  Edt1.UseScript = Script.ScriptPath
  Edt1.OnSelectFunc = "SelPlaylist"    
  
  Dim Chk2 : Set Chk2 = SDB.UI.NewCheckbox(Form)
  Chk2.Common.Left = 10
  Chk2.Common.Top = Label2.Common.Top +20
  Chk2.Common.Width = Form.Common.Width -25
  Chk2.Common.ControlName = "Chck2"
  Chk2.Caption = "Case sensitive?"
  Chk2.Checked = True
  Select Case Drp1.ItemIndex
    Case 1
      Chk2.Common.Visible = True
    Case 3
      Chk2.Common.Visible = True
    Case 4
      Chk2.Common.Visible = True      
    Case Else
      Chk2.Common.Visible = False
  End Select    
         
  Dim Chk1 : Set Chk1 = SDB.UI.NewCheckbox(Form)
  Chk1.Common.Left = 10
  Chk1.Common.Top = Chk2.Common.Top +15
  Chk1.Common.Width = Form.Common.Width -25
  Chk1.Common.ControlName = "Chck1"
  Chk1.Caption = "Include children?"
  Chk1.Checked = False
  Chk1.Common.Visible = False
    
  Dim BtnOk : Set BtnOk = SDB.UI.NewButton(Form)
  BtnOk.Caption = "&Ok"
  BtnOk.Common.Top = Edt1.Common.Top + Edt1.Common.Height +10
  BtnOk.Default = True
  BtnOk.ModalResult = 1
      
  Dim BtnCancel : Set BtnCancel = SDB.UI.NewButton(Form)
  BtnCancel.Caption = "&Cancel"
  BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width -20
  BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width -10
  BtnCancel.Common.Top = BtnOK.Common.Top
  BtnCancel.Cancel = True
  BtnCancel.ModalResult = 2
  
  If Form.ShowModal = 1 Then
    Dim dupby : dupby = Drp1.ItemIndex
    Dim cases : cases = Chk2.Checked
    SDB.IniFile.IntValue("Scripts","DupBy") = dupby
    If Edt1.Text = "[Now Playing]" Then
      Call fixNP(dupby,cases)
    Else  
      Dim found : found = False
      Dim sname : sname = Edt1.Text
      Dim recur : recur = Chk1.Checked
      If Edt1.Text = "[All]" Then
        sname = ""
        recur = True
      End If
      Call fixList("",found,dupby,sname,recur,cases)
      If Not found Then 
        Call SDB.MessageBox("Playlist entered was not found!",mtError,Array(mbOk)) 
      End If
    End If
  End If
End Sub

Sub AddPlaylists(drp)
  'find names
  Dim dic : Set dic = CreateObject("Scripting.Dictionary")
  Call AddPlaylistsRec(dic,"",True)
  'sort them
  Dim i : i = 0
  Dim a : a = dic.Keys
  Dim b : b = True
  Dim m : m = ""
  While b
    b = False
    For i = 0 To UBound(a)-1
      If a(i+1) < a(i) Then
        b = True
        m = a(i)
        a(i) = a(i+1)
        a(i+1) = m
      End If
    Next
  WEnd
  'add to list 
  For i = 0 To UBound(a)
    drp.AddItem(a(i))
  Next
End Sub

Sub AddPlaylistsRec(dic,nam,aut)
  Dim i : i = 0
  Dim list : Set list = SDB.PlaylistByTitle(nam)
  If Not (list Is Nothing) Then
    If (aut = False) And (Len(nam) > 0) Then
      dic.Item(nam) = nam
    End If
    Dim kids : Set kids = list.ChildPlaylists
    For i = 0 To kids.Count-1
      Dim itm : Set itm = kids.Item(i)
      Call AddPlaylistsRec(dic,itm.Title,itm.isAutoPlaylist)
    Next
  End If
End Sub

Sub SelPlaylist(edt)
  Dim chk : Set chk = edt.Common.TopParent.Common.ChildControl("Chck1")
  chk.Checked = False
  Select Case edt.Text
    Case "[Now Playing]"
      chk.Common.Visible = False
    Case "[All]"
      chk.Common.Visible = False
    Case Else
      If SDB.PlaylistByTitle(edt.Text).ChildPlaylists.Count = 0 Then
        chk.Common.Visible = False
      Else
        chk.Common.Visible = True
      End If  
  End Select
End Sub

Sub SelDupMode(drp)
  Dim chk : Set chk = drp.Common.TopParent.Common.ChildControl("Chck2")
  Select Case drp.ItemIndex
    Case 1
      chk.Common.Visible = True
    Case 3
      chk.Common.Visible = True
    Case 4
      chk.Common.Visible = True      
    Case Else
      chk.Common.Visible = False
  End Select
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("FixPlaylistDups","Filename") = "FixPlaylistDups.vbs"
    inif.StringValue("FixPlaylistDups","Procname") = "FixPlaylistDups"
    inif.StringValue("FixPlaylistDups","Order") = "9"
    inif.StringValue("FixPlaylistDups","DisplayName") = "Fix Playlist Dups"
    inif.StringValue("FixPlaylistDups","Description") = "Fix Playlist Duplications"
    inif.StringValue("FixPlaylistDups","Language") = "VBScript"
    inif.StringValue("FixPlaylistDups","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Wed Jun 06, 2007 4:41 pm, edited 5 times in total.
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.
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy »

explain to me please?

1.

will this find only dup's by the same artist.


2.

will it remove only the older version of the song if there really is two of them in the computer.

3.

or is this the fix for the double and sometimes triple listings of the songs in the playlist's, that seem to be happing in the latest released version and in the alpha test versions?

thanks 8)
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

This checks the track ID and if there are more than one track with the same ID in a playlist then it will remove all after the first. For example (don't know what track IDs actually look like but that's not the point):

TrackID01
TrackID02
TrackID99
TrackID02 <-- This one will be removed
TrackID98
TrackID02 <-- This one will be removed
TrackID97

They are removed depending on your MM settings, the default is to confirm the deletion, the default deletion option being "from playlist only".

Clear?
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.
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy »

so it seems to be the answer to match my number 3 in the above post of mine.

okay. just wanted to make sure it was clear for everyone including me 8)
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Yes, it matches number 3. I meant to say that but reading back I can see that I didn't. Sorry! :)
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.
judas
Posts: 572
Joined: Thu Jun 02, 2005 11:26 pm
Location: Bogotá, Colombia

Post by judas »

3.
or is this the fix for the double and sometimes triple listings of the songs in the playlist's, that seem to be happing in the latest released version and in the alpha test versions?
Yes, it matches number 3. I meant to say that but reading back I can see that I didn't. Sorry!
Are you sure??? im desperate with all the duplicates on my library..so i was really needing this...I executed the script over Accessible tracks and it didnt work...maybe its only for tracks you manually add twice and not for the duplicates, triplicates, and moreplicates that many of us are getting lately?

Perhaps Im doing something wrong [again] ??

cheers....

Judas[/quote]
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

At this moment it checks a single playlist for duplicate track ids (each track added to the library having a unique id). Once I have played with beta1 and established what duplicate warnings this has, I will redesign the script. Current ideas:

- Use currently selected playlist (rather than typing in name)
- Optionally recurse through child playlists
- Use Artist and Title to find duplicate

Any other ideas?
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.
judas
Posts: 572
Joined: Thu Jun 02, 2005 11:26 pm
Location: Bogotá, Colombia

Post by judas »

I still cant get it to remove duplicates...its a problem that have been discused before and no solution has been provided (yet)

heres a screenshot so you see what i mean:

Image


when i select one of the files that have duplicates it plays them all...when checking the details...they're all exactly the same...still, the script doesnt removes the duplicates (cause i didn't add the song more than once to the playlist...they duplicated by themselves!!!!)

Edited: Forgot to link to the screenshoy
Last edited by judas on Mon Nov 14, 2005 12:17 pm, edited 1 time in total.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I can't see your screenshot, and as I can't work out what you're doing, this really would be uesful.

Maybe these tracks do not have the same ID? Are you sure the track is not entered into the database several times?

Are you typing the correct playlist name on running the script? (This script currenly doesn't check the NowPlaying list (as far as I know!))
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.
judas
Posts: 572
Joined: Thu Jun 02, 2005 11:26 pm
Location: Bogotá, Colombia

Post by judas »

trixmoto wrote:I can't see your screenshot, and as I can't work out what you're doing, this really would be uesful.
There ya go...sorry i forgot!!! Fixed!!!!

Maybe these tracks do not have the same ID? Are you sure the track is not entered into the database several times?
Maybe it is entered in the database several times..idont know...its a known bug in mediamonkey and no solution has been found (yet)...i began getting the same file many times...but its the same file cause, as you can see in the screen shot above when I play a file it treats all the instances as one and so thy're all blacked. I think this is what rovingcowboy meant in his 3rd question in the second post of this topic.
Are you typing the correct playlist name on running the script? (This script currenly doesn't check the NowPlaying list (as far as I know!))
yes...i pretty sure im writing the correct name...i tested on a playlist i made for this purposed called...well...test. i can confirm the script works when i manually add to instances of the file, but does not remove the aforementioned duplicates caused by the MM bug.
judas
Posts: 572
Joined: Thu Jun 02, 2005 11:26 pm
Location: Bogotá, Colombia

Post by judas »

trixmoto wrote:I can't see your screenshot, and as I can't work out what you're doing, this really would be uesful.
There ya go...sorry i forgot!!! Fixed!!!!

Maybe these tracks do not have the same ID? Are you sure the track is not entered into the database several times?
Maybe it is entered in the database several times..idont know...its a known bug in mediamonkey and no solution has been found (yet)...i began getting the same file many times...but its the same file cause, as you can see in the screen shot above when I play a file it treats all the instances as one and so thy're all blacked. I think this is what rovingcowboy meant in his 3rd question in the second post of this topic.
Are you typing the correct playlist name on running the script? (This script currenly doesn't check the NowPlaying list (as far as I know!))
yes...i pretty sure im writing the correct name...i tested on a playlist i made for this purposed called...well...test. i can confirm the script works when i manually add to instances of the file, but does not remove the aforementioned duplicates caused by the MM bug.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I am currently working on Version 2.0 which will allow you to remove duplicates by fields matching rather than ID, so this should fix your problem.
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.
judas
Posts: 572
Joined: Thu Jun 02, 2005 11:26 pm
Location: Bogotá, Colombia

Post by judas »

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

Post by trixmoto »

This new version (2.0) allows the user to select how they want duplicates detected (track ID, artist & title, last played or file path). It also starts with the selected playlist (after confirmation) and allows the option of automatically recursing through child playlists.

:D 8) NEW CODE BELOW 8) :D
Last edited by trixmoto on Wed Nov 16, 2005 11:38 am, edited 1 time in total.
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.
judas
Posts: 572
Joined: Thu Jun 02, 2005 11:26 pm
Location: Bogotá, Colombia

Post by judas »

will test right away
Post Reply