basic podcast album override option in preferences

This commit is contained in:
Robb Ebright 2017-03-16 16:48:31 -04:00
parent c7187f997f
commit fefc53c000
6 changed files with 49 additions and 3 deletions

View File

@ -45,6 +45,7 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]); Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]);
Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]); Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]);
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]); Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
Application_Model_Preference::SetPodcastAlbumOverride($values["podcastAlbumOverride"]);
Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]); Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]);
Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]); Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]);
Application_Model_Preference::SetDefaultLocale($values["locale"]); Application_Model_Preference::SetDefaultLocale($values["locale"]);

View File

@ -100,6 +100,25 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
'value' => $defaultFadeOut, 'value' => $defaultFadeOut,
)); ));
$podcast_album_override = new Zend_Form_Element_Radio('podcastAlbumOverride');
$podcast_album_override->setLabel(_('Podcast Album Override'));
$podcast_album_override->setDescription(_('Always replace downloaded podcast track album with podcast name.'));
$podcast_album_override->setMultiOptions(array(
_("Disabled"),
_("Enabled"),
));
$podcast_album_override->setValue(Application_Model_Preference::GetPodcastAlbumOverride());
$podcast_album_override->setDescription(_('Enabling this means that podcast tracks will always contain the podcast name in their album field.'));
$podcast_album_override->setSeparator(' '); //No <br> between radio buttons
//$third_party_api->addDecorator(new Zend_Form_Decorator_Label(array('tag' => 'dd', 'class' => 'radio-inline-list')));
$podcast_album_override->addDecorator('HtmlTag', array('tag' => 'dd',
'id'=>"podcastAlbumOverride-element",
'class' => 'radio-inline-list',
));
$this->addElement($podcast_album_override);
$third_party_api = new Zend_Form_Element_Radio('thirdPartyApi'); $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');
$third_party_api->setLabel(_('Public Airtime API')); $third_party_api->setLabel(_('Public Airtime API'));
$third_party_api->setDescription(_('Required for embeddable schedule widget.')); $third_party_api->setDescription(_('Required for embeddable schedule widget.'));
@ -125,6 +144,10 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
$allowedCorsUrls->setValue($allowedCorsUrlsValue); $allowedCorsUrls->setValue($allowedCorsUrlsValue);
$this->addElement($allowedCorsUrls); $this->addElement($allowedCorsUrls);
$locale = new Zend_Form_Element_Select("locale"); $locale = new Zend_Form_Element_Select("locale");
$locale->setLabel(_("Default Language")); $locale->setLabel(_("Default Language"));
$locale->setMultiOptions(Application_Model_Locale::getLocales()); $locale->setMultiOptions(Application_Model_Locale::getLocales());

View File

@ -358,13 +358,27 @@ class Application_Model_Preference
{ {
self::setValue("third_party_api", $bool); self::setValue("third_party_api", $bool);
} }
public static function GetAllow3rdPartyApi() public static function GetAllow3rdPartyApi()
{ {
$val = self::getValue("third_party_api"); $val = self::getValue("third_party_api");
return (strlen($val) == 0 ) ? "1" : $val; return (strlen($val) == 0 ) ? "1" : $val;
} }
public static function SetPodcastAlbumOverride($bool)
{
self::setValue("podcast_album_override", $bool);
}
public static function GetPodcastAlbumOverride()
{
$val = self::getValue("podcast_album_override");
return (strlen($val) == 0 ) ? "1" : $val;
}
public static function SetPhone($phone) public static function SetPhone($phone)
{ {
self::setValue("phone", $phone); self::setValue("phone", $phone);

View File

@ -150,6 +150,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
'callback_url' => $stationUrl . 'rest/media', 'callback_url' => $stationUrl . 'rest/media',
'api_key' => $CC_CONFIG["apiKey"][0], 'api_key' => $CC_CONFIG["apiKey"][0],
'podcast_name' => $title, 'podcast_name' => $title,
'album_override' => Application_Model_Preference::GetPodcastAlbumOverride(),
); );
$task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data); $task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data);
// Get the created ThirdPartyTaskReference and set the episode ID so // Get the created ThirdPartyTaskReference and set the episode ID so

View File

@ -31,6 +31,8 @@
<?php echo $this->element->getElement('stationDefaultCrossfadeDuration')->render() ?> <?php echo $this->element->getElement('stationDefaultCrossfadeDuration')->render() ?>
<?php echo $this->element->getElement('podcastAlbumOverride')->render() ?>
<?php echo $this->element->getElement('thirdPartyApi')->render() ?> <?php echo $this->element->getElement('thirdPartyApi')->render() ?>
<?php echo $this->element->getElement('allowedCorsUrls')->render() ?> <?php echo $this->element->getElement('allowedCorsUrls')->render() ?>

View File

@ -130,7 +130,7 @@ def soundcloud_delete(token, track_id):
@celery.task(name='podcast-download', acks_late=True) @celery.task(name='podcast-download', acks_late=True)
def podcast_download(id, url, callback_url, api_key, podcast_name): def podcast_download(id, url, callback_url, api_key, podcast_name, album_override):
""" """
Download a podcast episode Download a podcast episode
@ -138,7 +138,8 @@ def podcast_download(id, url, callback_url, api_key, podcast_name):
:param url: download url for the episode :param url: download url for the episode
:param callback_url: callback URL to send the downloaded file to :param callback_url: callback URL to send the downloaded file to
:param api_key: API key for callback authentication :param api_key: API key for callback authentication
:param podcast_name: NAme of podcast to be added to id3 metadata for smartblock :param podcast_name: Name of podcast to be added to id3 metadata for smartblock
:param album_override: Passing whether to override the album id3 even if it exists
:return: JSON formatted string of a dictionary of download statuses :return: JSON formatted string of a dictionary of download statuses
and file identifiers (for successful uploads) and file identifiers (for successful uploads)
@ -156,11 +157,15 @@ def podcast_download(id, url, callback_url, api_key, podcast_name):
# currently hardcoded for mp3s may want to add support for oggs etc # currently hardcoded for mp3s may want to add support for oggs etc
m = MP3(audiofile.name, ID3=EasyID3) m = MP3(audiofile.name, ID3=EasyID3)
logger.debug('podcast_download loaded mp3 {0}'.format(audiofile.name)) logger.debug('podcast_download loaded mp3 {0}'.format(audiofile.name))
# replace the album id3 tag with the podcast name if the album tag is empty
try: try:
m['album'] m['album']
except KeyError: except KeyError:
logger.debug('setting new album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore'))) logger.debug('setting new album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore')))
m['album'] = podcast_name m['album'] = podcast_name
# if the album override option is enabled replace the album id3 tag with the podcast name even if the album tag contains data
if album_override is True:
m['album'] = podcast_name
m.save() m.save()
filetypeinfo = m.pprint() filetypeinfo = m.pprint()
logger.info('filetypeinfo is {0}'.format(filetypeinfo.encode('ascii', 'ignore'))) logger.info('filetypeinfo is {0}'.format(filetypeinfo.encode('ascii', 'ignore')))