SAAS-503: PYPO -> Use the REST API to download files
Removed Amazon S3 specific code
This commit is contained in:
parent
bf91677f91
commit
e1f1807f5a
3 changed files with 43 additions and 20 deletions
|
@ -771,9 +771,8 @@ SQL;
|
||||||
* @param Array $item schedule info about one track
|
* @param Array $item schedule info about one track
|
||||||
* @param Integer $media_id scheduled item's cc_files id
|
* @param Integer $media_id scheduled item's cc_files id
|
||||||
* @param String $uri path to the scheduled item's physical location
|
* @param String $uri path to the scheduled item's physical location
|
||||||
* @param String $amazonS3ResourceId scheduled item's Amazon S3 resource id, if applicable
|
|
||||||
*/
|
*/
|
||||||
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri, $amazonS3ResourceId)
|
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri, $downloadURL, $filesize)
|
||||||
{
|
{
|
||||||
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
||||||
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
||||||
|
@ -807,11 +806,10 @@ SQL;
|
||||||
'end' => $end,
|
'end' => $end,
|
||||||
'show_name' => $item["show_name"],
|
'show_name' => $item["show_name"],
|
||||||
'replay_gain' => $replay_gain,
|
'replay_gain' => $replay_gain,
|
||||||
'independent_event' => $independent_event
|
'independent_event' => $independent_event,
|
||||||
|
'download_url' => $downloadURL,
|
||||||
|
'filesize' => $filesize,
|
||||||
);
|
);
|
||||||
if (!is_null($amazonS3ResourceId)) {
|
|
||||||
$schedule_item["amazonS3_resource_id"] = $amazonS3ResourceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($schedule_item['cue_in'] > $schedule_item['cue_out']) {
|
if ($schedule_item['cue_in'] > $schedule_item['cue_out']) {
|
||||||
$schedule_item['cue_in'] = $schedule_item['cue_out'];
|
$schedule_item['cue_in'] = $schedule_item['cue_out'];
|
||||||
|
@ -945,9 +943,11 @@ SQL;
|
||||||
$storedFile = Application_Model_StoredFile::RecallById($media_id);
|
$storedFile = Application_Model_StoredFile::RecallById($media_id);
|
||||||
$file = $storedFile->getPropelOrm();
|
$file = $storedFile->getPropelOrm();
|
||||||
$uri = $file->getAbsoluteFilePath();
|
$uri = $file->getAbsoluteFilePath();
|
||||||
|
// TODO: fix this URL
|
||||||
|
$downloadURL = "http://localhost/rest/media/$media_id/download";
|
||||||
|
$filesize = $file->getFileSize();
|
||||||
|
|
||||||
$amazonS3ResourceId = $file->getResourceId();
|
self::createFileScheduleEvent($data, $item, $media_id, $uri, $downloadURL, $filesize);
|
||||||
self::createFileScheduleEvent($data, $item, $media_id, $uri, $amazonS3ResourceId);
|
|
||||||
}
|
}
|
||||||
elseif (!is_null($item['stream_id'])) {
|
elseif (!is_null($item['stream_id'])) {
|
||||||
//row is type "webstream"
|
//row is type "webstream"
|
||||||
|
|
|
@ -85,7 +85,7 @@ class CloudFile extends BaseCloudFile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Deletes the file from Amazon S3
|
* Deletes the file from cloud storage
|
||||||
*/
|
*/
|
||||||
public function deletePhysicalFile()
|
public function deletePhysicalFile()
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,10 +9,14 @@ import shutil
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import stat
|
import stat
|
||||||
|
import urllib2
|
||||||
|
import base64
|
||||||
|
import ConfigParser
|
||||||
|
|
||||||
from std_err_override import LogWriter
|
from std_err_override import LogWriter
|
||||||
|
|
||||||
|
CONFIG_PATH = '/etc/airtime/airtime.conf'
|
||||||
|
|
||||||
# configure logging
|
# configure logging
|
||||||
logging.config.fileConfig("logging.cfg")
|
logging.config.fileConfig("logging.cfg")
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -38,11 +42,14 @@ class PypoFile(Thread):
|
||||||
src = media_item['uri']
|
src = media_item['uri']
|
||||||
dst = media_item['dst']
|
dst = media_item['dst']
|
||||||
|
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
src_size = os.path.getsize(src)
|
src_size = os.path.getsize(src)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error("Could not get size of source file: %s", src)
|
self.logger.error("Could not get size of source file: %s", src)
|
||||||
return
|
return
|
||||||
|
"""
|
||||||
|
src_size = media_item['filesize']
|
||||||
|
|
||||||
dst_exists = True
|
dst_exists = True
|
||||||
try:
|
try:
|
||||||
|
@ -68,7 +75,18 @@ class PypoFile(Thread):
|
||||||
"""
|
"""
|
||||||
copy will overwrite dst if it already exists
|
copy will overwrite dst if it already exists
|
||||||
"""
|
"""
|
||||||
shutil.copy(src, dst)
|
#shutil.copy(src, dst)
|
||||||
|
config = self.read_config_file(CONFIG_PATH)
|
||||||
|
CONFIG_SECTION = "general"
|
||||||
|
username = config.get(CONFIG_SECTION, 'api_key')
|
||||||
|
url = media_item['download_url']
|
||||||
|
|
||||||
|
"""
|
||||||
|
Make HTTP request here
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open(dst, "wb") as code:
|
||||||
|
code.write(file.read())
|
||||||
|
|
||||||
#make file world readable
|
#make file world readable
|
||||||
os.chmod(dst, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|
os.chmod(dst, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||||
|
@ -108,6 +126,19 @@ class PypoFile(Thread):
|
||||||
|
|
||||||
return media_item
|
return media_item
|
||||||
|
|
||||||
|
def read_config_file(self, config_path):
|
||||||
|
"""Parse the application's config file located at config_path."""
|
||||||
|
config = ConfigParser.SafeConfigParser()
|
||||||
|
try:
|
||||||
|
config.readfp(open(config_path))
|
||||||
|
except IOError as e:
|
||||||
|
logging.debug("Failed to open config file at %s: %s" % (config_path, e.strerror))
|
||||||
|
sys.exit()
|
||||||
|
except Exception:
|
||||||
|
logging.debug(e.strerror)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
while True:
|
while True:
|
||||||
|
@ -133,14 +164,6 @@ class PypoFile(Thread):
|
||||||
|
|
||||||
media_item = self.get_highest_priority_media_item(self.media)
|
media_item = self.get_highest_priority_media_item(self.media)
|
||||||
if media_item is not None:
|
if media_item is not None:
|
||||||
"""
|
|
||||||
If an object_name exists the file is stored on Amazon S3
|
|
||||||
"""
|
|
||||||
if 'amazonS3_resource_id' in media_item:
|
|
||||||
csd = CloudStorageDownloader()
|
|
||||||
csd.download_obj(media_item['dst'], media_item['amazonS3_resource_id'])
|
|
||||||
media_item['file_ready'] = True
|
|
||||||
else:
|
|
||||||
self.copy_file(media_item)
|
self.copy_file(media_item)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue