• Welcome to RadioDJ - Free Radio Automation Software Forum. Please log in or sign up.

Stop On-Air Train Wrecks (Sweepers/VTs Stepping on Song Intros) With This Code

Started by RadioDJ Dude, December 07, 2024, 07:19:18 PM

RadioDJ Dude

Nothing screams "Amateur!", like train wrecked audio on your station. 💥 Crap-Be-Gone with this custom SQL query for RadioDJ. Your voice tracks and sweepers will never trample a song intro again!

🪄This magic code looks at the length of your imaging element or voice over and finds a song with a suitable intro time to match. Bub bye, basement crapcaster. Hello, major market sound!

Check out the video and give all your song intros a fighting chance!
XXX80s.com-XXXtreme 80s fun!
YouTube Channel: RadioDJ Dude

RadioDJ Dude

A viewer suggested the code should first select a song and then choose an appropriate sweeper (based on song's intro time...since it will play over intro) or jingle (if zero intro). Duh! This is a much better way. Here's the updated query. Of course, change all subcats and genres to match your own.

-- Step 1: Select a sweeper or jingle first based on the intro time of the upcoming song
SELECT id, title, artist, NULL AS absolute_intro
FROM (
    SELECT
        s.id,
        s.title,
        s.artist
    FROM songs s
    WHERE s.id_subcat = (
        -- Determine if the intro time is long enough for a sweeper or if a jingle should be selected
        SELECT
            CASE
                WHEN (CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(song.cue_times, '&int=', -1), '&', 1) AS DECIMAL(10, 5)) -
                      CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(song.cue_times, '&sta=', -1), '&', 1) AS DECIMAL(10, 5))) > 2 -- Threshold for short intro
                THEN 135 -- SweeperSubCat
                ELSE 11 -- JingleSubCat
            END
        FROM songs song
        LEFT JOIN queuelist q ON song.artist = q.artist
        WHERE song.enabled = 1
          AND song.song_type = 0
          AND song.id_genre = 143
          AND song.id_subcat = 2
          AND TIMESTAMPDIFF(MINUTE, song.date_played, NOW()) > $TrackRepeatInterval$
          AND TIMESTAMPDIFF(MINUTE, song.artist_played, NOW()) > $ArtistRepeatInterval$
          AND q.artist IS NULL
        ORDER BY song.date_played ASC
        LIMIT 1
    )
    AND (
        -- If the sweeper is selected, its running time must fit within the song's intro time
        (CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(s.cue_times, '&xta=', -1), '&', 1) AS DECIMAL(10, 5)) -
         CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(s.cue_times, '&sta=', -1), '&', 1) AS DECIMAL(10, 5)))
         <= (
             SELECT (CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(song.cue_times, '&int=', -1), '&', 1) AS DECIMAL(10, 5)) -
                     CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(song.cue_times, '&sta=', -1), '&', 1) AS DECIMAL(10, 5)))
             FROM songs song
             LEFT JOIN queuelist q ON song.artist = q.artist
             WHERE song.enabled = 1
               AND song.song_type = 0
               AND song.id_genre = 143
               AND song.id_subcat = 2
               AND TIMESTAMPDIFF(MINUTE, song.date_played, NOW()) > $TrackRepeatInterval$
               AND TIMESTAMPDIFF(MINUTE, song.artist_played, NOW()) > $ArtistRepeatInterval$
               AND q.artist IS NULL
             ORDER BY song.date_played ASC
             LIMIT 1
         )
    )
    ORDER BY s.date_played ASC
    LIMIT 1
) AS sweeper_or_jingle

UNION ALL

-- Step 2: Select the song and calculate its intro time
SELECT id, title, artist, absolute_intro
FROM (
    SELECT
        s.id,
        s.title,
        s.artist,
        (CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(s.cue_times, '&int=', -1), '&', 1) AS DECIMAL(10, 5)) -
         CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(s.cue_times, '&sta=', -1), '&', 1) AS DECIMAL(10, 5))) AS absolute_intro
    FROM songs s
    LEFT JOIN queuelist q ON s.artist = q.artist
    WHERE s.enabled = 1
      AND s.song_type = 0
      AND s.id_genre = 143
      AND s.id_subcat = 2
      AND TIMESTAMPDIFF(MINUTE, s.date_played, NOW()) > $TrackRepeatInterval$
      AND TIMESTAMPDIFF(MINUTE, s.artist_played, NOW()) > $ArtistRepeatInterval$
      AND q.artist IS NULL
    ORDER BY s.date_played ASC
    LIMIT 1
) AS song;
XXX80s.com-XXXtreme 80s fun!
YouTube Channel: RadioDJ Dude

stevewa

impressed that you can accept suggestions with that 80s aqua net hairdo makin your head so big :)

RadioDJ Dude

XXX80s.com-XXXtreme 80s fun!
YouTube Channel: RadioDJ Dude