Fix Playlist Dups 4.6 - Update 08/02/2011

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:

Post by trixmoto » Tue Nov 15, 2005 11:01 am

I'm actually working on a few changes already, but they are not functional changes, just tidying code and adding some messaging. Please let me know what you think. Are there any other types of duplicate you might want to check for?
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 » Tue Nov 15, 2005 11:11 am

First Look: A bit slow and recurse-intensive, but doing what I wanted it to....im REALLY REALLY happy at the moment. will keep playing for a while with it and post again soon. great work trix...and thanks a lot!!!!!

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

Post by trixmoto » Wed Nov 16, 2005 11:39 am

Latest version (3.0) allows the user to specify default duplicate detection type, warns if the playlist is not found, and also allows you to check the Now Playing list!

:D :o :roll: NEW CODE BELOW :roll: :o :D
Last edited by trixmoto on Mon Dec 05, 2005 6:19 pm, 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 » Sun Nov 20, 2005 10:41 pm

Forgot to reply before....i thought i did!!!!

i have been using your script for a week now and its beautiful...the now playing addition is great...thanks a lot trix.

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

Post by trixmoto » Mon Nov 21, 2005 4:41 am

Glad to hear you're enjoying it! :)
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 Dec 05, 2005 6:20 pm

New version (4.0) has a few bugs fixed. Don't forget you can download the installer from my website.

:o NEW CODE BELLOW :o
Last edited by trixmoto on Thu Dec 08, 2005 5:53 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 » Thu Dec 08, 2005 4:46 am

Hey trix...im having a bit of a problem with the new version of the script...when i run it to the now playing im getting:

Image


and then im getting this one:

Image

what can it be? any ideas? please let me knoW!!!

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

Post by trixmoto » Thu Dec 08, 2005 4:54 am

Well, that's quite funny! I thought I'd tested this script with every possible type of duplication, in every place, and I did. I just forget to test this script when there wasn't any duplications! :)

I'll release a new version later today which doesn't have the error message, but as it turns out, the error message is basically saying "you have no duplicates" - just not very clearly! :lol:
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 » Thu Dec 08, 2005 5:09 am

Oh...so that was it..very interesting...lol :-) Maybe is better to display a message that says exactly that: Couldnt find any duplicates in playlist_name playlist...that way you know that the script run!

As always...thanks a lot for your scripts...keeping MM tidy :-)

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

Post by trixmoto » Thu Dec 08, 2005 5:58 am

New version (4.2) has this bug fixed:

Code: Select all

'
' MediaMonkey Script
'
' NAME: FixPlaylistDups 4.2
'
' AUTHOR: trixmoto (http://trix.dork.com)
' DATE : 08/12/2005 
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' FIXES: Option to recurse through children playlists
'        Start from selected playlist
'        Change how duplicates are detected
'        Allow user to set default detection (below: *)
'        Warn if the entered playlist was not found
'        Allow user to check Now Playing list for duplicates
'        Fix problem with siblings being found accidently
'        Fix error message when no duplicates in now playing
'
' [FixPlaylistDups]
' FileName=FixPlaylistDups.vbs
' ProcName=FixPlaylistDups
' Order=9
' DisplayName=Fix Playlist Dups
' Description=Fix Playlist Duplications
' Language=VBScript
' ScriptType=0 
'

Dim default 'change this value to the default you require (*)
default = 0 
'0 = track id
'1 = artist and title
'2 = last played
'3 = file path

Dim selname, recurse, continue, dupby, notfound

Function dup(track1, track2)

  dup = false
  Select case dupby
    case 0
          If (track1.id = track2.id) Then dup = true
    case 1
          If (track1.artistname = track2.artistname) and (track1.title = track2.title) Then dup = true
    case 2
          If (track1.lastplayed = track2.lastplayed) and (track1.lastplayed <> "00:00:00") Then dup = true
    case 3
          if (track1.path = track2.path) Then dup = true
  End Select

End Function

