SAAS-772: Send metadata to Tunein

Update metadata when station goes offline
This commit is contained in:
drigato 2015-05-19 15:42:07 -04:00
parent c3457ae03f
commit 2da4e264e5
2 changed files with 34 additions and 8 deletions

View File

@ -4,15 +4,11 @@ class Application_Common_TuneIn
{ {
public static function sendMetadataToTunein($title, $artist) public static function sendMetadataToTunein($title, $artist)
{ {
$tuneInStationID = Application_Model_Preference::getTuneinStationId(); $credQryStr = self::getCredentialsQueryString();
$tuneInPartnerID = Application_Model_Preference::getTuneinPartnerId(); $metadataQryStr = "&title=".$title."&artist=".$artist."&commercial=false";
$tuneInPartnerKey = Application_Model_Preference::getTuneinPartnerKey();
$qry_str = "?partnerId=".$tuneInPartnerID."&partnerKey=".$tuneInPartnerKey."&id=".$tuneInStationID
."&title=".$title."&artist=".$artist."&commercial=false";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TUNEIN_API_URL . $qry_str); curl_setopt($ch, CURLOPT_URL, TUNEIN_API_URL . $credQryStr . $metadataQryStr);
curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 30);
@ -25,6 +21,28 @@ class Application_Common_TuneIn
} }
public static function updateOfflineMetadata() private static function getCredentialsQueryString() {
$tuneInStationID = Application_Model_Preference::getTuneinStationId();
$tuneInPartnerID = Application_Model_Preference::getTuneinPartnerId();
$tuneInPartnerKey = Application_Model_Preference::getTuneinPartnerKey();
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);
}
} }

View File

@ -1,4 +1,5 @@
<?php <?php
require_once('TuneIn.php');
$filepath = realpath (dirname(__FILE__)); $filepath = realpath (dirname(__FILE__));
require_once($filepath."/../modules/rest/controllers/MediaController.php"); require_once($filepath."/../modules/rest/controllers/MediaController.php");
@ -297,6 +298,13 @@ class ScheduleController extends Zend_Controller_Action
public function getCurrentPlaylistAction() public function getCurrentPlaylistAction()
{ {
$range = Application_Model_Schedule::GetPlayOrderRangeOld(); $range = Application_Model_Schedule::GetPlayOrderRangeOld();
// If there is no current track playing update TuneIn so it doesn't
// display outdated metadata
if (is_null($range["current"]) && Application_Model_Preference::getTuneinEnabled()) {
Application_Common_TuneIn::updateOfflineMetadata();
}
$show = Application_Model_Show::getCurrentShow(); $show = Application_Model_Show::getCurrentShow();
/* Convert all UTC times to localtime before sending back to user. */ /* Convert all UTC times to localtime before sending back to user. */