How to get live info and dj info
  • Hi,

    i was wondering how can i get the following info out of airtime.

    i want to know when a show is playing (regular program) and when a dj goes live as an master source or show source and if a show source is connected which user/dj is playing, can't seem to find it in the next files : api/live-info/?callback or api/week-info/?callback or anywhere else.  

    You can see if a master source or show source is connected in the airtime backend, but i need a file or something so i can read the info and use it for scripts on our website.

    So in short how can i see if a scheduled show is playing or a master souce of show source is connected and if show source what dj is playing.

    Cheers René

    i'm using airtime 2.5.1 on ubuntu 12.04

    Post edited by René Ooms at 2016-03-26 15:40:53
  • 3 Comments sorted by
  • Ok, lets take this step by step (sure, I could outright tell you how to do it, but I think it is always better to show someone how they can get to the answer themselves - teach a man to fish and all):

    Part 1: See if we are currently playing scheduled or 'live'

    Lets start by trying to figure out where the web interface gets its information from. We can be fairly certain that it updates via ajax requests to the server so lets use the browser development tools to look at the requests the browser is making. When we look, we can see a group of three requests that are repeated every couple of seconds:
    Of course, at this point we need to know which of these gets us the information we need. Luckily, using the same tools we can take a look at the information that the server gave us. To save space, I'm going to jump straight to the one that we want:

    {"source_status":{"live_dj_source":false,"master_dj_source":false},"switch_status":{"live_dj_source":"off","master_dj_source":"off","scheduled_play":"on"},"entries":{"env":"production","schedulerTime":"2016-03-27 21:22:43","previous":{"name":"Taylor Swift - I Know Places","starts":"2016-03-27 21:19:22","ends":"2016-03-27 21:22:36","type":"track"},"current":{"name":"David Bowie - Sorrow","starts":"2016-03-27 21:22:35","ends":"2016-03-27 21:25:28","media_item_played":true,"record":0,"type":"track"},"next":{"name":"C\u00e9line Dion - Moi quand je pleure","starts":"2016-03-27 21:25:27","ends":"2016-03-27 21:29:14","type":"track"},"currentShow":[{"start_timestamp":"2016-03-27 00:00:00","0":"2016-03-27 00:00:00","end_timestamp":"2016-03-27 23:59:00","1":"2016-03-27 22:59:00","name":"Daily","2":"Daily","id":1,"3":1,"instance_id":2,"4":2,"record":0,"5":0,"url":"","6":"","starts":"2016-03-27 00:00:00","7":"2016-03-27 00:00:00","ends":"2016-03-27 23:59:00","8":"2016-03-27 22:59:00"}],"nextShow":[{"id":1,"instance_id":6,"name":"Daily","url":"","start_timestamp":"2016-03-28 00:00:00","end_timestamp":"2016-03-28 23:59:00","starts":"2016-03-28 00:00:00","ends":"2016-03-28 23:59:00","record":0,"type":"show"}],"timezone":"BST","timezoneOffset":"3600"},"show_name":"Daily"}

    Now, this looks more like it! At this point, you may be wondering why we don't just make these requests from our own application - however, years of experience (and common sense) tell me that there is almost certainly more to it than that. Lets go and find the source of the php that supplies this information. Lets go to the github page for airtime and start running some searches.

    In the top right there is a search bar where we can start searching. Lets begin with a select part of the url:


    This gives us two results, 
    • dashboard.js - This is most likely the file that actually triggers the http request that we saw earlier - not what we want.
    • ScheduleController.php - This seems like it could be what we want. Especially since we see a line that looks like: addActionContext('get-current-playlist', 'json')
    This is where my limited knowledge of the zend framework starts to slow progress. First step is to find out exactly what "addActionContext" does. I believe it would call a function that looks something like:


    In here, we see three lines that look like:

    $scheduled_play_switch = Application_Model_Preference::GetSourceSwitchStatus("scheduled_play");
    $live_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("live_dj");
    $master_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("master_dj");

    Lets go and look in the Preference application model now. we find this in: airtime_mvc/application/models/Preference.php

    The function that we are calling looks like:

        public static function GetSourceSwitchStatus($sourcename)
            $value = self::getValue($sourcename."_switch");
            return ($value == null || $value == "off") ? 'off' : 'on';

    This calls the function: private static function getValue($key, $isUserValue = false)

    Here we ask the database table cc_pref to get the keys:


    This table seems to have at least two columns with data would think looks something like:

    |                keystr               |              valstr      |
    |         live_dj_switch           |                true      |
    | scheduled_play_switch      |                false    |
    |    master_dj_switch           |                false    |

    This suggests that we should be able to make sql requests straight to the database in order to tell which stream is currently live using an SQL query such as:

    SELECT valstr FROM cc_pref WHERE keystr = live_dj_switch

    I won't be able to test this tonight but will report back to confirm it worked for me and to try to figure out how to get the other information you wanted tomorrow.

    Hope this helps,
    Post edited by Marcus Hann at 2016-03-27 17:20:23
  • Hi Marcus,

    thank you for all your info, i will dive into it. 

    i'm doing a new installation today because i had some serious bugs with a silent stream, this is a old bug i noticed with ubuntu 12.04. 32 bit installations, so i'm installing ubtuntu 14.04 and start over, so it will take a day to get everything working again and uploading my music and then start with your info.

    Cheers René
  • Hi,

    no problem :) I did end up writing this fairly late at night so hopefully all works and I didn't mess up in some way! Let me know how it goes