diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 606acae00..d156dd5f6 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -895,9 +895,11 @@ SQL; //row is from "file" $media_id = $item['file_id']; $storedFile = Application_Model_StoredFile::RecallById($media_id); - $uri = $storedFile->getFilePath(); + $file = $storedFile->getPropelOrm(); + $uri = $file->getAbsoluteFilePath(); + $object_name = null; - if ($storedFile->getPropelOrm() instanceof CloudFile) { + if ($file instanceof CloudFile) { $object_name = $storedFile->getResourceId(); } $filesize = $storedFile->getFileSize(); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 3bf35899a..f035e616d 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -491,7 +491,7 @@ SQL; { assert($this->_file); - return $this->_file->getAbsoluteFilePath(); + return $this->_file->getURLForTrackPreviewOrDownload(); } /** diff --git a/airtime_mvc/application/models/airtime/CcFiles.php b/airtime_mvc/application/models/airtime/CcFiles.php index 9d40aef66..8bc02a25f 100644 --- a/airtime_mvc/application/models/airtime/CcFiles.php +++ b/airtime_mvc/application/models/airtime/CcFiles.php @@ -82,6 +82,11 @@ class CcFiles extends BaseCcFiles { return $info['filename']; } + public function getURLForTrackPreviewOrDownload() + { + return $this->getAbsoluteFilePath(); + } + public function getAbsoluteFilePath() { $music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory()); diff --git a/airtime_mvc/application/models/airtime/CloudFile.php b/airtime_mvc/application/models/airtime/CloudFile.php index 414933e11..cba99055d 100644 --- a/airtime_mvc/application/models/airtime/CloudFile.php +++ b/airtime_mvc/application/models/airtime/CloudFile.php @@ -16,37 +16,50 @@ require_once 'Amazon_S3.php'; class CloudFile extends BaseCloudFile { - public function getAbsoluteFilePath() + public function getURLForTrackPreviewOrDownload() { - return $this->get_s3_signed_url(); + return $this->getAbsoluteFilePath()."?".$this->getAuthenticationParams(); } - private function get_s3_signed_url() + /** + * + * Enter description here ... + */ + public function getAbsoluteFilePath() { - //should be longer than track length - $expires = 120; + $amazon_s3 = new Amazon_S3(); + $zend_s3 = $amazon_s3->getZendServiceAmazonS3(); $resource_id = $this->getResourceId(); - + $endpoint = $zend_s3->getEndpoint(); + $scheme = $endpoint->getScheme(); + $host = $endpoint->getHost(); + $s3_bucket = $amazon_s3->getBucket(); + return "$scheme://$host/$s3_bucket/".utf8_encode($resource_id); + } + + /** + * + * Returns a string of authentication paramaters to append to the cloud + * object's URL. We need this for track preview and download because the + * objects are privately stored on Amazon S3. + */ + public function getAuthenticationParams() + { + $expires = time()+120; + $resource_id = $this->getResourceId(); + $amazon_s3 = new Amazon_S3(); $s3_bucket = $amazon_s3->getBucket(); $s3_secret_key = $amazon_s3->getSecretKey(); $s3_access_key = $amazon_s3->getAccessKey(); - $zend_s3 = $amazon_s3->getZendServiceAmazonS3(); - - $expires = time()+$expires; + $string_to_sign = utf8_encode("GET\n\n\n$expires\n/$s3_bucket/$resource_id"); // We need to urlencode the entire signature in case the hashed signature // has spaces. (NOTE: utf8_encode() does not work here because it turns // spaces into non-breaking spaces) $signature = urlencode(base64_encode((hash_hmac("sha1", $string_to_sign, $s3_secret_key, true)))); - $authentication_params = "AWSAccessKeyId=$s3_access_key&Expires=$expires&Signature=$signature"; - - $endpoint = $zend_s3->getEndpoint(); - $scheme = $endpoint->getScheme(); - $host = $endpoint->getHost(); - $url = "$scheme://$host/$s3_bucket/".utf8_encode($resource_id)."?$authentication_params"; - return $url; + return "AWSAccessKeyId=$s3_access_key&Expires=$expires&Signature=$signature"; } public function getFileSize() @@ -71,7 +84,7 @@ class CloudFile extends BaseCloudFile { $ch = curl_init(); curl_setopt_array($ch, array( - CURLOPT_URL => $this->getAbsoluteFilePath(), + CURLOPT_URL => $this->getURLForTrackPreviewOrDownload(), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => false diff --git a/python_apps/pypo/cloud_storage_downloader.py b/python_apps/pypo/cloud_storage_downloader.py index 01a9a1ee7..6304c7fbb 100644 --- a/python_apps/pypo/cloud_storage_downloader.py +++ b/python_apps/pypo/cloud_storage_downloader.py @@ -28,8 +28,11 @@ class CloudStorageDownloader: except ObjectDoesNotExistError: logging.info("Could not find object: %s" % obj_name) - logging.info('Downloading: %s to %s' % (cloud_obj.name, dst)) - cloud_obj.download(destination_path=dst) + if os.path.isfile(dst) == False: + logging.info('Downloading: %s to %s' % (cloud_obj.name, dst)) + cloud_obj.download(destination_path=dst) + else: + logging.info("Skipping download because %s already exists" % dst) def read_config_file(self, config_path): """Parse the application's config file located at config_path."""