Blogs

get_img

  Add jingles to Sourcefabric Airtime Radio

Publicidad Google

Airtime 2.5.1, the open radio software for scheduling and remote station management.

How add jingles every x songs with Dynamic Smart Block:

Edit file:

/usr/share/airtime/application/models/Block.php

Add function:

// Return random jingle
function get_item_insertList(){

    $jingles = array(
                // array with jingles
                array ( 'id' => 545, 'length'=> 27.193 ),   // jingle ID and lenght  
                );


    // return random jingle in array
    $jingle = $jingles[ rand(0, count($jingles) - 1 ) ];

    $item_insertList = array( 'item' => $jingle, 'length' => $jingle['length'] );
    return $item_insertList;
}

Modify function:

    public function getListOfFilesUnderLimit()
    {
        $info       = $this->getListofFilesMeetCriteria();
        $files      = $info['files'];
        $limit      = $info['limit'];
        $repeat     = $info['repeat_tracks'];

        $insertList = array();
        $totalTime  = 0;
        $totalItems = 0;

        // this moves the pointer to the first element in the collection
        $files->getFirst();
        $iterator = $files->getIterator();
        
        $isBlockFull = false;
        

        while ($iterator->valid()) {
        	
            $id = $iterator->current()->getDbId();
            $fileLength = $iterator->current()->getCueLength();
            $length = Application_Common_DateHelper::calculateLengthInSeconds($fileLength);
            $insertList[] = array('id'=>$id, 'length'=>$length);
            $totalTime += $length;
            $totalItems++;

            
            if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
                $isBlockFull = true;
                break;
            }

            $iterator->next();
        }
        
        $sizeOfInsert = count($insertList);
        
        // if block is not full and repeat_track is check, fill up more
        while (!$isBlockFull && $repeat == 1 && $sizeOfInsert > 0) {
        	Logging::debug("adding repeated tracks.");
        	Logging::debug("total time = " . $totalTime);
        	
            $randomEleKey = array_rand(array_slice($insertList, 0, $sizeOfInsert));
            $insertList[] = $insertList[$randomEleKey];
            $totalTime += $insertList[$randomEleKey]['length'];
            $totalItems++;
            
            if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
                break;
            }
        }

        return $insertList;
    }

Like this:

    public function getListOfFilesUnderLimit()
    {
        $info       = $this->getListofFilesMeetCriteria();
        $files      = $info['files'];
        $limit      = $info['limit'];
        $repeat     = $info['repeat_tracks'];

        $insertList = array();
        $totalTime  = 0;
        $totalItems = 0;

        // this moves the pointer to the first element in the collection
        $files->getFirst();
        $iterator = $files->getIterator();
        
        $isBlockFull = false;
        
        $rand = 0;  // add
        while ($iterator->valid()) {
        	
            $id = $iterator->current()->getDbId();
            $fileLength = $iterator->current()->getCueLength();
            $length = Application_Common_DateHelper::calculateLengthInSeconds($fileLength);
            $insertList[] = array('id'=>$id, 'length'=>$length);
            $totalTime += $length;
            $totalItems++;

            // Add this code to add jingles to dynamyc smart block
            $rand++;
            if ($rand >= 1 && rand(1,10) > 3 ){
                $item_insertList = get_item_insertList();
                $insertList[] = $item_insertList['item'];
                $totalTime += $item_insertList['length'];
                $totalItems++;
                $rand = 0;
            }

            
            if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
                $isBlockFull = true;
                break;
            }

            $iterator->next();
        }
        
        $sizeOfInsert = count($insertList);
        
        // if block is not full and repeat_track is check, fill up more
        while (!$isBlockFull && $repeat == 1 && $sizeOfInsert > 0) {
        	Logging::debug("adding repeated tracks.");
        	Logging::debug("total time = " . $totalTime);
        	
            $randomEleKey = array_rand(array_slice($insertList, 0, $sizeOfInsert));
            $insertList[] = $insertList[$randomEleKey];
            $totalTime += $insertList[$randomEleKey]['length'];
            $totalItems++;
            
            if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
                break;
            }
        }

        //file_put_contents('/tmp/insertList', print_r($insertList, true));       // debug list

        return $insertList;
    }
  • Geoff Fish

    Hey, this looks great, and just what I need (Well, I need to do Jingle->Advert->Jingle between every track – We only play long mixes. I can easily modify this part.)

    My question – for the function get_item_insertList(), Is there a way to automatically search the library for matching media where the Genre or Album is “Jingle”?

    This means we can upload/add/remove jingles from the AirTime interface without having to touch the code again?

    • Ernesto Bustos

      Thanks my friend, maybe we can develop this functionality for your radio for 100 USD ?