Sub fixList(name,found)

  Dim i,j
  Dim list,progress,tracks

  Set list = SDB.PlaylistByTitle(name)
  Set tracks = list.Tracks
  continue = true

  If name = selname Then 
    found = true   	'local
    notfound = false	'global
  End If

  If found and tracks.count > 1 Then 
    Set progress = SDB.Progress
    progress.MaxValue = tracks.count 
    progress.Text = "Scanning playlist '"&name&"' for duplicated ("&tracks.count&" tracks)"
    For i = 0 To tracks.count-2
      For j = i+1 To tracks.count-1
        If dup(tracks.Item(i),tracks.Item(j)) Then list.RemoveTrack(tracks.Item(j))
        If progress.Terminate Then Exit For
      Next    
      If progress.Terminate Then Exit For
      progress.Value = i+1
    Next
    
    If progress.Terminate Then continue = false
    Set progress = Nothing 
  End If

  If continue and (recurse or found = false) Then
    Dim children
    Set children = list.ChildPlaylists
    If found Then	'fix bug with local variable name
      For i = 0 To children.count-1
        fixList children.Item(i).Title, true
      Next
    Else
      For i = 0 To children.count-1
        fixList children.Item(i).Title, false
      Next
    End If
  End If

End Sub

Sub fixNP()

  SDB.Player.Stop
  SDB.Player.CurrentSongIndex = 0

  Dim i,j,m,a,b
  Dim progress,tracks
  Set tracks = SDB.Player.CurrentSonglist
  Set progress = SDB.Progress
  m = ""
 
  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),tracks.Item(j)) and (InStr(m,j)=0) Then m=m&j&","
        If progress.Terminate Then Exit For
      Next    
      If progress.Terminate Then Exit For
      progress.Value = i+1
    Next
  End If

  If progress.Terminate Then
    'do nothing
  Else
    If len(m) > 0 Then
      m = left(m,len(m)-1)
      m = strreverse(m)
      a = split(m,",")
      progress.MaxValue = UBound(a)
      progress.Value = 0

      progress.Text = "Removing "&UBound(a)&" tracks from Now Playing list"
      Do
        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
      Loop Until b = false

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

  Set progress = Nothing 

End Sub

