SAAS-772: Send metadata to Tunein

This is pretty much working for scheduled metadata - just to need to
test with a TuneIn account.
This commit is contained in:
drigato 2015-05-13 16:05:37 -04:00
parent 77241bb6fc
commit cf24c141fd
10 changed files with 179 additions and 2 deletions

View file

@ -0,0 +1,29 @@
<?php
class Application_Common_TuneIn
{
public static function sendMetadataToTunein($title, $artist)
{
$tuneInStationID = null;
$tuneInPartnerKey = null;
$tuneInPartnerID = null;
$qry_str = "?partnerId=".$tuneInPartnerID."&partnerKey=".$tuneInPartnerKey."&id=".$tuneInStationID
."&title=".$title."&artist=".$artist;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TUNEIN_API_URL . $qry_str);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$jsonData = 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);
$arr = json_decode($jsonData, true);
Logging::info($arr);
}
}

View file

@ -92,3 +92,7 @@ define('SENTRY_CONFIG_PATH', '/etc/airtime-saas/sentry.airtime_web.ini');
//Provisioning status //Provisioning status
define('PROVISIONING_STATUS_SUSPENDED' , 'Suspended'); define('PROVISIONING_STATUS_SUSPENDED' , 'Suspended');
define('PROVISIONING_STATUS_ACTIVE' , 'Active'); define('PROVISIONING_STATUS_ACTIVE' , 'Active');
//TuneIn integration
define("TUNEIN_API_URL", "http://air.radiotime.com/Playing.ashx");

View file

@ -1,4 +1,5 @@
<?php <?php
require_once('TuneIn.php');
class ApiController extends Zend_Controller_Action class ApiController extends Zend_Controller_Action
{ {
@ -615,6 +616,14 @@ class ApiController extends Zend_Controller_Action
$file = Application_Model_StoredFile::RecallById($file_id); $file = Application_Model_StoredFile::RecallById($file_id);
$now = new DateTime("now", new DateTimeZone("UTC")); $now = new DateTime("now", new DateTimeZone("UTC"));
$file->setLastPlayedTime($now); $file->setLastPlayedTime($now);
// Push metadata to TuneIn
if (Application_Model_Preference::getTuneinEnabled()) {
$filePropelOrm = $file->getPropelOrm();
$title = urlencode($filePropelOrm->getDbTrackTitle());
$artist = urlencode($filePropelOrm->getDbArtistName());
Application_Common_TuneIn::sendMetadataToTunein($title, $artist);
}
} }
} else { } else {
// webstream // webstream

View file

@ -56,14 +56,19 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetStationLogo($imagePath); Application_Model_Preference::SetStationLogo($imagePath);
} }
Application_Model_Preference::SetUploadToSoundcloudOption($values["UploadToSoundcloudOption"]); Application_Model_Preference::setTuneinEnabled($values["enable_tunein"]);
Application_Model_Preference::setTuneinStationId($values["tunein_station_id"]);
Application_Model_Preference::setTuneinPartnerKey($values["tunein_partner_key"]);
Application_Model_Preference::setTuneinPartnerId($values["tunein_partner_id"]);
/*Application_Model_Preference::SetUploadToSoundcloudOption($values["UploadToSoundcloudOption"]);
Application_Model_Preference::SetSoundCloudDownloadbleOption($values["SoundCloudDownloadbleOption"]); Application_Model_Preference::SetSoundCloudDownloadbleOption($values["SoundCloudDownloadbleOption"]);
Application_Model_Preference::SetSoundCloudUser($values["SoundCloudUser"]); Application_Model_Preference::SetSoundCloudUser($values["SoundCloudUser"]);
Application_Model_Preference::SetSoundCloudPassword($values["SoundCloudPassword"]); Application_Model_Preference::SetSoundCloudPassword($values["SoundCloudPassword"]);
Application_Model_Preference::SetSoundCloudTags($values["SoundCloudTags"]); Application_Model_Preference::SetSoundCloudTags($values["SoundCloudTags"]);
Application_Model_Preference::SetSoundCloudGenre($values["SoundCloudGenre"]); Application_Model_Preference::SetSoundCloudGenre($values["SoundCloudGenre"]);
Application_Model_Preference::SetSoundCloudTrackType($values["SoundCloudTrackType"]); Application_Model_Preference::SetSoundCloudTrackType($values["SoundCloudTrackType"]);
Application_Model_Preference::SetSoundCloudLicense($values["SoundCloudLicense"]); Application_Model_Preference::SetSoundCloudLicense($values["SoundCloudLicense"]);*/
$this->view->statusMsg = "<div class='success'>". _("Preferences updated.")."</div>"; $this->view->statusMsg = "<div class='success'>". _("Preferences updated.")."</div>";
$this->view->form = $form; $this->view->form = $form;

View file

@ -21,6 +21,10 @@ class Application_Form_Preferences extends Zend_Form
$this->addSubForm($general_pref, 'preferences_general'); $this->addSubForm($general_pref, 'preferences_general');
//tunein form
$tuneinPreferences = new Application_Form_TuneInPreferences();
$this->addSubForm($tuneinPreferences, 'preferences_tunein');
$soundcloud_pref = new Application_Form_SoundcloudPreferences(); $soundcloud_pref = new Application_Form_SoundcloudPreferences();
$this->addSubForm($soundcloud_pref, 'preferences_soundcloud'); $this->addSubForm($soundcloud_pref, 'preferences_soundcloud');

