From fefc53c000cab5f23c0621b591e4424bfc700a0b Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Thu, 16 Mar 2017 16:48:31 -0400 Subject: [PATCH 1/3] basic podcast album override option in preferences --- .../controllers/PreferenceController.php | 1 + .../application/forms/GeneralPreferences.php | 23 +++++++++++++++++++ airtime_mvc/application/models/Preference.php | 16 ++++++++++++- .../services/PodcastEpisodeService.php | 1 + .../scripts/form/preferences_general.phtml | 2 ++ .../airtime-celery/airtime-celery/tasks.py | 9 ++++++-- 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 44c32d8fa..8e66c31a7 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -45,6 +45,7 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]); Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]); Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]); + Application_Model_Preference::SetPodcastAlbumOverride($values["podcastAlbumOverride"]); Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]); Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]); Application_Model_Preference::SetDefaultLocale($values["locale"]); diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index a87b7fa12..f580a0d2a 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -100,6 +100,25 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm '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
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->setLabel(_('Public Airtime API')); $third_party_api->setDescription(_('Required for embeddable schedule widget.')); @@ -125,6 +144,10 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $allowedCorsUrls->setValue($allowedCorsUrlsValue); $this->addElement($allowedCorsUrls); + + + + $locale = new Zend_Form_Element_Select("locale"); $locale->setLabel(_("Default Language")); $locale->setMultiOptions(Application_Model_Locale::getLocales()); diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 17f6d69be..18d3aee9c 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -358,13 +358,27 @@ class Application_Model_Preference { self::setValue("third_party_api", $bool); } - + + public static function GetAllow3rdPartyApi() { $val = self::getValue("third_party_api"); 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) { self::setValue("phone", $phone); diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index 4f5628464..6a85f3b12 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -150,6 +150,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir 'callback_url' => $stationUrl . 'rest/media', 'api_key' => $CC_CONFIG["apiKey"][0], 'podcast_name' => $title, + 'album_override' => Application_Model_Preference::GetPodcastAlbumOverride(), ); $task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data); // Get the created ThirdPartyTaskReference and set the episode ID so diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index dbae3e2da..61dbfeabe 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -31,6 +31,8 @@ element->getElement('stationDefaultCrossfadeDuration')->render() ?> + element->getElement('podcastAlbumOverride')->render() ?> + element->getElement('thirdPartyApi')->render() ?> element->getElement('allowedCorsUrls')->render() ?> diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index d838b54b6..018109a23 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -130,7 +130,7 @@ def soundcloud_delete(token, track_id): @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 @@ -138,7 +138,8 @@ def podcast_download(id, url, callback_url, api_key, podcast_name): :param url: download url for the episode :param callback_url: callback URL to send the downloaded file to :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 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 m = MP3(audiofile.name, ID3=EasyID3) 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: m['album'] except KeyError: logger.debug('setting new album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore'))) 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() filetypeinfo = m.pprint() logger.info('filetypeinfo is {0}'.format(filetypeinfo.encode('ascii', 'ignore'))) From ae4c9203e66b3985070cfc3f1664d67877210180 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Fri, 17 Mar 2017 02:10:04 +0100 Subject: [PATCH 2/3] Refactor override preference Properly defaults the preference to be true and always return a boolean value since that is what celery will be expecting. --- .../application/forms/GeneralPreferences.php | 4 --- airtime_mvc/application/models/Preference.php | 7 ++--- .../airtime-celery/airtime-celery/tasks.py | 29 +++++++++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index f580a0d2a..c6ec16aae 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -144,10 +144,6 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $allowedCorsUrls->setValue($allowedCorsUrlsValue); $this->addElement($allowedCorsUrls); - - - - $locale = new Zend_Form_Element_Select("locale"); $locale->setLabel(_("Default Language")); $locale->setMultiOptions(Application_Model_Locale::getLocales()); diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 18d3aee9c..e6474af4e 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -358,8 +358,7 @@ class Application_Model_Preference { self::setValue("third_party_api", $bool); } - - + public static function GetAllow3rdPartyApi() { $val = self::getValue("third_party_api"); @@ -374,11 +373,9 @@ class Application_Model_Preference public static function GetPodcastAlbumOverride() { $val = self::getValue("podcast_album_override"); - return (strlen($val) == 0 ) ? "1" : $val; + return $val === '1' ? true : false; } - - public static function SetPhone($phone) { self::setValue("phone", $phone); diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index 018109a23..10b8ca2d1 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -157,15 +157,10 @@ def podcast_download(id, url, callback_url, api_key, podcast_name, album_overrid # currently hardcoded for mp3s may want to add support for oggs etc m = MP3(audiofile.name, ID3=EasyID3) 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: - m['album'] - except KeyError: - logger.debug('setting new album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore'))) - 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 + + # replace album title as needed + m = podcast_override_album(m, podcast_name, album_override) + m.save() filetypeinfo = m.pprint() logger.info('filetypeinfo is {0}'.format(filetypeinfo.encode('ascii', 'ignore'))) @@ -181,6 +176,22 @@ def podcast_download(id, url, callback_url, api_key, podcast_name, album_overrid obj['status'] = 0 return json.dumps(obj) +def podcast_override_album(m, podcast_name, override): + """ + Override m['album'] if empty or forced with override arg + """ + # if the album override option is enabled replace the album id3 tag with the podcast name even if the album tag contains data + if override is True: + logger.debug('overriding album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore'))) + m['album'] = podcast_name + else: + # replace the album id3 tag with the podcast name if the album tag is empty + try: + m['album'] + except KeyError: + logger.debug('setting new album name to {0} in podcast'.format(podcast_name.encode('ascii', 'ignore'))) + m['album'] = podcast_name + return m def get_filename(r): """ From 8a8c54c21febe2607ffc931a278cbbd640ab7562 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Fri, 17 Mar 2017 02:28:45 +0100 Subject: [PATCH 3/3] Remove redundant call to setDescription --- airtime_mvc/application/forms/GeneralPreferences.php | 1 - 1 file changed, 1 deletion(-) diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index c6ec16aae..d7ac46f37 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -103,7 +103,6 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $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"),