This bit of code should populate the playlist with five songs that appear in a playlist that has been saved to the RadioDJ database, randomly, and obey the settings for the track/artist repeat rules:
SELECT `songs`.`ID`, `songs`.`artist`, `songs`.`title` FROM `songs`
LEFT JOIN `queuelist` ON (`songs`.`ID` = `queuelist`.`songID` OR `songs`.`artist` = `queuelist`.`artist`)
LEFT JOIN `playlists_list` ON (`songs`.`ID` = `playlists_list`.`sID`)
WHERE `songs`.`enabled`=1
AND ((`start_date` = NOW() OR `end_date` = '2002-01-01 00:00:01'))
AND (TIMESTAMPDIFF(MINUTE, `date_played`, NOW())>$TrackRepeatInterval$ AND TIMESTAMPDIFF(MINUTE, `artist_played`, NOW())>$ArtistRepeatInterval$)
AND (`queuelist`.`songID` IS NULL OR `queuelist`.`artist` IS NULL)
AND (`playlists_list`.`pID` = '3')
ORDER BY RAND() LIMIT 5;
Note: The number value for the playlist ID in line AND (`playlists_list`.`pID` = '3')
can be found in the playlists table…
Explanation of why one would wanna do this: Say I wanna have certain songs appear a little more often, and keep them in regular rotation… or, maybe I wanna create a special block/set of certain songs… Well, I go create a “playlist” using the playlist builder, save it, then add this code to the Tracks Rotation rules.
Other potential uses include using a playlist as a store for certain sets of commercials, etc., and having them loaded randomly or in order…
Idea and code from the RadioDJ forums: http://www.radiodj.ro/community/index.php?topic=6658.msg39493#msg39493
One thought on “Tracks Rotation SQL Query: Load five songs from a playlist”