2010-12-07 20:19:27 +01:00
< ? php
2012-02-24 15:07:04 +01:00
require_once 'formatters/LengthFormatter.php' ;
2012-02-24 18:22:07 +01:00
require_once 'formatters/SamplerateFormatter.php' ;
require_once 'formatters/BitrateFormatter.php' ;
2012-02-24 15:07:04 +01:00
2010-12-07 20:19:27 +01:00
/**
2011-09-22 18:24:17 +02:00
* Application_Model_StoredFile class
2010-12-07 20:19:27 +01:00
*
2011-01-05 18:19:58 +01:00
* @ package Airtime
2010-12-07 20:19:27 +01:00
* @ subpackage StorageServer
* @ copyright 2010 Sourcefabric O . P . S .
* @ license http :// www . gnu . org / licenses / gpl . txt
* @ see MetaData
*/
2012-07-16 03:17:13 +02:00
class Application_Model_StoredFile
{
2010-12-07 20:19:27 +01:00
/**
2011-06-08 10:15:35 +02:00
* @ holds propel database object
*/
private $_file ;
2010-12-07 20:19:27 +01:00
/**
2011-06-08 10:15:35 +02:00
* array of db metadata -> propel
2010-12-07 20:19:27 +01:00
*/
2011-06-08 10:15:35 +02:00
private $_dbMD = array (
2012-08-23 16:21:39 +02:00
" track_title " => " DbTrackTitle " ,
" artist_name " => " DbArtistName " ,
" album_title " => " DbAlbumTitle " ,
" genre " => " DbGenre " ,
" mood " => " DbMood " ,
2011-06-08 10:15:35 +02:00
" track_number " => " DbTrackNumber " ,
2012-08-23 16:21:39 +02:00
" bpm " => " DbBpm " ,
" label " => " DbLabel " ,
" composer " => " DbComposer " ,
" encoded_by " => " DbEncodedBy " ,
" conductor " => " DbConductor " ,
" year " => " DbYear " ,
" info_url " => " DbInfoUrl " ,
" isrc_number " => " DbIsrcNumber " ,
" copyright " => " DbCopyright " ,
" length " => " DbLength " ,
" bit_rate " => " DbBitRate " ,
" sample_rate " => " DbSampleRate " ,
" mime " => " DbMime " ,
2012-09-12 17:10:25 +02:00
//"md5" => "DbMd5",
2012-08-23 16:21:39 +02:00
" ftype " => " DbFtype " ,
" language " => " DbLanguage " ,
" replay_gain " => " DbReplayGain " ,
2012-08-23 22:46:35 +02:00
" directory " => " DbDirectory " ,
2013-01-03 20:02:06 +01:00
" owner_id " => " DbOwnerId " ,
" cuein " => " DbCueIn " ,
" cueout " => " DbCueOut " ,
2011-06-08 10:15:35 +02:00
);
2011-06-08 11:59:48 +02:00
public function getId ()
{
2011-06-08 10:15:35 +02:00
return $this -> _file -> getDbId ();
}
2010-12-07 20:19:27 +01:00
2011-06-08 11:59:48 +02:00
public function getFormat ()
{
return $this -> _file -> getDbFtype ();
}
2012-07-16 03:17:13 +02:00
public function getPropelOrm ()
{
2011-06-20 20:10:33 +02:00
return $this -> _file ;
}
2011-06-08 11:59:48 +02:00
public function setFormat ( $p_format )
{
$this -> _file -> setDbFtype ( $p_format );
}
2012-08-29 16:58:03 +02:00
2012-07-20 00:07:39 +02:00
/* This function is only called after liquidsoap
* has notified that a track has started playing .
*/
public function setLastPlayedTime ( $p_now )
{
$this -> _file -> setDbLPtime ( $p_now );
/* Normally we would only call save after all columns have been set
2012-08-29 16:58:03 +02:00
* like in setDbColMetadata () . But since we are only setting one
2012-07-20 00:07:39 +02:00
* column in this case it is OK .
*/
$this -> _file -> save ();
}
2011-06-08 11:59:48 +02:00
2012-09-12 00:22:46 +02:00
public static function createWithFile ( $f ) {
$storedFile = new Application_Model_StoredFile ();
$storedFile -> _file = $f ;
return $storedFile ;
}
2010-12-07 20:19:27 +01:00
/**
2011-06-08 10:15:35 +02:00
* Set multiple metadata values using defined metadata constants .
2010-12-07 20:19:27 +01:00
*
2011-06-08 10:15:35 +02:00
* @ param array $p_md
* example : $p_md [ 'MDATA_KEY_URL' ] = 'http://www.fake.com'
2010-12-07 20:19:27 +01:00
*/
2012-02-28 19:47:57 +01:00
public function setMetadata ( $p_md = null )
2010-12-07 20:19:27 +01:00
{
2011-06-08 10:15:35 +02:00
if ( is_null ( $p_md )) {
$this -> setDbColMetadata ();
2012-07-16 03:17:13 +02:00
} else {
2011-06-08 10:15:35 +02:00
$dbMd = array ();
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
if ( isset ( $p_md [ " MDATA_KEY_YEAR " ])) {
2012-09-19 23:39:30 +02:00
// We need to make sure to clean this value before
// inserting into database. If value is outside of range
// [-2^31, 2^31-1] then postgresl will throw error when
// trying to retrieve this value. We could make sure
// number is within these bounds, but simplest is to do
// substring to 4 digits (both values are garbage, but
// at least our new garbage value won't cause errors).
// If the value is 2012-01-01, then substring to first 4
// digits is an OK result. CC-3771
2012-07-11 00:51:32 +02:00
2012-06-04 17:43:41 +02:00
$year = $p_md [ " MDATA_KEY_YEAR " ];
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
if ( strlen ( $year ) > 4 ) {
2012-06-04 17:43:41 +02:00
$year = substr ( $year , 0 , 4 );
}
2012-07-16 03:17:13 +02:00
if ( ! is_numeric ( $year )) {
2012-06-04 17:43:41 +02:00
$year = 0 ;
}
$p_md [ " MDATA_KEY_YEAR " ] = $year ;
}
2012-07-11 00:51:32 +02:00
2012-08-27 20:07:05 +02:00
# Translate metadata attributes from media monitor (MDATA_KEY_*)
# to their counterparts in constants.php (usually the column names)
2013-01-10 17:49:02 +01:00
$track_length = $p_md [ 'MDATA_KEY_DURATION' ];
$track_length_in_sec = Application_Common_DateHelper :: calculateLengthInSeconds ( $track_length );
2011-06-08 10:15:35 +02:00
foreach ( $p_md as $mdConst => $mdValue ) {
2012-07-16 03:17:13 +02:00
if ( defined ( $mdConst )) {
2013-01-15 17:16:50 +01:00
if ( $mdConst == " MDATA_KEY_CUE_OUT " ) {
if ( $mdValue == '0.0' ) {
$mdValue = $track_length_in_sec ;
} else {
$this -> _file -> setDbSilanCheck ( true ) -> save ();
}
2013-01-10 17:49:02 +01:00
}
2012-05-15 21:17:19 +02:00
$dbMd [ constant ( $mdConst )] = $mdValue ;
2013-01-10 17:49:02 +01:00
2012-08-27 20:03:22 +02:00
} else {
2012-08-27 20:51:35 +02:00
Logging :: warn ( " using metadata that is not defined.
2012-08-27 20:03:22 +02:00
[ $mdConst ] => [ $mdValue ] " );
2012-05-15 21:17:19 +02:00
}
2011-06-08 10:15:35 +02:00
}
$this -> setDbColMetadata ( $dbMd );
2010-12-07 20:19:27 +01:00
}
}
2011-06-08 10:15:35 +02:00
/**
* Set multiple metadata values using database columns as indexes .
*
* @ param array $p_md
* example : $p_md [ 'url' ] = 'http://www.fake.com'
*/
2012-02-28 19:47:57 +01:00
public function setDbColMetadata ( $p_md = null )
2010-12-07 20:19:27 +01:00
{
2011-06-08 10:15:35 +02:00
if ( is_null ( $p_md )) {
foreach ( $this -> _dbMD as $dbColumn => $propelColumn ) {
$method = " set $propelColumn " ;
$this -> _file -> $method ( null );
}
2012-07-16 03:17:13 +02:00
} else {
2012-08-24 18:38:33 +02:00
$owner = $this -> _file -> getFkOwner ();
2012-08-29 16:58:03 +02:00
// if owner_id is already set we don't want to set it again.
if ( ! $owner ) { // no owner detected, we try to assign one.
// if MDATA_OWNER_ID is not set then we default to the
2012-08-23 22:46:35 +02:00
// first admin user we find
2012-08-27 21:09:55 +02:00
if ( ! array_key_exists ( 'owner_id' , $p_md )) {
2012-08-24 18:38:33 +02:00
//$admins = Application_Model_User::getUsers(array('A'));
$admins = Application_Model_User :: getUsersOfType ( 'A' );
2012-08-23 22:46:35 +02:00
if ( count ( $admins ) > 0 ) { // found admin => pick first one
$owner = $admins [ 0 ];
}
}
// get the user by id and set it like that
else {
2012-08-24 16:20:23 +02:00
$user = CcSubjsQuery :: create ()
2012-08-27 21:09:55 +02:00
-> findPk ( $p_md [ 'owner_id' ]);
2012-08-23 22:46:35 +02:00
if ( $user ) {
$owner = $user ;
}
}
2012-08-29 16:58:03 +02:00
if ( $owner ) {
2012-08-24 18:38:33 +02:00
$this -> _file -> setDbOwnerId ( $owner -> getDbId () );
2012-08-29 16:58:03 +02:00
} else {
2012-08-24 18:38:33 +02:00
Logging :: info ( " Could not find suitable owner for file
2012-11-07 18:05:20 +01:00
'".$p_md[' filepath ']."' " );
2012-08-23 22:46:35 +02:00
}
}
2012-08-27 21:09:55 +02:00
# We don't want to process owner_id in bulk because we already
# processed it in the code above. This is done because owner_id
# needs special handling
if ( array_key_exists ( 'owner_id' , $p_md )) {
unset ( $p_md [ 'owner_id' ]);
}
2011-06-08 10:15:35 +02:00
foreach ( $p_md as $dbColumn => $mdValue ) {
2012-08-24 18:38:33 +02:00
// don't blank out name, defaults to original filename on first
// insertion to database.
2012-07-16 03:17:13 +02:00
if ( $dbColumn == " track_title " && ( is_null ( $mdValue ) || $mdValue == " " )) {
2011-06-15 09:19:41 +02:00
continue ;
}
2012-10-03 18:01:24 +02:00
# TODO : refactor string evals
2011-06-21 10:24:02 +02:00
if ( isset ( $this -> _dbMD [ $dbColumn ])) {
$propelColumn = $this -> _dbMD [ $dbColumn ];
2012-08-23 22:46:35 +02:00
$method = " set $propelColumn " ;
2012-10-16 21:56:03 +02:00
/* We need to set track_number to null if it is an empty string
* because propel defaults empty strings to zeros */
if ( $dbColumn == " track_number " && empty ( $mdValue )) $mdValue = null ;
2011-06-21 10:24:02 +02:00
$this -> _file -> $method ( $mdValue );
}
2011-06-08 10:15:35 +02:00
}
2010-12-07 20:19:27 +01:00
}
2012-07-20 00:11:31 +02:00
2012-07-20 00:07:39 +02:00
$this -> _file -> setDbMtime ( new DateTime ( " now " , new DateTimeZone ( " UTC " )));
2011-06-08 10:15:35 +02:00
$this -> _file -> save ();
2010-12-07 20:19:27 +01:00
}
/**
* Set metadata element value
*
* @ param string $category
2012-07-11 00:51:32 +02:00
* Metadata element by metadata constant
2010-12-07 20:19:27 +01:00
* @ param string $value
2012-07-11 00:51:32 +02:00
* value to store , if NULL then delete record
2010-12-07 20:19:27 +01:00
*/
public function setMetadataValue ( $p_category , $p_value )
{
2011-07-15 23:35:16 +02:00
// constant() was used because it gets quoted constant name value from
// api_client.py. This is the wrapper funtion
2011-06-08 10:15:35 +02:00
$this -> setDbColMetadataValue ( constant ( $p_category ), $p_value );
2010-12-07 20:19:27 +01:00
}
/**
2011-06-08 10:15:35 +02:00
* Set metadata element value
2010-12-07 20:19:27 +01:00
*
2011-06-08 10:15:35 +02:00
* @ param string $category
2012-07-11 00:51:32 +02:00
* Metadata element by db column
2011-06-08 10:15:35 +02:00
* @ param string $value
2012-07-11 00:51:32 +02:00
* value to store , if NULL then delete record
2010-12-07 20:19:27 +01:00
*/
2011-06-08 10:15:35 +02:00
public function setDbColMetadataValue ( $p_category , $p_value )
2010-12-07 20:19:27 +01:00
{
2011-06-15 09:19:41 +02:00
//don't blank out name, defaults to original filename on first insertion to database.
2012-07-16 03:17:13 +02:00
if ( $p_category == " track_title " && ( is_null ( $p_value ) || $p_value == " " )) {
2011-06-15 09:19:41 +02:00
return ;
}
2011-07-15 23:35:16 +02:00
if ( isset ( $this -> _dbMD [ $p_category ])) {
2012-09-11 22:25:45 +02:00
// TODO : fix this crust -- RG
2011-06-21 10:24:02 +02:00
$propelColumn = $this -> _dbMD [ $p_category ];
$method = " set $propelColumn " ;
$this -> _file -> $method ( $p_value );
$this -> _file -> save ();
}
2010-12-07 20:19:27 +01:00
}
2011-06-08 10:15:35 +02:00
/**
* Get metadata as array , indexed by the column names in the database .
*
* @ return array
*/
public function getDbColMetadata ()
2010-12-07 20:19:27 +01:00
{
2011-06-08 10:15:35 +02:00
$md = array ();
foreach ( $this -> _dbMD as $dbColumn => $propelColumn ) {
$method = " get $propelColumn " ;
$md [ $dbColumn ] = $this -> _file -> $method ();
2010-12-07 23:29:28 +01:00
}
2011-06-08 10:15:35 +02:00
return $md ;
2010-12-07 20:19:27 +01:00
}
2011-06-15 14:20:14 +02:00
/**
* Get metadata as array , indexed by the constant names .
*
* @ return array
*/
public function getMetadata ()
{
$c = get_defined_constants ( true );
$md = array ();
2012-07-11 00:51:32 +02:00
/* Create a copy of dbMD here and create a " filepath " key inside of
2012-05-04 18:02:42 +02:00
* it . The reason we do this here , instead of creating this key inside
2012-07-11 00:51:32 +02:00
* dbMD is because " filepath " isn 't really metadata, and we don' t want
2012-05-04 18:02:42 +02:00
* filepath updated everytime the metadata changes . Also it needs extra
2012-07-11 00:51:32 +02:00
* processing before we can write it to the database ( needs to be split
2012-05-04 18:02:42 +02:00
* into base and relative path )
* */
$dbmd_copy = $this -> _dbMD ;
$dbmd_copy [ " filepath " ] = " DbFilepath " ;
2011-06-15 14:20:14 +02:00
foreach ( $c [ 'user' ] as $constant => $value ) {
if ( preg_match ( '/^MDATA_KEY/' , $constant )) {
2012-05-04 18:02:42 +02:00
if ( isset ( $dbmd_copy [ $value ])) {
2012-08-23 16:21:39 +02:00
$propelColumn = $dbmd_copy [ $value ];
$method = " get $propelColumn " ;
2012-05-04 18:47:29 +02:00
$md [ $constant ] = $this -> _file -> $method ();
2011-06-15 14:20:14 +02:00
}
}
}
return $md ;
}
2010-12-07 20:19:27 +01:00
/**
* Returns an array of playlist objects that this file is a part of .
* @ return array
*/
2012-07-16 03:17:13 +02:00
public function getPlaylists ()
{
2012-04-01 21:51:03 +02:00
$con = Propel :: getConnection ();
2012-09-04 23:21:59 +02:00
2012-09-11 22:20:59 +02:00
$sql = <<< SQL
SELECT playlist_id
FROM cc_playlist
WHERE file_id = : file_id
SQL ;
2012-09-04 23:21:59 +02:00
$stmt = $con -> prepare ( $sql );
$stmt -> bindParam ( ':file_id' , $this -> id , PDO :: PARAM_INT );
if ( $stmt -> execute ()) {
$ids = $stmt -> fetchAll ();
} else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
}
2010-12-07 20:19:27 +01:00
if ( is_array ( $ids ) && count ( $ids ) > 0 ) {
2012-09-11 22:20:59 +02:00
return array_map ( function ( $id ) {
return Application_Model_Playlist :: Recall ( $id );
}, $ids );
} else {
return array ();
2010-12-07 20:19:27 +01:00
}
}
/**
2011-06-08 11:59:48 +02:00
* Delete stored virtual file
2010-12-07 20:19:27 +01:00
*
2011-06-08 11:59:48 +02:00
* @ param boolean $p_deleteFile
*
2010-12-07 20:19:27 +01:00
*/
2012-11-02 22:49:32 +01:00
public function delete ()
2010-12-07 20:19:27 +01:00
{
2011-07-19 11:00:32 +02:00
2012-02-06 11:07:10 +01:00
$filepath = $this -> getFilePath ();
2011-06-08 11:59:48 +02:00
// Check if the file is scheduled to be played in the future
2011-09-23 22:50:00 +02:00
if ( Application_Model_Schedule :: IsFileScheduledInTheFuture ( $this -> getId ())) {
2012-02-05 18:19:22 +01:00
throw new DeleteScheduledFileException ();
2011-06-08 11:59:48 +02:00
}
2011-07-18 15:28:17 +02:00
2012-10-31 21:51:29 +01:00
$userInfo = Zend_Auth :: getInstance () -> getStorage () -> read ();
$user = new Application_Model_User ( $userInfo -> id );
$isAdminOrPM = $user -> isUserType ( array ( UTYPE_ADMIN , UTYPE_PROGRAM_MANAGER ));
if ( ! $isAdminOrPM && $this -> getFileOwnerId () != $user -> getId ()) {
throw new FileNoPermissionException ();
}
2012-06-28 19:28:45 +02:00
$music_dir = Application_Model_MusicDir :: getDirByPK ( $this -> _file -> getDbDirectory ());
$type = $music_dir -> getType ();
2012-07-11 00:51:32 +02:00
2012-06-28 19:28:45 +02:00
if ( file_exists ( $filepath ) && $type == " stor " ) {
2012-02-05 18:19:22 +01:00
$data = array ( " filepath " => $filepath , " delete " => 1 );
Application_Model_RabbitMq :: SendMessageToMediaMonitor ( " file_delete " , $data );
2010-12-07 20:19:27 +01:00
}
2012-11-07 17:21:36 +01:00
2012-11-20 21:10:38 +01:00
// set hidden flag to true
2012-11-03 06:33:13 +01:00
$this -> _file -> setDbHidden ( true );
2012-04-12 22:17:19 +02:00
$this -> _file -> save ();
2012-11-06 16:58:25 +01:00
// need to explicitly update any playlist's and block's length
// that contains the file getting deleted
$fileId = $this -> _file -> getDbId ();
$plRows = CcPlaylistcontentsQuery :: create () -> filterByDbFileId () -> find ();
foreach ( $plRows as $row ) {
$pl = CcPlaylistQuery :: create () -> filterByDbId ( $row -> getDbPlaylistId ( $fileId )) -> findOne ();
$pl -> setDbLength ( $pl -> computeDbLength ( Propel :: getConnection ( CcPlaylistPeer :: DATABASE_NAME )));
$pl -> save ();
}
$blRows = CcBlockcontentsQuery :: create () -> filterByDbFileId ( $fileId ) -> find ();
foreach ( $blRows as $row ) {
$bl = CcBlockQuery :: create () -> filterByDbId ( $row -> getDbBlockId ()) -> findOne ();
$bl -> setDbLength ( $bl -> computeDbLength ( Propel :: getConnection ( CcBlockPeer :: DATABASE_NAME )));
$bl -> save ();
}
2012-04-12 22:17:19 +02:00
}
2012-07-11 00:51:32 +02:00
2012-04-12 22:17:19 +02:00
/**
* This function is for when media monitor detects deletion of file
* and trying to update airtime side
*
* @ param boolean $p_deleteFile
*
*/
public function deleteByMediaMonitor ( $deleteFromPlaylist = false )
{
$filepath = $this -> getFilePath ();
2010-12-07 20:19:27 +01:00
2012-07-16 03:17:13 +02:00
if ( $deleteFromPlaylist ) {
2012-04-12 22:17:19 +02:00
Application_Model_Playlist :: DeleteFileFromAllPlaylists ( $this -> getId ());
}
2012-08-27 22:49:45 +02:00
// set file_exists flag to false
2012-02-05 18:19:22 +01:00
$this -> _file -> setDbFileExists ( false );
$this -> _file -> save ();
2010-12-07 20:19:27 +01:00
}
2012-09-18 18:04:54 +02:00
public function getRealFileExtension () {
$path = $this -> _file -> getDbFilepath ();
$path_elements = explode ( '.' , $path );
if ( count ( $path_elements ) < 2 ) {
return " " ;
} else {
return $path_elements [ count ( $path_elements ) - 1 ];
}
}
2010-12-07 20:19:27 +01:00
/**
2011-06-08 11:59:48 +02:00
* Return suitable extension .
2010-12-07 20:19:27 +01:00
*
* @ return string
2012-07-11 00:51:32 +02:00
* file extension without a dot
2010-12-07 20:19:27 +01:00
*/
2011-06-08 11:59:48 +02:00
public function getFileExtension ()
2010-12-07 20:19:27 +01:00
{
2012-09-18 18:04:54 +02:00
$possible_ext = $this -> getRealFileExtension ();
if ( $possible_ext !== " " ) {
return $possible_ext ;
}
2012-09-18 18:08:30 +02:00
// We fallback to guessing the extension from the mimetype if we
// cannot extract it from the file name
2011-06-08 11:59:48 +02:00
$mime = $this -> _file -> getDbMime ();
2010-12-07 20:19:27 +01:00
2012-09-17 22:40:27 +02:00
if ( $mime == " audio/ogg " || $mime == " application/ogg " ) {
2011-06-08 11:59:48 +02:00
return " ogg " ;
2012-07-16 03:17:13 +02:00
} elseif ( $mime == " audio/mp3 " || $mime == " audio/mpeg " ) {
2011-06-08 11:59:48 +02:00
return " mp3 " ;
2012-09-08 00:23:14 +02:00
} elseif ( $mime == " audio/x-flac " ) {
2012-09-05 20:33:49 +02:00
return " flac " ;
2012-09-11 20:04:45 +02:00
} elseif ( $mime == " audio/mp4 " ) {
return " mp4 " ;
2013-01-03 20:02:06 +01:00
} else {
2012-09-08 00:23:14 +02:00
throw new Exception ( " Unknown $mime " );
2011-06-08 11:59:48 +02:00
}
2011-06-08 10:15:35 +02:00
}
2010-12-07 20:19:27 +01:00
/**
* Get real filename of raw media data
*
* @ return string
*/
2011-06-08 11:59:48 +02:00
public function getFilePath ()
2012-01-17 11:18:17 +01:00
{
2012-08-24 17:09:38 +02:00
$music_dir = Application_Model_MusicDir :: getDirByPK ( $this ->
_file -> getDbDirectory ());
2011-12-22 23:21:18 +01:00
$directory = $music_dir -> getDirectory ();
2012-08-24 17:09:38 +02:00
$filepath = $this -> _file -> getDbFilepath ();
2012-08-29 16:58:03 +02:00
2012-08-27 22:49:45 +02:00
return Application_Common_OsPath :: join ( $directory , $filepath );
2011-06-21 10:24:02 +02:00
}
2012-07-11 00:51:32 +02:00
2011-06-21 10:24:02 +02:00
/**
* Set real filename of raw media data
*
* @ return string
*/
public function setFilePath ( $p_filepath )
{
2011-09-22 18:24:17 +02:00
$path_info = Application_Model_MusicDir :: splitFilePath ( $p_filepath );
2012-01-17 11:18:17 +01:00
2011-06-21 10:24:02 +02:00
if ( is_null ( $path_info )) {
return - 1 ;
}
2011-09-22 18:24:17 +02:00
$musicDir = Application_Model_MusicDir :: getDirByPath ( $path_info [ 0 ]);
2011-06-21 10:24:02 +02:00
$this -> _file -> setDbDirectory ( $musicDir -> getId ());
$this -> _file -> setDbFilepath ( $path_info [ 1 ]);
$this -> _file -> save ();
2010-12-07 20:19:27 +01:00
}
/**
2011-10-14 00:07:53 +02:00
* Get the URL to access this file using the server name / address that
* this PHP script was invoked through .
2010-12-07 20:19:27 +01:00
*/
public function getFileUrl ()
2011-09-22 21:31:21 +02:00
{
2011-09-09 17:45:19 +02:00
$serverName = $_SERVER [ 'SERVER_NAME' ];
$serverPort = $_SERVER [ 'SERVER_PORT' ];
2011-12-01 11:16:29 +01:00
2011-10-17 13:36:16 +02:00
return $this -> constructGetFileUrl ( $serverName , $serverPort );
2011-10-14 00:07:53 +02:00
}
2011-12-01 11:16:29 +01:00
2011-10-14 00:07:53 +02:00
/**
* Get the URL to access this file using the server name / address that
2011-11-14 22:08:45 +01:00
* is specified in the airtime . conf config file . If either of these is
* not specified , then use values provided by the $_SERVER global variable .
2011-10-14 00:07:53 +02:00
*/
2012-07-16 03:17:13 +02:00
public function getFileUrlUsingConfigAddress ()
{
2013-01-14 22:16:14 +01:00
$CC_CONFIG = Config :: getConfig ();
2011-12-01 11:16:29 +01:00
2012-07-16 03:17:13 +02:00
if ( isset ( $CC_CONFIG [ 'baseUrl' ])) {
2011-11-14 22:08:45 +01:00
$serverName = $CC_CONFIG [ 'baseUrl' ];
} else {
$serverName = $_SERVER [ 'SERVER_NAME' ];
}
2011-12-01 11:16:29 +01:00
2012-07-16 03:17:13 +02:00
if ( isset ( $CC_CONFIG [ 'basePort' ])) {
2011-11-14 22:08:45 +01:00
$serverPort = $CC_CONFIG [ 'basePort' ];
} else {
$serverPort = $_SERVER [ 'SERVER_PORT' ];
}
2011-10-17 13:36:16 +02:00
return $this -> constructGetFileUrl ( $serverName , $serverPort );
2011-10-14 00:07:53 +02:00
}
2011-12-01 11:16:29 +01:00
2012-07-16 03:17:13 +02:00
private function constructGetFileUrl ( $p_serverName , $p_serverPort )
{
2012-07-22 22:12:34 +02:00
return " http:// $p_serverName : $p_serverPort /api/get-media/file/ " . $this -> getId () . " . " . $this -> getFileExtension ();
2011-06-09 11:50:03 +02:00
}
2011-06-22 22:50:58 +02:00
/**
* Sometimes we want a relative URL and not a full URL . See bug
* http :// dev . sourcefabric . org / browse / CC - 2403
*/
2011-06-24 22:04:57 +02:00
public function getRelativeFileUrl ( $baseUrl )
2011-06-22 22:50:58 +02:00
{
2013-01-14 22:00:38 +01:00
return $baseUrl . " api/get-media/file/ " . $this -> getId () . " . " . $this -> getFileExtension ();
2011-06-22 22:50:58 +02:00
}
2012-08-08 21:55:58 +02:00
public static function Insert ( $md )
2011-06-09 11:50:03 +02:00
{
2012-08-08 21:55:58 +02:00
// save some work by checking if filepath is given right away
2012-08-29 16:58:03 +02:00
if ( ! isset ( $md [ 'MDATA_KEY_FILEPATH' ]) ) {
return null ;
}
2012-08-08 21:55:58 +02:00
2011-06-09 11:50:03 +02:00
$file = new CcFiles ();
2012-08-24 17:09:38 +02:00
$now = new DateTime ( " now " , new DateTimeZone ( " UTC " ));
$file -> setDbUtime ( $now );
$file -> setDbMtime ( $now );
2011-06-09 11:50:03 +02:00
2011-09-22 18:24:17 +02:00
$storedFile = new Application_Model_StoredFile ();
2011-06-09 12:57:30 +02:00
$storedFile -> _file = $file ;
2012-08-08 21:55:58 +02:00
// removed "//" in the path. Always use '/' for path separator
2012-08-23 19:49:49 +02:00
// TODO : it might be better to just call OsPath::normpath on the file
// path. Also note that mediamonitor normalizes the paths anyway
// before passing them to php so it's not necessary to do this at all
2012-08-24 17:09:38 +02:00
2012-08-08 21:55:58 +02:00
$filepath = str_replace ( " // " , " / " , $md [ 'MDATA_KEY_FILEPATH' ]);
$res = $storedFile -> setFilePath ( $filepath );
if ( $res === - 1 ) {
2011-06-21 10:24:02 +02:00
return null ;
}
2012-08-08 21:55:58 +02:00
$storedFile -> setMetadata ( $md );
2012-08-29 16:58:03 +02:00
2012-08-08 21:55:58 +02:00
return $storedFile ;
2010-12-07 20:19:27 +01:00
}
2012-09-12 00:22:46 +02:00
public static function Recall ( $p_id = null , $p_gunid = null , $p_md5sum = null ,
$p_filepath = null ) {
2013-01-03 20:02:06 +01:00
if ( isset ( $p_id ) ) {
2012-09-12 00:22:46 +02:00
$f = CcFilesQuery :: create () -> findPK ( intval ( $p_id ));
return is_null ( $f ) ? null : self :: createWithFile ( $f );
2013-01-03 20:02:06 +01:00
} elseif ( isset ( $p_gunid ) ) {
2012-09-12 00:22:46 +02:00
throw new Exception ( " You should never use gunid ( $gunid ) anymore " );
} elseif ( isset ( $p_md5sum ) ) {
throw new Exception ( " Searching by md5( $p_md5sum ) is disabled " );
} elseif ( isset ( $p_filepath ) ) {
return is_null ( $f ) ? null : self :: createWithFile (
Application_Model_StoredFile :: RecallByFilepath ( $p_filepath ));
2012-07-16 03:17:13 +02:00
} else {
2012-09-12 00:22:46 +02:00
throw new Exception ( " No arguments passsed to Recall " );
2011-06-09 12:57:30 +02:00
}
2011-06-08 10:15:35 +02:00
}
2011-06-28 15:04:03 +02:00
2012-07-16 03:17:13 +02:00
public function getName ()
{
2011-06-27 17:23:48 +02:00
$info = pathinfo ( $this -> getFilePath ());
return $info [ 'filename' ];
}
2011-06-08 10:15:35 +02:00
/**
2011-09-22 18:24:17 +02:00
* Fetch the Application_Model_StoredFile by looking up its filepath .
2011-06-08 10:15:35 +02:00
*
2012-09-18 18:09:28 +02:00
* @ param string $p_filepath path of file stored in Airtime .
2011-09-22 18:24:17 +02:00
* @ return Application_Model_StoredFile | NULL
2011-06-08 10:15:35 +02:00
*/
public static function RecallByFilepath ( $p_filepath )
{
2012-09-12 00:22:46 +02:00
$path_info = Application_Model_MusicDir :: splitFilePath ( $p_filepath );
if ( is_null ( $path_info )) {
return null ;
}
$music_dir = Application_Model_MusicDir :: getDirByPath ( $path_info [ 0 ]);
$file = CcFilesQuery :: create ()
-> filterByDbDirectory ( $music_dir -> getId ())
-> filterByDbFilepath ( $path_info [ 1 ])
-> findOne ();
return is_null ( $file ) ? null : self :: createWithFile ( $file );
2011-06-08 10:15:35 +02:00
}
2011-12-01 11:16:29 +01:00
2012-07-16 03:17:13 +02:00
public static function RecallByPartialFilepath ( $partial_path )
{
2011-09-27 20:49:03 +02:00
$path_info = Application_Model_MusicDir :: splitFilePath ( $partial_path );
if ( is_null ( $path_info )) {
return null ;
}
$music_dir = Application_Model_MusicDir :: getDirByPath ( $path_info [ 0 ]);
$files = CcFilesQuery :: create ()
-> filterByDbDirectory ( $music_dir -> getId ())
-> filterByDbFilepath ( " $path_info[1] % " )
-> find ();
$res = array ();
2012-07-16 03:17:13 +02:00
foreach ( $files as $file ) {
2012-08-23 23:52:28 +02:00
$storedFile = new Application_Model_StoredFile ();
2011-09-27 20:49:03 +02:00
$storedFile -> _file = $file ;
2012-08-23 23:52:28 +02:00
$res [] = $storedFile ;
2011-09-27 20:49:03 +02:00
}
2012-07-16 03:17:13 +02:00
2011-09-27 20:49:03 +02:00
return $res ;
}
2011-12-01 11:16:29 +01:00
2012-10-19 17:09:34 +02:00
2012-09-14 18:09:40 +02:00
public static function getLibraryColumns ()
{
return array ( " id " , " track_title " , " artist_name " , " album_title " ,
" genre " , " length " , " year " , " utime " , " mtime " , " ftype " ,
" track_number " , " mood " , " bpm " , " composer " , " info_url " ,
" bit_rate " , " sample_rate " , " isrc_number " , " encoded_by " , " label " ,
" copyright " , " mime " , " language " , " filepath " , " owner_id " ,
" conductor " , " replay_gain " , " lptime " );
}
2012-07-16 03:17:13 +02:00
public static function searchLibraryFiles ( $datatables )
{
2012-10-19 20:42:01 +02:00
$baseUrl = Application_Common_OsPath :: getBaseDir ();
2012-10-19 17:09:34 +02:00
2012-07-11 00:51:32 +02:00
$con = Propel :: getConnection ( CcFilesPeer :: DATABASE_NAME );
2010-12-07 23:29:28 +01:00
2012-09-14 18:09:40 +02:00
$displayColumns = self :: getLibraryColumns ();
2012-08-31 19:34:21 +02:00
2012-08-23 16:21:39 +02:00
$plSelect = array ();
$blSelect = array ();
$fileSelect = array ();
2012-07-19 00:27:39 +02:00
$streamSelect = array ();
2012-02-22 18:38:33 +01:00
foreach ( $displayColumns as $key ) {
if ( $key === " id " ) {
2012-08-23 16:21:39 +02:00
$plSelect [] = " PL.id AS " . $key ;
$blSelect [] = " BL.id AS " . $key ;
2012-08-31 19:34:21 +02:00
$fileSelect [] = " FILES.id AS $key " ;
2012-08-04 00:06:47 +02:00
$streamSelect [] = " ws.id AS " . $key ;
2012-07-16 03:17:13 +02:00
} elseif ( $key === " track_title " ) {
2012-08-23 16:21:39 +02:00
$plSelect [] = " name AS " . $key ;
$blSelect [] = " name AS " . $key ;
$fileSelect [] = $key ;
2012-07-19 00:27:39 +02:00
$streamSelect [] = " name AS " . $key ;
2012-07-16 03:17:13 +02:00
} elseif ( $key === " ftype " ) {
2012-08-23 16:21:39 +02:00
$plSelect [] = " 'playlist'::varchar AS " . $key ;
$blSelect [] = " 'block'::varchar AS " . $key ;
$fileSelect [] = $key ;
2012-07-19 00:27:39 +02:00
$streamSelect [] = " 'stream'::varchar AS " . $key ;
2012-07-16 03:17:13 +02:00
} elseif ( $key === " artist_name " ) {
2012-08-23 16:21:39 +02:00
$plSelect [] = " login AS " . $key ;
$blSelect [] = " login AS " . $key ;
$fileSelect [] = $key ;
2012-08-04 00:06:47 +02:00
$streamSelect [] = " login AS " . $key ;
2012-09-11 23:18:17 +02:00
} elseif ( $key === " owner_id " ) {
2012-08-31 19:34:21 +02:00
$plSelect [] = " login AS " . $key ;
$blSelect [] = " login AS " . $key ;
$fileSelect [] = " sub.login AS $key " ;
$streamSelect [] = " login AS " . $key ;
2012-09-10 20:37:38 +02:00
} elseif ( $key === " replay_gain " ) {
$plSelect [] = " NULL::NUMERIC AS " . $key ;
$blSelect [] = " NULL::NUMERIC AS " . $key ;
2012-09-11 00:01:36 +02:00
$fileSelect [] = $key ;
2012-09-10 20:37:38 +02:00
$streamSelect [] = " NULL::NUMERIC AS " . $key ;
2012-09-11 00:01:36 +02:00
} elseif ( $key === " lptime " ) {
2012-09-18 18:26:07 +02:00
$plSelect [] = " NULL::TIMESTAMP AS " . $key ;
$blSelect [] = " NULL::TIMESTAMP AS " . $key ;
$fileSelect [] = $key ;
2012-09-11 00:01:36 +02:00
$streamSelect [] = $key ;
2012-02-24 00:55:20 +01:00
}
2012-02-24 16:05:01 +01:00
//same columns in each table.
2012-07-16 03:17:13 +02:00
else if ( in_array ( $key , array ( " length " , " utime " , " mtime " ))) {
2012-09-18 18:26:07 +02:00
$plSelect [] = $key ;
$blSelect [] = $key ;
$fileSelect [] = $key ;
2012-07-19 00:27:39 +02:00
$streamSelect [] = $key ;
2012-07-16 03:17:13 +02:00
} elseif ( $key === " year " ) {
2012-09-18 18:26:07 +02:00
$plSelect [] = " EXTRACT(YEAR FROM utime)::varchar AS " . $key ;
$blSelect [] = " EXTRACT(YEAR FROM utime)::varchar AS " . $key ;
$fileSelect [] = " year AS " . $key ;
2012-07-19 00:27:39 +02:00
$streamSelect [] = " EXTRACT(YEAR FROM utime)::varchar AS " . $key ;
2012-02-24 00:55:20 +01:00
}
//need to cast certain data as ints for the union to search on.
2012-08-15 22:40:04 +02:00
else if ( in_array ( $key , array ( " track_number " , " bit_rate " , " sample_rate " , " bpm " ))) {
2012-08-23 16:21:39 +02:00
$plSelect [] = " NULL::int AS " . $key ;
$blSelect [] = " NULL::int AS " . $key ;
$fileSelect [] = $key ;
2012-07-19 00:27:39 +02:00
$streamSelect [] = " NULL::int AS " . $key ;
2012-08-29 16:58:03 +02:00
} elseif ( $key === " filepath " ) {
2012-08-23 16:21:39 +02:00
$plSelect [] = " NULL::VARCHAR AS " . $key ;
$blSelect [] = " NULL::VARCHAR AS " . $key ;
$fileSelect [] = $key ;
2012-08-09 20:39:31 +02:00
$streamSelect [] = " url AS " . $key ;
2013-01-02 22:09:32 +01:00
} else if ( $key == " mime " ) {
$plSelect [] = " NULL::VARCHAR AS " . $key ;
$blSelect [] = " NULL::VARCHAR AS " . $key ;
$fileSelect [] = $key ;
$streamSelect [] = $key ;
2012-07-16 03:17:13 +02:00
} else {
2012-08-23 16:21:39 +02:00
$plSelect [] = " NULL::text AS " . $key ;
$blSelect [] = " NULL::text AS " . $key ;
$fileSelect [] = $key ;
2012-07-19 00:27:39 +02:00
$streamSelect [] = " NULL::text AS " . $key ;
2010-12-30 00:43:17 +01:00
}
}
2012-08-23 16:21:39 +02:00
$plSelect = " SELECT " . join ( " , " , $plSelect );
$blSelect = " SELECT " . join ( " , " , $blSelect );
$fileSelect = " SELECT " . join ( " , " , $fileSelect );
2012-07-19 00:27:39 +02:00
$streamSelect = " SELECT " . join ( " , " , $streamSelect );
2012-02-22 18:38:33 +01:00
2012-02-24 00:55:20 +01:00
$type = intval ( $datatables [ " type " ]);
$plTable = " ( { $plSelect } FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id)) " ;
2012-07-25 23:08:22 +02:00
$blTable = " ( { $blSelect } FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id)) " ;
2012-11-20 21:18:18 +01:00
$fileTable = " ( { $fileSelect } FROM cc_files AS FILES LEFT JOIN cc_subjs AS sub ON (sub.id = FILES.owner_id) WHERE file_exists = 'TRUE' AND hidden='FALSE') " ;
2012-08-31 19:34:21 +02:00
//$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
2012-08-04 00:06:47 +02:00
$streamTable = " ( { $streamSelect } FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id)) " ;
2012-07-19 00:27:39 +02:00
$unionTable = " ( { $plTable } UNION { $blTable } UNION { $fileTable } UNION { $streamTable } ) AS RESULTS " ;
2012-01-17 11:18:17 +01:00
2012-02-24 00:55:20 +01:00
//choose which table we need to select data from.
2012-09-18 18:48:45 +02:00
// TODO : use constants instead of numbers -- RG
2012-02-24 00:55:20 +01:00
switch ( $type ) {
case 0 :
$fromTable = $unionTable ;
break ;
case 1 :
$fromTable = $fileTable . " AS File " ; //need an alias for the table if it's standalone.
break ;
case 2 :
$fromTable = $plTable . " AS Playlist " ; //need an alias for the table if it's standalone.
break ;
2012-07-25 23:08:22 +02:00
case 3 :
$fromTable = $blTable . " AS Block " ; //need an alias for the table if it's standalone.
break ;
2012-08-03 22:33:58 +02:00
case 4 :
$fromTable = $streamTable . " AS StreamTable " ; //need an alias for the table if it's standalone.
break ;
2012-02-24 00:55:20 +01:00
default :
$fromTable = $unionTable ;
}
2012-04-01 21:51:03 +02:00
2012-03-12 15:32:24 +01:00
$results = Application_Model_Datatables :: findEntries ( $con , $displayColumns , $fromTable , $datatables );
2013-01-30 14:57:59 +01:00
$futureScheduledFiles = Application_Model_Schedule :: getAllFutureScheduledFiles ();
2013-01-30 22:53:59 +01:00
// we are only interested in which files belong to playlists and blocks
$playlistBlockFiles = array_merge ( Application_Model_Playlist :: getAllPlaylistFiles (),
2013-01-30 16:55:24 +01:00
Application_Model_Block :: getAllBlockContent ());
2013-01-30 21:38:25 +01:00
2013-01-30 22:53:59 +01:00
$futureScheduledStreams = Application_Model_Schedule :: getAllFutureScheduledWebstreams ();
// here we are only interested in which streams belong to a playlist
$playlistStreams = Application_Model_Playlist :: getAllPlaylistStreams ();
2012-02-20 11:41:44 +01:00
foreach ( $results [ 'aaData' ] as & $row ) {
2012-02-01 18:47:08 +01:00
$row [ 'id' ] = intval ( $row [ 'id' ]);
2012-02-24 15:07:04 +01:00
$formatter = new LengthFormatter ( $row [ 'length' ]);
$row [ 'length' ] = $formatter -> format ();
2012-02-01 23:33:20 +01:00
2012-02-24 18:22:07 +01:00
if ( $row [ 'ftype' ] === " audioclip " ) {
$formatter = new SamplerateFormatter ( $row [ 'sample_rate' ]);
$row [ 'sample_rate' ] = $formatter -> format ();
$formatter = new BitrateFormatter ( $row [ 'bit_rate' ]);
$row [ 'bit_rate' ] = $formatter -> format ();
2013-01-30 21:38:25 +01:00
//soundcloud status
$file = Application_Model_StoredFile :: Recall ( $row [ 'id' ]);
$row [ 'soundcloud_status' ] = $file -> getSoundCloudId ();
2013-01-30 22:53:59 +01:00
2013-01-30 21:38:25 +01:00
//file 'in use' status
if ( in_array ( $row [ 'id' ], $futureScheduledFiles ) && in_array ( $row [ 'id' ], $playlistBlockFiles )) {
2013-01-30 22:53:59 +01:00
$row [ 'status_in_use' ] = true ;
$row [ 'status_msg' ] = _ ( " This track is scheduled in the future and belongs to a playlist or smart block " );
2013-01-30 21:38:25 +01:00
} elseif ( in_array ( $row [ 'id' ], $futureScheduledFiles )) {
2013-01-30 22:53:59 +01:00
$row [ 'status_in_use' ] = true ;
$row [ 'status_msg' ] = _ ( " This track is scheduled in the future " );
2013-01-30 21:38:25 +01:00
} elseif ( in_array ( $row [ 'id' ], $playlistBlockFiles )) {
2013-01-30 22:53:59 +01:00
$row [ 'status_in_use' ] = true ;
$row [ 'status_msg' ] = _ ( " This track belongs to a playlist or smart block " );
2013-01-30 21:38:25 +01:00
}
2013-01-30 22:53:59 +01:00
2013-01-30 21:38:25 +01:00
// for audio preview
$row [ 'audioFile' ] = $row [ 'id' ] . " . " . pathinfo ( $row [ 'filepath' ], PATHINFO_EXTENSION );
2013-01-30 22:53:59 +01:00
} else if ( $row [ 'ftype' ] === " stream " ) {
$row [ 'audioFile' ] = $row [ 'id' ];
if ( in_array ( $row [ 'id' ], $futureScheduledStreams ) && in_array ( $row [ 'id' ], $playlistStreams )) {
$row [ 'status_in_use' ] = true ;
$row [ 'status_msg' ] = _ ( " This webstream is scheduled in the future and belongs to a playlist " );
} elseif ( in_array ( $row [ 'id' ], $futureScheduledStreams )) {
$row [ 'status_in_use' ] = true ;
$row [ 'status_msg' ] = _ ( " This webstream is scheduled in the future " );
} elseif ( in_array ( $row [ 'id' ], $playlistStreams )) {
$row [ 'status_in_use' ] = true ;
$row [ 'status_msg' ] = _ ( " This webstream belongs to a playlist " );
}
2013-01-30 21:38:25 +01:00
} else {
$row [ 'audioFile' ] = $row [ 'id' ];
2012-02-24 18:22:07 +01:00
}
2012-08-29 16:58:03 +02:00
2012-07-20 01:11:42 +02:00
//convert mtime and utime to localtime
$row [ 'mtime' ] = new DateTime ( $row [ 'mtime' ], new DateTimeZone ( 'UTC' ));
$row [ 'mtime' ] -> setTimeZone ( new DateTimeZone ( date_default_timezone_get ()));
$row [ 'mtime' ] = $row [ 'mtime' ] -> format ( 'Y-m-d H:i:s' );
$row [ 'utime' ] = new DateTime ( $row [ 'utime' ], new DateTimeZone ( 'UTC' ));
$row [ 'utime' ] -> setTimeZone ( new DateTimeZone ( date_default_timezone_get ()));
$row [ 'utime' ] = $row [ 'utime' ] -> format ( 'Y-m-d H:i:s' );
2012-08-29 16:58:03 +02:00
2013-01-30 21:38:25 +01:00
// we need to initalize the checkbox and image row because we do not retrieve
// any data from the db for these and datatables will complain
$row [ 'checkbox' ] = " " ;
$row [ 'image' ] = " " ;
$row [ 'status' ] = " " ;
2012-01-17 11:18:17 +01:00
2012-02-01 23:33:20 +01:00
$row [ 'tr_id' ] = " { $type } _ { $row [ 'id' ] } " ;
2012-01-13 20:17:39 +01:00
}
2012-01-17 11:18:17 +01:00
2012-01-13 20:17:39 +01:00
return $results ;
2012-01-09 04:31:18 +01:00
}
2012-03-07 18:27:32 +01:00
2011-06-08 10:15:35 +02:00
public static function uploadFile ( $p_targetDir )
2011-06-06 16:18:03 +02:00
{
2011-03-25 04:07:13 +01:00
// HTTP headers for no cache etc
2012-02-28 19:47:57 +01:00
header ( 'Content-type: text/plain; charset=UTF-8' );
header ( " Expires: Mon, 26 Jul 1997 05:00:00 GMT " );
header ( " Last-Modified: " . gmdate ( " D, d M Y H:i:s " ) . " GMT " );
header ( " Cache-Control: no-store, no-cache, must-revalidate " );
header ( " Cache-Control: post-check=0, pre-check=0 " , false );
header ( " Pragma: no-cache " );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// Settings
$cleanupTargetDir = false ; // Remove old files
2012-08-24 16:20:23 +02:00
$maxFileAge = 60 * 60 ; // Temp file age in seconds
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// 5 minutes execution time
@ set_time_limit ( 5 * 60 );
// usleep(5000);
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// Get parameters
$chunk = isset ( $_REQUEST [ " chunk " ]) ? $_REQUEST [ " chunk " ] : 0 ;
$chunks = isset ( $_REQUEST [ " chunks " ]) ? $_REQUEST [ " chunks " ] : 0 ;
$fileName = isset ( $_REQUEST [ " name " ]) ? $_REQUEST [ " name " ] : '' ;
2012-08-27 21:09:55 +02:00
# TODO : should not log __FILE__ itself. there is general logging for
# this
2012-08-22 00:41:56 +02:00
Logging :: info ( __FILE__ . " :uploadFile(): filename= $fileName to $p_targetDir " );
2012-02-28 19:47:57 +01:00
// Clean the fileName for security reasons
2011-07-21 12:12:37 +02:00
//this needs fixing for songs not in ascii.
2012-02-28 19:47:57 +01:00
//$fileName = preg_replace('/[^\w\._]+/', '', $fileName);
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// Create target dir
if ( ! file_exists ( $p_targetDir ))
@ mkdir ( $p_targetDir );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// Remove old temp files
if ( is_dir ( $p_targetDir ) && ( $dir = opendir ( $p_targetDir ))) {
while (( $file = readdir ( $dir )) !== false ) {
$filePath = $p_targetDir . DIRECTORY_SEPARATOR . $file ;
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// Remove temp files if they are older than the max age
if ( preg_match ( '/\.tmp$/' , $file ) && ( filemtime ( $filePath ) < time () - $maxFileAge ))
@ unlink ( $filePath );
}
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
closedir ( $dir );
} else
2012-11-15 21:52:51 +01:00
die ( '{"jsonrpc" : "2.0", "error" : {"code": 100, "message": _("Failed to open temp directory.")}, "id" : "id"}' );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
// Look for the content type header
if ( isset ( $_SERVER [ " HTTP_CONTENT_TYPE " ]))
$contentType = $_SERVER [ " HTTP_CONTENT_TYPE " ];
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
if ( isset ( $_SERVER [ " CONTENT_TYPE " ]))
$contentType = $_SERVER [ " CONTENT_TYPE " ];
2011-03-25 04:07:13 +01:00
2011-11-23 20:12:14 +01:00
// create temp file name (CC-3086)
2011-12-14 21:58:26 +01:00
// we are not using mktemp command anymore.
// plupload support unique_name feature.
$tempFilePath = $p_targetDir . DIRECTORY_SEPARATOR . $fileName ;
2011-12-01 11:16:29 +01:00
2012-09-19 23:37:49 +02:00
// Old IBM code...
2012-02-28 19:47:57 +01:00
if ( strpos ( $contentType , " multipart " ) !== false ) {
if ( isset ( $_FILES [ 'file' ][ 'tmp_name' ]) && is_uploaded_file ( $_FILES [ 'file' ][ 'tmp_name' ])) {
// Open temp file
$out = fopen ( $tempFilePath , $chunk == 0 ? " wb " : " ab " );
if ( $out ) {
// Read binary input stream and append it to temp file
$in = fopen ( $_FILES [ 'file' ][ 'tmp_name' ], " rb " );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
if ( $in ) {
while ( $buff = fread ( $in , 4096 ))
fwrite ( $out , $buff );
} else
2012-11-15 21:52:51 +01:00
die ( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": _("Failed to open input stream.")}, "id" : "id"}' );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
fclose ( $out );
unlink ( $_FILES [ 'file' ][ 'tmp_name' ]);
} else
2012-11-15 21:52:51 +01:00
die ( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": _("Failed to open output stream.")}, "id" : "id"}' );
2012-02-28 19:47:57 +01:00
} else
2012-11-15 21:52:51 +01:00
die ( '{"jsonrpc" : "2.0", "error" : {"code": 103, "message": _("Failed to move uploaded file.")}, "id" : "id"}' );
2012-02-28 19:47:57 +01:00
} else {
// Open temp file
$out = fopen ( $tempFilePath , $chunk == 0 ? " wb " : " ab " );
if ( $out ) {
// Read binary input stream and append it to temp file
$in = fopen ( " php://input " , " rb " );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
if ( $in ) {
while ( $buff = fread ( $in , 4096 ))
fwrite ( $out , $buff );
} else
2012-11-15 21:52:51 +01:00
die ( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": _("Failed to open input stream.")}, "id" : "id"}' );
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
fclose ( $out );
} else
2012-11-15 21:52:51 +01:00
die ( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": _("Failed to open output stream.")}, "id" : "id"}' );
2012-02-28 19:47:57 +01:00
}
2012-03-07 18:27:32 +01:00
2012-02-28 19:47:57 +01:00
return $tempFilePath ;
2011-07-29 22:45:13 +02:00
}
2011-08-03 18:32:59 +02:00
2012-02-09 18:45:39 +01:00
/**
* Check , using disk_free_space , the space available in the $destination_folder folder to see if it has
* enough space to move the $audio_file into and report back to the user if not .
**/
2012-07-16 03:17:13 +02:00
public static function isEnoughDiskSpaceToCopy ( $destination_folder , $audio_file )
{
2012-02-17 11:50:49 +01:00
//check to see if we have enough space in the /organize directory to copy the file
$freeSpace = disk_free_space ( $destination_folder );
$fileSize = filesize ( $audio_file );
2012-04-01 21:51:03 +02:00
2012-07-06 04:37:40 +02:00
return $freeSpace >= $fileSize ;
2012-02-09 18:45:39 +01:00
}
2012-02-16 19:46:14 +01:00
2012-07-16 03:17:13 +02:00
public static function copyFileToStor ( $p_targetDir , $fileName , $tempname )
{
2011-11-23 20:12:14 +01:00
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname ;
2012-08-22 00:41:56 +02:00
Logging :: info ( 'copyFileToStor: moving file ' . $audio_file );
2012-07-11 00:51:32 +02:00
2012-08-22 22:08:46 +02:00
$storDir = Application_Model_MusicDir :: getStorDir ();
$stor = $storDir -> getDirectory ();
// check if "organize" dir exists and if not create one
if ( ! file_exists ( $stor . " /organize " )) {
if ( ! mkdir ( $stor . " /organize " , 0777 )) {
return array (
" code " => 109 ,
2012-11-15 21:52:51 +01:00
" message " => _ ( " Failed to create 'organize' directory. " ));
2012-07-06 04:37:40 +02:00
}
2012-08-22 22:08:46 +02:00
}
2012-07-11 00:51:32 +02:00
2012-08-22 22:08:46 +02:00
if ( chmod ( $audio_file , 0644 ) === false ) {
Logging :: info ( " Warning: couldn't change permissions of $audio_file to 0644 " );
}
2012-07-11 00:51:32 +02:00
2012-08-22 22:08:46 +02:00
// Check if we have enough space before copying
2012-08-29 16:58:03 +02:00
if ( ! self :: isEnoughDiskSpaceToCopy ( $stor , $audio_file )) {
2012-08-22 22:08:46 +02:00
$freeSpace = disk_free_space ( $stor );
2012-08-29 16:58:03 +02:00
2012-08-22 22:08:46 +02:00
return array ( " code " => 107 ,
2012-11-15 21:52:51 +01:00
" message " => sprintf ( _ ( " The file was not uploaded, there is "
. " %s MB of disk space left and the file you are "
. " uploading has a size of %s MB. " ), $freeSpace , $fileSize ));
2012-08-22 22:08:46 +02:00
}
2012-07-06 04:37:40 +02:00
2012-08-22 22:08:46 +02:00
// Check if liquidsoap can play this file
2012-08-29 16:58:03 +02:00
if ( ! self :: liquidsoapFilePlayabilityTest ( $audio_file )) {
2012-08-22 22:08:46 +02:00
return array (
2012-08-23 16:21:39 +02:00
" code " => 110 ,
2012-11-15 21:52:51 +01:00
" message " => _ ( " This file appears to be corrupted and will not "
. " be added to media library. " ));
2012-02-28 19:47:57 +01:00
}
2012-07-16 03:17:13 +02:00
2012-09-19 23:45:03 +02:00
// Did all the checks for real, now trying to copy
2012-08-27 23:58:09 +02:00
$audio_stor = Application_Common_OsPath :: join ( $stor , " organize " ,
$fileName );
$user = Application_Model_User :: getCurrentUser ();
if ( is_null ( $user )) {
$uid = Application_Model_User :: getFirstAdminId ();
} else {
$uid = $user -> getId ();
}
2012-08-24 18:37:16 +02:00
$id_file = " $audio_stor .identifier " ;
2012-09-04 23:21:59 +02:00
if ( file_put_contents ( $id_file , $uid ) === false ) {
2012-08-24 18:37:16 +02:00
Logging :: info ( " Could not write file to identify user: ' $uid ' " );
Logging :: info ( " Id file path: ' $id_file ' " );
Logging :: info ( " Defaulting to admin (no identification file was
written ) " );
} else {
Logging :: info ( " Successfully written identification file for
uploaded '$audio_stor' " );
}
2012-08-22 22:08:46 +02:00
Logging :: info ( " copyFileToStor: moving file $audio_file to $audio_stor " );
2012-08-23 17:13:03 +02:00
// Martin K.: changed to rename: Much less load + quicker since this is
// an atomic operation
2012-08-22 22:08:46 +02:00
if ( @ rename ( $audio_file , $audio_stor ) === false ) {
2012-09-19 23:37:49 +02:00
//something went wrong likely there wasn't enough space in .
//the audio_stor to move the file too warn the user that .
//the file wasn't uploaded and they should check if there .
//is enough disk space .
2012-08-23 17:13:03 +02:00
unlink ( $audio_file ); //remove the file after failed rename
2012-08-24 18:37:16 +02:00
unlink ( $id_file ); // Also remove the identifier file
2012-08-29 16:58:03 +02:00
2012-08-22 22:08:46 +02:00
return array (
2012-08-23 16:21:39 +02:00
" code " => 108 ,
2012-11-15 21:52:51 +01:00
" message " => _ ( " The file was not uploaded, this error can occur if the computer "
. " hard drive does not have enough disk space or the stor "
. " directory does not have correct write permissions. " ));
2012-08-22 22:08:46 +02:00
}
2012-08-23 16:21:39 +02:00
// Now that we successfully added this file, we will add another tag
// file that will identify the user that owns it
2012-08-22 22:08:46 +02:00
return null ;
2011-03-25 04:07:13 +01:00
}
2012-07-11 00:51:32 +02:00
2012-07-06 04:37:40 +02:00
/*
* Pass the file through Liquidsoap and test if it is readable . Return True if readable , and False otherwise .
*/
2012-07-16 03:17:13 +02:00
public static function liquidsoapFilePlayabilityTest ( $audio_file )
{
2012-07-06 04:37:40 +02:00
$LIQUIDSOAP_ERRORS = array ( 'TagLib: MPEG::Properties::read() -- Could not find a valid last MPEG frame in the stream.' );
2012-07-11 00:51:32 +02:00
2012-07-06 04:37:40 +02:00
// Ask Liquidsoap if file is playable
$command = sprintf ( " /usr/bin/airtime-liquidsoap -c 'output.dummy(audio_to_stereo(single( \" %s \" )))' 2>&1 " , $audio_file );
2012-07-11 00:51:32 +02:00
2012-07-06 04:37:40 +02:00
exec ( $command , $output , $rv );
2012-07-11 00:51:32 +02:00
2012-07-06 04:37:40 +02:00
$isError = count ( $output ) > 0 && in_array ( $output [ 0 ], $LIQUIDSOAP_ERRORS );
2012-07-16 03:17:13 +02:00
2012-07-11 00:51:32 +02:00
return ( $rv == 0 && ! $isError );
2012-07-06 04:37:40 +02:00
}
2012-07-11 00:51:32 +02:00
2011-07-22 12:54:42 +02:00
public static function getFileCount ()
{
2012-07-16 03:17:13 +02:00
$con = Propel :: getConnection ();
2012-09-04 23:21:59 +02:00
$sql = " SELECT count(*) as cnt FROM cc_files WHERE file_exists " ;
2012-04-01 21:51:03 +02:00
return $con -> query ( $sql ) -> fetchColumn ( 0 );
2011-07-22 12:54:42 +02:00
}
2012-01-13 20:17:39 +01:00
/**
2012-01-17 11:18:17 +01:00
*
2012-01-13 20:17:39 +01:00
* Enter description here ...
2012-09-19 17:17:32 +02:00
* @ param $dir_id - if this is not provided , it returns all files with full
* path constructed .
2012-01-13 20:17:39 +01:00
*/
2012-09-04 23:21:59 +02:00
public static function listAllFiles ( $dir_id = null , $all )
2012-04-01 21:51:03 +02:00
{
2012-07-16 03:17:13 +02:00
$con = Propel :: getConnection ();
2012-01-17 11:18:17 +01:00
2012-09-19 17:17:32 +02:00
$sql = <<< SQL
SELECT filepath AS fp
FROM CC_FILES AS f
2013-01-03 20:02:06 +01:00
WHERE f . directory = : dir_id
2012-09-19 17:17:32 +02:00
SQL ;
2012-11-05 17:11:05 +01:00
# TODO : the option $all is deprecated now and is always true.
# refactor code where it's still being passed
$all = true ;
2012-09-04 23:21:59 +02:00
if ( ! $all ) {
$sql .= " AND f.file_exists = 'TRUE' " ;
}
2012-08-28 18:35:19 +02:00
2012-09-04 23:21:59 +02:00
$stmt = $con -> prepare ( $sql );
$stmt -> bindParam ( ':dir_id' , $dir_id );
if ( $stmt -> execute ()) {
$rows = $stmt -> fetchAll ();
2012-04-01 21:51:03 +02:00
} else {
2012-09-04 23:21:59 +02:00
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
2012-01-13 20:17:39 +01:00
}
2012-09-04 23:21:59 +02:00
2011-07-04 20:29:09 +02:00
$results = array ();
2012-04-01 21:51:03 +02:00
foreach ( $rows as $row ) {
2012-09-04 23:21:59 +02:00
$results [] = $row [ " fp " ];
2011-07-04 20:29:09 +02:00
}
return $results ;
}
2012-07-16 03:17:13 +02:00
2012-07-12 23:58:29 +02:00
//TODO: MERGE THIS FUNCTION AND "listAllFiles" -MK
2012-09-04 23:21:59 +02:00
public static function listAllFiles2 ( $dir_id = null , $limit = " ALL " )
2012-07-12 23:58:29 +02:00
{
$con = Propel :: getConnection ();
2012-09-18 21:04:22 +02:00
$sql = <<< SQL
SELECT id ,
filepath AS fp
FROM cc_files
WHERE directory = : dir_id
AND file_exists = 'TRUE'
AND replay_gain IS NULL LIMIT : lim
SQL ;
2012-08-29 16:58:03 +02:00
2012-09-04 23:21:59 +02:00
$stmt = $con -> prepare ( $sql );
$stmt -> bindParam ( ':dir_id' , $dir_id );
$stmt -> bindParam ( ':lim' , $limit );
if ( $stmt -> execute ()) {
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
} else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
}
2012-08-29 16:58:03 +02:00
2012-07-12 23:58:29 +02:00
return $rows ;
}
2013-01-18 17:53:26 +01:00
public static function getAllFilesWithoutSilan () {
$con = Propel :: getConnection ();
$sql = <<< SQL
SELECT f . id ,
m . directory || f . filepath AS fp
FROM cc_files as f
JOIN cc_music_dirs as m ON f . directory = m . id
WHERE file_exists = 'TRUE'
AND silan_check IS FALSE Limit 100
SQL ;
$stmt = $con -> prepare ( $sql );
if ( $stmt -> execute ()) {
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
} else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
}
return $rows ;
}
2012-07-11 00:51:32 +02:00
2012-05-07 17:24:40 +02:00
/* Gets number of tracks uploaded to
* Soundcloud in the last 24 hours
*/
public static function getSoundCloudUploads ()
{
2012-05-07 18:12:08 +02:00
try {
2012-07-11 00:51:32 +02:00
$con = Propel :: getConnection ();
2012-09-11 22:13:39 +02:00
$sql = <<< SQL
SELECT soundcloud_id AS id ,
soundcloud_upload_time
FROM CC_FILES
WHERE ( id != - 2
AND id != - 3 )
AND ( soundcloud_upload_time >= ( now () - ( INTERVAL '1 day' )))
SQL ;
2012-07-11 00:51:32 +02:00
2012-05-07 18:12:08 +02:00
$rows = $con -> query ( $sql ) -> fetchAll ();
2012-07-16 03:17:13 +02:00
2012-05-07 18:12:08 +02:00
return count ( $rows );
} catch ( Exception $e ) {
header ( 'HTTP/1.0 503 Service Unavailable' );
2012-08-22 00:41:56 +02:00
Logging :: info ( " Could not connect to database. " );
2012-07-11 00:51:32 +02:00
exit ;
2012-05-07 18:12:08 +02:00
}
2012-07-11 00:51:32 +02:00
2012-05-07 17:24:40 +02:00
}
2011-09-22 21:31:21 +02:00
2011-10-22 17:34:04 +02:00
public function setSoundCloudLinkToFile ( $link_to_file )
{
$this -> _file -> setDbSoundCloudLinkToFile ( $link_to_file )
-> save ();
}
2011-12-01 11:16:29 +01:00
2012-07-16 03:17:13 +02:00
public function getSoundCloudLinkToFile ()
{
2011-10-22 17:34:04 +02:00
return $this -> _file -> getDbSoundCloudLinkToFile ();
}
2011-12-01 11:16:29 +01:00
2011-09-22 17:47:24 +02:00
public function setSoundCloudFileId ( $p_soundcloud_id )
{
$this -> _file -> setDbSoundCloudId ( $p_soundcloud_id )
-> save ();
}
2011-09-22 21:31:21 +02:00
2012-07-16 03:17:13 +02:00
public function getSoundCloudId ()
{
2011-09-22 17:47:24 +02:00
return $this -> _file -> getDbSoundCloudId ();
}
2011-09-22 21:31:21 +02:00
2012-07-16 03:17:13 +02:00
public function setSoundCloudErrorCode ( $code )
{
2011-09-22 17:47:24 +02:00
$this -> _file -> setDbSoundCloudErrorCode ( $code )
-> save ();
}
2011-09-22 21:31:21 +02:00
2012-07-16 03:17:13 +02:00
public function getSoundCloudErrorCode ()
{
2011-09-22 17:47:24 +02:00
return $this -> _file -> getDbSoundCloudErrorCode ();
}
2011-09-22 21:31:21 +02:00
2012-07-16 03:17:13 +02:00
public function setSoundCloudErrorMsg ( $msg )
{
2011-09-22 17:47:24 +02:00
$this -> _file -> setDbSoundCloudErrorMsg ( $msg )
-> save ();
}
2011-09-22 21:31:21 +02:00
2012-07-16 03:17:13 +02:00
public function getSoundCloudErrorMsg ()
{
2011-09-22 17:47:24 +02:00
return $this -> _file -> getDbSoundCloudErrorMsg ();
}
2012-07-11 00:51:32 +02:00
2012-07-16 03:17:13 +02:00
public function getDirectory ()
{
2012-07-11 00:51:32 +02:00
return $this -> _file -> getDbDirectory ();
}
2012-01-17 11:18:17 +01:00
2012-07-16 03:17:13 +02:00
public function setFileExistsFlag ( $flag )
{
2012-01-13 20:17:39 +01:00
$this -> _file -> setDbFileExists ( $flag )
-> save ();
}
2013-01-08 21:42:35 +01:00
public function setFileHiddenFlag ( $flag )
{
$this -> _file -> setDbHidden ( $flag )
-> save ();
}
2012-07-16 03:17:13 +02:00
public function setSoundCloudUploadTime ( $time )
{
2012-05-07 17:24:40 +02:00
$this -> _file -> setDbSoundCloundUploadTime ( $time )
2012-07-11 00:51:32 +02:00
-> save ();
2012-05-07 17:24:40 +02:00
}
2012-01-17 11:18:17 +01:00
2012-11-05 15:49:49 +01:00
// This method seems to be unsued everywhere so I've commented it out
2013-01-03 20:02:06 +01:00
// If it's absence does not have any effect then it will be completely
2012-11-05 15:49:49 +01:00
// removed soon
//public function getFileExistsFlag()
//{
//return $this->_file->getDbFileExists();
//}
2011-09-22 21:31:21 +02:00
2012-10-31 21:01:17 +01:00
public function getFileOwnerId ()
{
return $this -> _file -> getDbOwnerId ();
}
2012-09-18 21:04:22 +02:00
// note: never call this method from controllers because it does a sleep
2011-09-22 17:47:24 +02:00
public function uploadToSoundCloud ()
{
2013-01-14 22:16:14 +01:00
$CC_CONFIG = Config :: getConfig ();
2011-12-01 11:16:29 +01:00
2011-09-22 17:47:24 +02:00
$file = $this -> _file ;
2012-07-16 03:17:13 +02:00
if ( is_null ( $file )) {
2011-09-22 17:47:24 +02:00
return " File does not exist " ;
}
2012-07-16 03:17:13 +02:00
if ( Application_Model_Preference :: GetUploadToSoundcloudOption ()) {
for ( $i = 0 ; $i < $CC_CONFIG [ 'soundcloud-connection-retries' ]; $i ++ ) {
2011-09-22 17:47:24 +02:00
$description = $file -> getDbTrackTitle ();
2012-09-18 18:56:01 +02:00
$tag = array ();
$genre = $file -> getDbGenre ();
$release = $file -> getDbYear ();
2011-09-22 17:47:24 +02:00
try {
2012-09-18 18:56:01 +02:00
$soundcloud = new Application_Model_Soundcloud ();
2012-09-17 18:35:12 +02:00
$soundcloud_res = $soundcloud -> uploadTrack (
$this -> getFilePath (), $this -> getName (), $description ,
$tag , $release , $genre );
2011-10-22 17:34:04 +02:00
$this -> setSoundCloudFileId ( $soundcloud_res [ 'id' ]);
$this -> setSoundCloudLinkToFile ( $soundcloud_res [ 'permalink_url' ]);
2012-05-07 17:24:40 +02:00
$this -> setSoundCloudUploadTime ( new DateTime ( " now " ), new DateTimeZone ( " UTC " ));
2011-09-22 17:47:24 +02:00
break ;
2012-07-16 03:17:13 +02:00
} catch ( Services_Soundcloud_Invalid_Http_Response_Code_Exception $e ) {
2011-09-22 17:47:24 +02:00
$code = $e -> getHttpCode ();
2012-09-18 18:56:01 +02:00
$msg = $e -> getHttpBody ();
2012-09-18 21:02:07 +02:00
// TODO : Do not parse JSON by hand
2011-09-22 17:47:24 +02:00
$temp = explode ( '"error":' , $msg );
2012-09-18 18:56:01 +02:00
$msg = trim ( $temp [ 1 ], '"}' );
2011-09-22 17:47:24 +02:00
$this -> setSoundCloudErrorCode ( $code );
$this -> setSoundCloudErrorMsg ( $msg );
// setting sc id to -3 which indicates error
2011-09-29 20:47:07 +02:00
$this -> setSoundCloudFileId ( SOUNDCLOUD_ERROR );
2012-07-16 03:17:13 +02:00
if ( ! in_array ( $code , array ( 0 , 100 ))) {
2011-09-22 17:47:24 +02:00
break ;
}
}
sleep ( $CC_CONFIG [ 'soundcloud-connection-wait' ]);
}
}
}
2010-12-07 23:29:28 +01:00
}
2011-02-22 18:22:31 +01:00
2012-02-05 18:19:22 +01:00
class DeleteScheduledFileException extends Exception {}
2012-02-16 19:46:14 +01:00
class FileDoesNotExistException extends Exception {}
2012-10-31 21:51:29 +01:00
class FileNoPermissionException extends Exception {}