View file

@ -0,0 +1,44 @@
<?php
require_once 'customvalidators/ConditionalNotEmpty.php';
class Application_Form_TuneInPreferences extends Zend_Form_SubForm
{
public function init()
{
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/preferences_tunein.phtml'))
));
$enableTunein = new Zend_Form_Element_Checkbox("enable_tunein");
$enableTunein->setLabel(_("Push metadata to your station on TuneIn?"));
$enableTunein->setValue(Application_Model_Preference::getTuneinEnabled());
$enableTunein->setAttrib("class", "block-display");
$this->addElement($enableTunein);
// TODO: figure out how to make this validator work
$validator = new ConditionalNotEmpty(array(
'enable_tunein' => 1
));
$tuneinStationId = new Zend_Form_Element_Text("tunein_station_id");
$tuneinStationId->setLabel(_("Station ID:"));
$tuneinStationId->setValue(Application_Model_Preference::getTuneinStationId());
$tuneinStationId->setAttrib("class", "input_text");
$tuneinStationId->addValidator($validator);
$this->addElement($tuneinStationId);
$tuneinPartnerKey = new Zend_Form_Element_Text("tunein_partner_key");
$tuneinPartnerKey->setLabel(_("Partner Key:"));
$tuneinPartnerKey->setValue(Application_Model_Preference::getTuneinPartnerKey());
$tuneinPartnerKey->setAttrib("class", "input_text");
$tuneinPartnerKey->addValidator($validator);
$this->addElement($tuneinPartnerKey);
$tuneinPartnerId = new Zend_Form_Element_Text("tunein_partner_id");
$tuneinPartnerId->setLabel(_("Partner Id:"));
$tuneinPartnerId->setValue(Application_Model_Preference::getTuneinPartnerId());
$tuneinPartnerId->setAttrib("class", "input_text");
$tuneinPartnerId->addValidator($validator);
$this->addElement($tuneinPartnerId);
}
}

View file

@ -1453,4 +1453,44 @@ class Application_Model_Preference
{ {
return self::getValue("provisioning_status"); return self::getValue("provisioning_status");
} }
public static function setTuneinEnabled($value)
{
self::setValue("tunein_enabled", $value);
}
public static function getTuneinEnabled()
{
return self::getValue("tunein_enabled");
}
public static function setTuneinPartnerKey($value)
{
self::setValue("tunein_partner_key", $value);
}
public static function getTuneinPartnerKey()
{
return self::getValue("tunein_partner_key");
}
public static function setTuneinPartnerId($value)
{
self::setValue("tunein_partner_id", $value);
}
public static function getTuneinPartnerId()
{
return self::getValue("tunein_partner_id");
}
public static function setTuneinStationId($value)
{
self::setValue("tunein_station_id", $value);
}
public static function getTuneinStationId()
{
return self::getValue("tunein_station_id");
}
} }

View file

@ -4,6 +4,11 @@
<?php echo $this->element->getSubform('preferences_general') ?> <?php echo $this->element->getSubform('preferences_general') ?>
<?php //No soundcloud stuff on Airtime Pro -- Albert ?> <?php //No soundcloud stuff on Airtime Pro -- Albert ?>
<h3 class="collapsible-header" id="tunein-pref-heading"><span class="arrow-icon"></span><?php echo _("TuneIn Settings"); ?></h3>
<div class="collapsible-content" id="tunein-settings">
<?php echo $this->element->getSubform('preferences_tunein') ?>
</div>
<?php echo $this->element->submit->render() ?> <?php echo $this->element->submit->render() ?>
</form> </form>

View file

@ -0,0 +1,11 @@
<fieldset class="padded">
<dl class="zend_form">
<?php echo $this->element->getElement('enable_tunein')->render() ?>
<?php echo $this->element->getElement('tunein_station_id')->render() ?>
<?php echo $this->element->getElement('tunein_partner_key')->render() ?>
<?php echo $this->element->getElement('tunein_partner_id')->render() ?>
</dl>
</fieldset>

View file

@ -63,6 +63,30 @@ function setMailServerInputReadonly() {
setMsAuthenticationFieldsReadonly(requiresAuthCB); setMsAuthenticationFieldsReadonly(requiresAuthCB);
} }
function setTuneInSettingsListener() {
var enableTunein = $("#enable_tunein");
enableTunein.click(function(event){
setTuneInSettingsReadonly();
});
}
function setTuneInSettingsReadonly() {
var enableTunein = $("#enable_tunein");
var stationId = $("#tunein_station_id");
var partnerKey = $("#tunein_partner_key");
var partnerId = $("#tunein_partner_id");
if (enableTunein.is(':checked')) {
stationId.removeAttr("readonly");
partnerKey.removeAttr("readonly");
partnerId.removeAttr("readonly");
} else {
stationId.attr("readonly", "readonly");
partnerKey.attr("readonly", "readonly");
partnerId.attr("readonly", "readonly");
}
}
/* /*
* Enable/disable mail server authentication fields * Enable/disable mail server authentication fields
*/ */
@ -151,4 +175,6 @@ $(document).ready(function() {
setConfigureMailServerListener(); setConfigureMailServerListener();
setEnableSystemEmailsListener(); setEnableSystemEmailsListener();
setCollapsibleWidgetJsCode(); setCollapsibleWidgetJsCode();
setTuneInSettingsReadonly();
setTuneInSettingsListener();
}); });