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
7 changed files with 59 additions and 26 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue