Track exists in playlist - best method ?

Post a reply

Visual Confirmation

To prevent automated access and spam, you are required to confirm that you are human. Please place a check mark next to all images of monkeys or apes. If you cannot see any images, please contact the Board Administrator.

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Track exists in playlist - best method ?

Re: Track exists in playlist - best method ?

Post by raybeau528 » Mon Feb 23, 2009 8:22 pm

Thanks ZvezdanD ! All 3 methods worked perfectly!

Ray

Re: Track exists in playlist - best method ?

Post by ZvezdanD » Mon Feb 23, 2009 12:02 pm

By the way, if you want to check if all 1000 tracks belong to same playlist, I suppose that it is faster to check this with a single SQL query, instead of one SQL query for each track. Here is an example:
Code: Select all
' sSongDataIDArray = "1234, 1235, ..., 9999"

If Not SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs WHERE PlaylistSongs.IDSong IN (" & sSongDataIDArray & ") AND PlaylistSongs.IDPlaylist = " & iPlaylistID).EOF Then

Re: Track exists in playlist - best method ?

Post by ZvezdanD » Mon Feb 23, 2009 11:45 am

raybeau528 wrote:Result was NOT in playlist.

Well, if EOF is True that mean the recordset is empty, so you should switch MsgBox-es after Then and Else or put Not after If.

Re: Track exists in playlist - best method ?

Post by raybeau528 » Mon Feb 23, 2009 11:24 am

I can get the playlist ID . I'll try that next but it will be later today. Thanks for your expert help!

Ray

Re: Track exists in playlist - best method ?

Post by raybeau528 » Mon Feb 23, 2009 11:23 am

ZvezdanD,

I tried this:

Code: Select all
Sub TrackinPlaylist(arg)
   dim isongdataid : iSongDataID = 6431
   dim sPlaylistName : sPlaylistName = "Test"

   If SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs, Playlists WHERE PlaylistSongs.IDSong = " & iSongDataID & " AND PlaylistSongs.IDPlaylist = Playlists.IDPlaylist AND Playlists.PlaylistName = '" & sPlaylistName & "'").EOF Then
      msgbox("In Playlist")
   else
      msgbox("Not in Playlist")
   End If

End Sub


I created a playlist named "Test". I copied the song.id's to custom1 so I could see them and verified that one track song.id was 6431. I hard coded them for a quick test. Result was NOT in playlist. I don't know sql but those look like the only variables.

Ray

Re: Track exists in playlist - best method ?

Post by ZvezdanD » Mon Feb 23, 2009 11:19 am

It could be even shorter if you know playlist's ID:
Code: Select all
If SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs WHERE PlaylistSongs.IDSong = " & iSongDataID & " AND PlaylistSongs.IDPlaylist = " & iPlaylistID).EOF Then

Re: Track exists in playlist - best method ?

Post by raybeau528 » Mon Feb 23, 2009 11:05 am

Thanks for the super quick response!!! I'll give it a try.

Ray

Re: Track exists in playlist - best method ?

Post by ZvezdanD » Mon Feb 23, 2009 11:00 am

raybeau528 wrote:What would be the best method to determine, via a script, if a track exists in a playlist?

I haven't tried, but you could try something like this:
Code: Select all
If SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs, Playlists WHERE PlaylistSongs.IDSong = " & iSongDataID & " AND PlaylistSongs.IDPlaylist = Playlists.IDPlaylist AND Playlists.PlaylistName = '" & sPlaylistName & "'").EOF Then

Track exists in playlist - best method ?

Post by raybeau528 » Mon Feb 23, 2009 10:39 am

What would be the best method to determine, via a script, if a track exists in a playlist?

I certainly could loop through all tracks and check for matching song.id. Not heavy processing if I'm checking for 1 track in 1000. Checking for 1000 tracks in a 10,000 track playlist could result in a million cycles!

Does the AddTrackbyID(ID) method return any indication whether the track ID already exists in the playlist?

The Properties editor / Classification lists the playlists for which the selected song is a member. Is there a scripting property/method to access that?

Thanks!

Ray

Top

cron