CC-5884: Modify Pypo -> Download files from cloud storage
This commit is contained in:
parent
d2e8325258
commit
c2411b6f41
5 changed files with 77 additions and 18 deletions
|
@ -724,7 +724,7 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri)
|
||||
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri, $filesize, $object_name, $isInCloud)
|
||||
{
|
||||
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
||||
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
||||
|
@ -756,6 +756,9 @@ SQL;
|
|||
'show_name' => $item["show_name"],
|
||||
'replay_gain' => $replay_gain,
|
||||
'independent_event' => $independent_event,
|
||||
'filesize' => $filesize,
|
||||
'object_name' => $object_name,
|
||||
'is_in_cloud' => $isInCloud
|
||||
);
|
||||
|
||||
if ($schedule_item['cue_in'] > $schedule_item['cue_out']) {
|
||||
|
@ -889,7 +892,10 @@ SQL;
|
|||
$media_id = $item['file_id'];
|
||||
$storedFile = Application_Model_StoredFile::RecallById($media_id);
|
||||
$uri = $storedFile->getFilePath();
|
||||
self::createFileScheduleEvent($data, $item, $media_id, $uri);
|
||||
$object_name = $storedFile->getResourceId();
|
||||
$filesize = $storedFile->getFileSize();
|
||||
$isInCloud = $storedFile->isInCloud();
|
||||
self::createFileScheduleEvent($data, $item, $media_id, $uri, $filesize, $object_name, $isInCloud);
|
||||
}
|
||||
elseif (!is_null($item['stream_id'])) {
|
||||
//row is type "webstream"
|
||||
|
|
|
@ -473,7 +473,7 @@ SQL;
|
|||
|
||||
$mime = $this->_file->getDbMime();
|
||||
|
||||
if ($mime == "audio/ogg" || $mime == "application/ogg") {
|
||||
if ($mime == "audio/ogg" || $mime == "application/ogg" || $mime == "audio/vorbis") {
|
||||
return "ogg";
|
||||
} elseif ($mime == "audio/mp3" || $mime == "audio/mpeg") {
|
||||
return "mp3";
|
||||
|
@ -495,15 +495,20 @@ SQL;
|
|||
{
|
||||
assert($this->_file);
|
||||
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->
|
||||
_file->getDbDirectory());
|
||||
if (!$music_dir) {
|
||||
throw new Exception("Invalid music_dir for file in database.");
|
||||
if ($this->isInCloud()) {
|
||||
return $this->getCloudUrl();
|
||||
} else {
|
||||
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->
|
||||
_file->getDbDirectory());
|
||||
if (!$music_dir) {
|
||||
throw new Exception("Invalid music_dir for file in database.");
|
||||
}
|
||||
$directory = $music_dir->getDirectory();
|
||||
$filepath = $this->_file->getDbFilepath();
|
||||
|
||||
return Application_Common_OsPath::join($directory, $filepath);
|
||||
}
|
||||
$directory = $music_dir->getDirectory();
|
||||
$filepath = $this->_file->getDbFilepath();
|
||||
|
||||
return Application_Common_OsPath::join($directory, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -555,7 +560,37 @@ SQL;
|
|||
{
|
||||
return $baseUrl."api/get-media/file/".$this->getId().".".$this->getFileExtension();
|
||||
}
|
||||
|
||||
public function isInCloud()
|
||||
{
|
||||
$location = CcMusicDirsQuery::create()->findPk($this->_file->getDbDirectory());
|
||||
if ($location->getType() == "cloud") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCloudUrl()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
return $CC_CONFIG["s3"]["host"]."/".$CC_CONFIG["s3"]["bucket"]."/" . urlencode($this->getResourceId());
|
||||
}
|
||||
|
||||
public function getResourceId()
|
||||
{
|
||||
return $this->_file->getDbResourceId();
|
||||
}
|
||||
|
||||
public function getFileSize()
|
||||
{
|
||||
if ($this->isInCloud()) {
|
||||
//TODO: error checking - 403 forbidden>
|
||||
return strlen(file_get_contents($this->getCloudUrl()));
|
||||
} else {
|
||||
return filesize($this->getFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
public static function Insert($md, $con)
|
||||
{
|
||||
// save some work by checking if filepath is given right away
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue