SAAS-772: Send metadata to Tunein
Made Improvement so Airtime always makes a request to TuneIn every 4 minutes so TuneIn does not turn metadata off
This commit is contained in:
parent
fc02de4920
commit
532bd1ea85
|
@ -17,12 +17,20 @@ class Application_Common_TuneIn
|
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
curl_exec($ch);
|
||||
$xmlResponse = curl_exec($ch);
|
||||
if (curl_error($ch)) {
|
||||
Logging::error("Failed to reach TuneIn: ". curl_errno($ch)." - ". curl_error($ch) . " - " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$xmlObj = new SimpleXMLElement($xmlResponse);
|
||||
if (!$xmlObj || $xmlObj->head->status != "200") {
|
||||
Logging::info("Error occurred pushing metadata to TuneIn:");
|
||||
Logging::info($xmlResponse);
|
||||
} else if ($xmlObj->head->status == "200") {
|
||||
Application_Model_Preference::setLastTuneinMetadataUpdate(time());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static function getCredentialsQueryString() {
|
||||
|
@ -33,20 +41,4 @@ class Application_Common_TuneIn
|
|||
return "?partnerId=".$tuneInPartnerID."&partnerKey=".$tuneInPartnerKey."&id=".$tuneInStationID;
|
||||
}
|
||||
|
||||
public static function updateOfflineMetadata() {
|
||||
$credQryStr = self::getCredentialsQueryString();
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, TUNEIN_API_URL . $credQryStr . "&commercial=true");
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
curl_exec($ch);
|
||||
if (curl_error($ch)) {
|
||||
Logging::error("Failed to reach TuneIn: ". curl_errno($ch)." - ". curl_error($ch) . " - " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
|
||||
}
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1515,5 +1515,30 @@ class ApiController extends Zend_Controller_Action
|
|||
$this->_helper->json($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called from PYPO (pypofetch) every 2 minutes and updates
|
||||
* metadata on TuneIn if we haven't done so in the last 4 minutes. We have
|
||||
* to do this because TuneIn turns off metadata if it has not received a
|
||||
* request within 5 minutes. This is necessary for long tracks > 5 minutes.
|
||||
*/
|
||||
public function updateMetadataOnTuneinAction()
|
||||
{
|
||||
if (!Application_Model_Preference::getTuneinEnabled()) {
|
||||
$this->_helper->json->sendJson(array(0));
|
||||
}
|
||||
|
||||
$lastTuneInMetadataUpdate = Application_Model_Preference::geLastTuneinMetadataUpdate();
|
||||
if (time() - $lastTuneInMetadataUpdate >= 240) {
|
||||
$metadata = $metadata = Application_Model_Schedule::getCurrentPlayingTrack();
|
||||
if (!is_null($metadata)) {
|
||||
Application_Common_TuneIn::sendMetadataToTunein(
|
||||
$metadata["title"],
|
||||
$metadata["artist"]
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->_helper->json->sendJson(array(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -315,13 +315,6 @@ class ScheduleController extends Zend_Controller_Action
|
|||
{
|
||||
$range = Application_Model_Schedule::GetPlayOrderRangeOld();
|
||||
|
||||
// If there is no current track playing update TuneIn so it doesn't
|
||||
// display outdated metadata
|
||||
//TODO: find a better solution for this so we don't spam the station on TuneIn
|
||||
/*if (is_null($range["current"]) && Application_Model_Preference::getTuneinEnabled()) {
|
||||
Application_Common_TuneIn::updateOfflineMetadata();
|
||||
}*/
|
||||
|
||||
$show = Application_Model_Show::getCurrentShow();
|
||||
|
||||
/* Convert all UTC times to localtime before sending back to user. */
|
||||
|
|
|
@ -87,6 +87,7 @@ class Application_Form_TuneInPreferences extends Zend_Form_SubForm
|
|||
if (!$xmlObj || $xmlObj->head->status != "200") {
|
||||
$valid = false;
|
||||
} else if ($xmlObj->head->status == "200") {
|
||||
Application_Model_Preference::setLastTuneinMetadataUpdate(time());
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1493,4 +1493,14 @@ class Application_Model_Preference
|
|||
{
|
||||
return self::getValue("tunein_station_id");
|
||||
}
|
||||
|
||||
public static function geLastTuneinMetadataUpdate()
|
||||
{
|
||||
return self::getValue("last_tunein_metadata_update");
|
||||
}
|
||||
|
||||
public static function setLastTuneinMetadataUpdate($value)
|
||||
{
|
||||
self::setValue("last_tunein_metadata_update", $value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ api_config['push_stream_stats'] = 'push-stream-stats/api_key/%%api_key%%/format/
|
|||
api_config['update_stream_setting_table'] = 'update-stream-setting-table/api_key/%%api_key%%/format/json'
|
||||
api_config['get_files_without_silan_value'] = 'get-files-without-silan-value/api_key/%%api_key%%'
|
||||
api_config['update_cue_values_by_silan'] = 'update-cue-values-by-silan/api_key/%%api_key%%'
|
||||
api_config['update_metadata_on_tunein'] = 'update-metadata-on-tunein/api_key/%%api_key%%'
|
||||
|
||||
|
||||
|
||||
|
@ -530,6 +531,9 @@ class AirtimeApiClient(object):
|
|||
#TODO
|
||||
self.logger.error(str(e))
|
||||
|
||||
def update_metadata_on_tunein(self):
|
||||
self.services.update_metadata_on_tunein()
|
||||
|
||||
|
||||
class InvalidContentType(Exception):
|
||||
pass
|
||||
|
|
|
@ -14,7 +14,7 @@ import traceback
|
|||
import pure
|
||||
|
||||
from Queue import Empty
|
||||
from threading import Thread
|
||||
from threading import Thread, Timer
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from api_clients import api_client
|
||||
|
@ -447,6 +447,12 @@ class PypoFetch(Thread):
|
|||
|
||||
return success
|
||||
|
||||
# This function makes a request to Airtime to see if we need to
|
||||
# push metadata to TuneIn. We have to do this because TuneIn turns
|
||||
# off metadata if it does not receive a request every 5 minutes.
|
||||
def update_metadata_on_tunein(self):
|
||||
self.api_client.update_metadata_on_tunein()
|
||||
Timer(120, self.update_metadata_on_tunein).start()
|
||||
|
||||
def main(self):
|
||||
#Make sure all Liquidsoap queues are empty. This is important in the
|
||||
|
@ -458,8 +464,10 @@ class PypoFetch(Thread):
|
|||
|
||||
self.set_bootstrap_variables()
|
||||
|
||||
self.update_metadata_on_tunein()
|
||||
|
||||
# Bootstrap: since we are just starting up, we need to grab the
|
||||
# most recent schedule. After that we fetch the schedule every 30
|
||||
# most recent schedule. After that we fetch the schedule every 8
|
||||
# minutes or wait for schedule updates to get pushed.
|
||||
success = self.persistent_manual_schedule_fetch(max_attempts=5)
|
||||
|
||||
|
|
Loading…
Reference in New Issue