Sub FixPlaylistDups

  Set Form = SDB.UI.NewForm
  Form.Common.SetRect 100, 100, 350, 150
  Form.BorderStyle  = 3   ' Resizable
  Form.FormPosition = 4   ' Screen Center
  Form.Caption = "Fix Duplicates..."

  Set Label1 = SDB.UI.NewLabel(Form)
  Label1.Caption = "Playlist name:"
  Label1.Common.Left = 10
  Label1.Common.Top = 14
         
  Set Edt1 = SDB.UI.NewEdit(Form)
  Edt1.Common.Left = Label1.Common.Left + Label1.Common.Width +25
  Edt1.Common.Top = Label1.Common.Top -4
  Edt1.Common.Width = Form.Common.Width - Edt1.Common.Left -15
  Edt1.Common.ControlName = "Edit1"
  Edt1.Text = SDB.MainTree.CurrentNode.Caption

  Set Label2 = SDB.UI.NewLabel(Form)
  Label2.Caption = "Include children?"
  Label2.Common.Left = 10
  Label2.Common.Top = 39

  Set Chk1 = SDB.UI.NewCheckbox(Form)
  Chk1.Common.Left = Edt1.Common.Left +1
  Chk1.Common.Top = Label2.Common.Top -4
  Chk1.Common.Width = Form.Common.Width - Chk1.Common.Left -15
  Chk1.Common.ControlName = "Chck1"
  Chk1.Caption = ""
  Chk1.Checked = True

  Set BtnNP = SDB.UI.NewButton(Form)
  BtnNP.Caption = "&Now Playing"
  BtnNP.Common.Top = Chk1.Common.Top
  BtnNP.Common.Left = Form.Common.Width - BtnNP.Common.Width -15
  BtnNP.Common.Height = 21
  BtnNP.UseScript = Script.ScriptPath
  BtnNP.ModalResult = 3

  Set BtnAll = SDB.UI.NewButton(Form)
  BtnAll.Caption = "&All"
  BtnAll.Common.Top = Chk1.Common.Top
  BtnAll.Common.Width = 25
  BtnAll.Common.Left = BtnNP.Common.Left - BtnAll.Common.Width -5
  BtnAll.Common.Height = 21
  BtnAll.UseScript = Script.ScriptPath
  BtnAll.ModalResult = 4

  Set Label3 = SDB.UI.NewLabel(Form)
  Label3.Caption = "Duplicates by:"
  Label3.Common.Left = 10
  Label3.Common.Top = 64

  Set Drp1 = SDB.UI.NewDropdown(Form)
  Drp1.Common.Left = Chk1.Common.Left
  Drp1.Common.Top = Label3.Common.Top -4
  Drp1.Common.Width = Form.Common.Width - Drp1.Common.Left -15
  Drp1.Common.ControlName = "Drop1"
  Drp1.Style = 2
  Drp1.AddItem("Track ID")
  Drp1.AddItem("Artist & Title")
  Drp1.AddItem("Last played")
  Drp1.AddItem("File path")
  Drp1.ItemIndex = default
   
  Set BtnOk = SDB.UI.NewButton(Form)
  BtnOk.Caption = "&Ok"
  BtnOk.Common.Top = Drp1.Common.Top + Drp1.Common.Height +10
  BtnOk.UseScript = Script.ScriptPath
  BtnOk.Default = True
  BtnOk.ModalResult = 1
      
  Set BtnCancel = SDB.UI.NewButton(Form)
  BtnCancel.Caption = "&Cancel"
  BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width -15
  BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width -10
  BtnCancel.Common.Top = BtnOK.Common.Top
  BtnCancel.UseScript = Script.ScriptPath
  BtnCancel.Cancel = True
  BtnCancel.ModalResult = 2

  Dim res
  Do
    res = Form.showModal
    If res = 1 Then
      res = 2
      dupby = Drp1.ItemIndex
      selname = Edt1.Text 
      recurse = Chk1.Checked
      continue = true
      notfound = true
  
      If selname = "[NP]" Then
        fixNP
      Else  
        fixList "", false
        If notfound Then 
          res = SDB.MessageBox("Playlist entered was not found!", mtError, Array(mbOk)) 
        End If
      End If
    End If  
    If res = 3 Then
      Edt1.Text = "[NP]"
      Chk1.Checked = false
    End If
    If res = 4 Then
      Edt1.Text = ""
      Chk1.Checked = true
    End If
  Loop Until res = 2
End Sub 
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 Dec 12, 2005 4:19 am

Couldn't resist adding this:
cali wrote:it's working wonderfully, good work
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.

Guest4544

Post by Guest4544 » Tue Sep 26, 2006 2:46 pm

Great script. Thank you !

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

Post by trixmoto » Tue Sep 26, 2006 3:24 pm

Glad you like! :)
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.

scratchie77
Posts: 10
Joined: Tue Nov 14, 2006 5:53 am

Small Modification

Post by scratchie77 » Wed Dec 06, 2006 6:04 am

Triximoto,

Great script.

Most of my auto playlists tend to have a large number of songs by the same artist in them so i made a small modification to make the script remove duplicate artists, and leave the song least recently heard by the artist in the playlist.

Code: Select all

case 4
If (track1.artistname = track2.artistname) and (track1.lastplayed < track2.lastplayed) Then dup = true
If (track1.artistname = track2.artistname) and (track1.lastplayed > track2.lastplayed) Then dupeArtist = true

and then down further in the loop

Code: Select all

For j = i+1 To tracks.count-1
        If dup(tracks.Item(i),tracks.Item(j)) Then list.RemoveTrack(tracks.Item(j))
        if dupeArtist = true Then list.RemoveTrack(tracks.Item(i))
        If progress.Terminate Then Exit For
Next 
I know there are cleaner ways to code it, but hey it works!

What i would really like to do is on startup copy the autoplaylist to a regular playlist and then automatically run your script.

i don't suppose you could point me in the right direction on a simple way to copy the playlist?

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

Post by trixmoto » Wed Dec 06, 2006 7:01 am

Sorry, I don't know how to create a new manual playlist in MM, if it's even possible through scripting.
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