From 04333aaa299cc90456a4ca40308ba086956f80be Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Thu, 16 Jul 2015 11:27:27 -0400 Subject: [PATCH 1/4] SoundCloud download initial commit --- .../controllers/ThirdPartyController.php | 13 ++++++++ .../services/SoundcloudService.php | 5 +++ .../services/ThirdPartyCeleryService.php | 32 ++++++++++++++++++- .../services/ThirdPartyService.php | 7 ++++ .../airtime-celery/airtime-celery/tasks.py | 27 +++++++++++++++- 5 files changed, 82 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/controllers/ThirdPartyController.php b/airtime_mvc/application/controllers/ThirdPartyController.php index 5c15ae5ea..090156ee1 100644 --- a/airtime_mvc/application/controllers/ThirdPartyController.php +++ b/airtime_mvc/application/controllers/ThirdPartyController.php @@ -77,6 +77,19 @@ abstract class ThirdPartyController extends Zend_Controller_Action { $this->_service->upload($id); } + /** + * Download the file with the given id from a third-party service + * + * @return void + * + * @throws Zend_Controller_Response_Exception thrown if download fails for any reason + */ + public function downloadAction() { + $request = $this->getRequest(); + $id = $request->getParam('id'); + $this->_service->download($id); + } + /** * Delete the file with the given id from a third-party service * diff --git a/airtime_mvc/application/services/SoundcloudService.php b/airtime_mvc/application/services/SoundcloudService.php index 8e946375e..91b2ab941 100644 --- a/airtime_mvc/application/services/SoundcloudService.php +++ b/airtime_mvc/application/services/SoundcloudService.php @@ -29,6 +29,11 @@ class SoundcloudService extends ThirdPartyCeleryService implements OAuth2 { */ protected static $_CELERY_UPLOAD_TASK_NAME = 'soundcloud-upload'; + /** + * @var string celery task name for third party uploads + */ + protected static $_CELERY_DOWNLOAD_TASK_NAME = 'soundcloud-download'; + /** * @var string celery task name for third party deletions */ diff --git a/airtime_mvc/application/services/ThirdPartyCeleryService.php b/airtime_mvc/application/services/ThirdPartyCeleryService.php index 5dbc1ebad..78b0a09ce 100644 --- a/airtime_mvc/application/services/ThirdPartyCeleryService.php +++ b/airtime_mvc/application/services/ThirdPartyCeleryService.php @@ -14,6 +14,11 @@ abstract class ThirdPartyCeleryService extends ThirdPartyService { */ protected static $_CELERY_UPLOAD_TASK_NAME; + /** + * @var string celery task name for third-party uploads + */ + protected static $_CELERY_DOWNLOAD_TASK_NAME; + /** * @var string celery task name for third-party deletion */ @@ -41,6 +46,31 @@ abstract class ThirdPartyCeleryService extends ThirdPartyService { } } + /** + * Given a SoundCloud track identifier, download a track from SoundCloud. + * + * If no track identifier is given, download all tracks for the currently + * authenticated SoundCloud user. + * + * @param int|null $trackId a SoundCloud track identifier + */ + public function download($trackId = null) { + $namespace = new Zend_Session_Namespace('csrf_namespace'); + $csrfToken = $namespace->authtoken; + $data = array( + 'callback_url' => 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . '/media/post>csrf_token=' . $csrfToken, + 'token' => $this->_accessToken, + 'track_id' => $trackId + ); + try { + CeleryService::sendCeleryMessage(static::$_CELERY_DOWNLOAD_TASK_NAME, + static::$_CELERY_EXCHANGE_NAME, + $data); + } catch (Exception $e) { + Logging::info("Invalid request: " . $e->getMessage()); + } + } + /** * Delete the file with the given identifier from a third-party service * @@ -52,7 +82,7 @@ abstract class ThirdPartyCeleryService extends ThirdPartyService { public function delete($fileId) { $serviceId = $this->getServiceId($fileId); if ($serviceId == 0) { - throw new ServiceNotFoundException("No service found for file with ID $fileId"); + throw new ServiceNotFoundException("No service ID found for file with ID $fileId"); } $data = array( 'token' => $this->_accessToken, diff --git a/airtime_mvc/application/services/ThirdPartyService.php b/airtime_mvc/application/services/ThirdPartyService.php index 5af1eb0e4..d3293f18c 100644 --- a/airtime_mvc/application/services/ThirdPartyService.php +++ b/airtime_mvc/application/services/ThirdPartyService.php @@ -124,6 +124,13 @@ abstract class ThirdPartyService { */ abstract function upload($fileId); + /** + * Download the file with the given identifier from a third-party service + * + * @param int $trackId the third-party service track identifier + */ + abstract function download($trackId); + /** * Delete the file with the given identifier from a third-party service * diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index 27554241a..ad5fa64af 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -1,6 +1,7 @@ import os import json import urllib2 +import requests import soundcloud from celery import Celery from celery.utils.log import get_task_logger @@ -33,12 +34,36 @@ def soundcloud_upload(data, token, file_path): data['asset_data'].close() return json.dumps(track.fields()) + +@celery.task(name='soundcloud-download', acks_late=True) +def soundcloud_download(token, callback_url, track_id=None): + """ + + :param token: OAuth2 client access token + :param track_id: SoundCloud track identifier + :rtype: None + """ + client = soundcloud.Client(access_token=token) + try: + tracks = client.get('/me/tracks') if track_id is None else {client.get('/tracks/%s' % track_id)} + for track in tracks: + if track.downloadable: + track_file = client.get(track.download_url) + with track_file as f: + requests.post(callback_url, data=f) + except Exception as e: + logger.info('Error during file download: {0}'.format(e.message)) + logger.info(str(e)) + raise e + + @celery.task(name='soundcloud-delete', acks_late=True) def soundcloud_delete(token, track_id): """ Delete a file from SoundCloud - :param token: OAuth2 client access token + :param token: OAuth2 client access token + :param track_id: SoundCloud track identifier :return: the SoundCloud response object :rtype: dict From 63784d4e6b38705d3329b0ba1b90e9adfa374e74 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Tue, 8 Sep 2015 16:39:33 -0400 Subject: [PATCH 2/4] Fix some behaviour with playlist/smartblock fade button --- .../application/views/scripts/playlist/playlist.phtml | 6 +++--- .../application/views/scripts/playlist/smart-block.phtml | 4 ++-- airtime_mvc/public/js/airtime/library/spl.js | 8 ++++---- python_apps/airtime-celery/airtime-celery/tasks.py | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/views/scripts/playlist/playlist.phtml b/airtime_mvc/application/views/scripts/playlist/playlist.phtml index c7b490455..b9f107aae 100644 --- a/airtime_mvc/application/views/scripts/playlist/playlist.phtml +++ b/airtime_mvc/application/views/scripts/playlist/playlist.phtml @@ -43,10 +43,10 @@ if (isset($this->obj)) {
-
"> - +
diff --git a/airtime_mvc/application/views/scripts/playlist/smart-block.phtml b/airtime_mvc/application/views/scripts/playlist/smart-block.phtml index e4a5d6553..c24df6a63 100644 --- a/airtime_mvc/application/views/scripts/playlist/smart-block.phtml +++ b/airtime_mvc/application/views/scripts/playlist/smart-block.phtml @@ -51,8 +51,8 @@ if (isset($this->obj)) {
form->getElement('shuffle_button');?>
-
"> - + diff --git a/airtime_mvc/public/js/airtime/library/spl.js b/airtime_mvc/public/js/airtime/library/spl.js index 89d6db9bd..c6c97adcc 100644 --- a/airtime_mvc/public/js/airtime/library/spl.js +++ b/airtime_mvc/public/js/airtime/library/spl.js @@ -406,7 +406,7 @@ var AIRTIME = (function(AIRTIME){ var empty = $pl.find(".spl_empty"); if (!show || empty.length > 0) { - $pl.find("#spl_crossfade").hide(); + //$pl.find("#spl_crossfade").hide(); } else { //get list of playlist contents var list = contents.children(); @@ -416,7 +416,7 @@ var AIRTIME = (function(AIRTIME){ var last = list.last(); if (first.find(':first-child').children().attr('blockid') !== undefined && last.find(':first-child').children().attr('blockid') !== undefined) { - $pl.find("#spl_crossfade").hide(); + //$pl.find("#spl_crossfade").hide(); } else { $pl.find("#spl_crossfade").show(); } @@ -783,7 +783,7 @@ var AIRTIME = (function(AIRTIME){ fadeIn.parent().prev().hide(); fadeIn.hide(); } else { - console.log(json.fadeIn); + //console.log(json.fadeIn); //console.log(fadeIn.val()); fadeIn.parent().prev().show(); fadeIn.show(); @@ -1095,7 +1095,7 @@ var AIRTIME = (function(AIRTIME){ aSelected = AIRTIME.library.getSelectedData(); for (i = 0, length = aSelected.length; i < length; i++) { - console.log(aSelected[i]); + //console.log(aSelected[i]); aItems.push(new Array(aSelected[i].id, aSelected[i].ftype)); } diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index ad5fa64af..74ce00fb3 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -38,6 +38,7 @@ def soundcloud_upload(data, token, file_path): @celery.task(name='soundcloud-download', acks_late=True) def soundcloud_download(token, callback_url, track_id=None): """ + This is in stasis :param token: OAuth2 client access token :param track_id: SoundCloud track identifier From 8c65ba8f66ae0d6cf4eaa73e3f9f913fa0ea4947 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 14 Sep 2015 18:26:28 -0400 Subject: [PATCH 3/4] SAAS-1061 - implement podcast list view skeleton; small bugfixes Conflicts: airtime_mvc/public/js/airtime/library/library.js --- airtime_mvc/application/Bootstrap.php | 1 + airtime_mvc/application/airtime-boot.php | 2 + airtime_mvc/application/common/enum/Enum.php | 47 +++ .../application/common/enum/MediaType.php | 14 + .../application/layouts/scripts/layout.phtml | 22 +- airtime_mvc/application/models/StoredFile.php | 12 +- .../partialviews/dashboard-sub-nav.php | 30 ++ .../scripts/showbuilder/builderDialog.phtml | 25 +- .../views/scripts/showbuilder/index.phtml | 1 + .../public/ajax/library_placeholders.json | 28 -- airtime_mvc/public/css/dashboard.css | 12 + airtime_mvc/public/css/styles.css | 2 +- .../library/events/library_showbuilder.js | 28 +- .../public/js/airtime/library/library.js | 366 +++++++++++------- .../public/js/airtime/library/plupload.js | 127 ++---- .../js/airtime/showbuilder/main_builder.js | 22 +- 16 files changed, 406 insertions(+), 333 deletions(-) create mode 100644 airtime_mvc/application/common/enum/Enum.php create mode 100644 airtime_mvc/application/common/enum/MediaType.php create mode 100644 airtime_mvc/application/views/scripts/partialviews/dashboard-sub-nav.php delete mode 100644 airtime_mvc/public/ajax/library_placeholders.json diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 26a6843c7..e64c74136 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -31,6 +31,7 @@ require_once "Auth.php"; require_once "interface/OAuth2.php"; require_once "TaskManager.php"; require_once "UsabilityHints.php"; +require_once "MediaType.php"; require_once __DIR__.'/models/formatters/LengthFormatter.php'; require_once __DIR__.'/services/CeleryService.php'; require_once __DIR__.'/services/SoundcloudService.php'; diff --git a/airtime_mvc/application/airtime-boot.php b/airtime_mvc/application/airtime-boot.php index 08a5b9869..5ed3cb4bc 100644 --- a/airtime_mvc/application/airtime-boot.php +++ b/airtime_mvc/application/airtime-boot.php @@ -36,6 +36,8 @@ set_include_path(implode(PATH_SEPARATOR, array( ))); set_include_path(APPLICATION_PATH . 'common' . PATH_SEPARATOR . get_include_path()); +set_include_path(APPLICATION_PATH . 'common/enum' . PATH_SEPARATOR . get_include_path()); +set_include_path(APPLICATION_PATH . 'common/interface' . PATH_SEPARATOR . get_include_path()); //Propel classes. set_include_path(APPLICATION_PATH . 'models' . PATH_SEPARATOR . get_include_path()); diff --git a/airtime_mvc/application/common/enum/Enum.php b/airtime_mvc/application/common/enum/Enum.php new file mode 100644 index 000000000..b0d34fbc3 --- /dev/null +++ b/airtime_mvc/application/common/enum/Enum.php @@ -0,0 +1,47 @@ +getConstants(); + } + return self::$constCacheArray[$calledClass]; + } + + public static function isValidName($name, $strict = false) { + $constants = self::getConstants(); + + if ($strict) { + return array_key_exists($name, $constants); + } + + $keys = array_map('strtolower', array_keys($constants)); + return in_array(strtolower($name), $keys); + } + + public static function isValidValue($value) { + $values = array_values(self::getConstants()); + return in_array($value, $values, $strict = true); + } + + public static function getDefault() { + return static::__default; + } + +} \ No newline at end of file diff --git a/airtime_mvc/application/common/enum/MediaType.php b/airtime_mvc/application/common/enum/MediaType.php new file mode 100644 index 000000000..69843c0d7 --- /dev/null +++ b/airtime_mvc/application/common/enum/MediaType.php @@ -0,0 +1,14 @@ + - +
- -
-
-
-
-
-
-
-
+ + + +