Clever method to check if song in playlist?

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

Moderator: Gurus

Clever method to check if song in playlist?

Postby Just Guessing » Tue Sep 13, 2016 10:18 am

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.
Just Guessing
 
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm

Re: Clever method to check if song in playlist?

Postby Lowlander » Tue Sep 13, 2016 11:13 am

The following Addon can show this in a panel: viewtopic.php?f=2&t=41882&hilit=song+information+panel

The Classification tab of the Properties window will also show what Playlist(s) a file belongs to.
Lowlander (MediaMonkey user since 2003)
Lowlander
 
Posts: 43393
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Re: Clever method to check if song in playlist?

Postby Just Guessing » Tue Sep 13, 2016 11:29 am

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
Just Guessing
 
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm

Re: Clever method to check if song in playlist?

Postby chrisjj » Fri Oct 14, 2016 4:57 am

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: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK

Re: Clever method to check if song in playlist?

Postby chrisjj » Fri Oct 14, 2016 4:57 am

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
chrisjj
 
Posts: 4926
Joined: Wed Feb 14, 2007 5:14 pm
Location: UK


Return to MediaMonkey 4 Addons developer forum

Who is online

Users browsing this forum: No registered users and 3 guests