Clever method to check if song in playlist?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Just Guessing
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm

Clever method to check if song in playlist?

Post by Just Guessing »

Is there a simple scripting method to test if a song is already in a playlist?

I'd like to avoid the MM duplication confirmation page I would get otherwise. Obviously one could go through a loop of each song in playlist, but I'm wondering if it isn't easier than that.
Lowlander
Posts: 56491
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: Clever method to check if song in playlist?

Post by Lowlander »

The following Addon can show this in a panel: http://www.mediamonkey.com/forum/viewto ... tion+panel

The Classification tab of the Properties window will also show what Playlist(s) a file belongs to.
Just Guessing
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm

Re: Clever method to check if song in playlist?

Post by Just Guessing »

No, I mean in order to accomplish an IF/THEN like below:

If Not In Playlist "whatever"( theSong) then
SDB.PlaylistByTitle("whatever").AddTrack( theSong )
end if

I can tighten the goal down to 5 lines of code, but wonder if I haven't missed some single line that does the job:
Dup = False
for i = 0 To SDB.PlaylistByTitle(Playlist).Tracks.Count - 1
if SDB.PlaylistByTitle(Playlist).Tracks.Item(i).ID = NewSong.ID Then Dup = True
next
if Dup = False Then SDB.PlaylistByTitle(Playlist).AddTrack NewSong
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Clever method to check if song in playlist?

Post by chrisjj »

Just Guessing wrote: I can tighten the goal down to 5 lines of code, but wonder if I haven't missed some single line that does the job:
Dup = False
for i = 0 To SDB.PlaylistByTitle(Playlist).Tracks.Count - 1
if SDB.PlaylistByTitle(Playlist).Tracks.Item(i).ID = NewSong.ID Then Dup = True
next
if Dup = False Then SDB.PlaylistByTitle(Playlist).AddTrack NewSong
You could accelerate that by exiting the loop in the THEN.
Chris
chrisjj
Posts: 5007
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Clever method to check if song in playlist?

Post by chrisjj »

Just Guessing wrote:Is there a simple scripting method to test if a song is already in a playlist?

I'd like to avoid the MM duplication confirmation page I would get otherwise.
Don't you get this option to avoid that confirmation dialog?

Image
Chris
Post Reply