Playlist editing methods moved from GreenBox to separate class Playlist.
GreenBox have only wrapper now. Offset calculations fixed, changeFadeInfo method added.
This commit is contained in:
parent
05ee72190a
commit
a6d757f1dd
2 changed files with 488 additions and 218 deletions
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: tomas $
|
Author : $Author: tomas $
|
||||||
Version : $Revision: 1.46 $
|
Version : $Revision: 1.47 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -35,7 +35,7 @@ require_once "BasicStor.php";
|
||||||
* LiveSupport file storage module
|
* LiveSupport file storage module
|
||||||
*
|
*
|
||||||
* @author $Author: tomas $
|
* @author $Author: tomas $
|
||||||
* @version $Revision: 1.46 $
|
* @version $Revision: 1.47 $
|
||||||
* @see BasicStor
|
* @see BasicStor
|
||||||
*/
|
*/
|
||||||
class GreenBox extends BasicStor{
|
class GreenBox extends BasicStor{
|
||||||
|
@ -404,10 +404,13 @@ class GreenBox extends BasicStor{
|
||||||
$lc =& new LocStor($this->dbc, $this->config);
|
$lc =& new LocStor($this->dbc, $this->config);
|
||||||
$gunid2 = $lc->createPlaylist($sessid, $gunid, $fname);
|
$gunid2 = $lc->createPlaylist($sessid, $gunid, $fname);
|
||||||
if(PEAR::isError($gunid2)) return $gunid2;
|
if(PEAR::isError($gunid2)) return $gunid2;
|
||||||
|
// get local id:
|
||||||
$id = $this->_idFromGunid($gunid2);
|
$id = $this->_idFromGunid($gunid2);
|
||||||
if(PEAR::isError($id)) return $id;
|
if(PEAR::isError($id)) return $id;
|
||||||
|
// get home dir id:
|
||||||
$hdid = $this->_getHomeDirId($sessid);
|
$hdid = $this->_getHomeDirId($sessid);
|
||||||
if(PEAR::isError($hdid)) return $hdid;
|
if(PEAR::isError($hdid)) return $hdid;
|
||||||
|
// optionally move it to the destination folder:
|
||||||
if($parid != $hdid && !is_null($parid)){
|
if($parid != $hdid && !is_null($parid)){
|
||||||
$r = $this->bsMoveFile($id, $parid);
|
$r = $this->bsMoveFile($id, $parid);
|
||||||
if(PEAR::isError($r)){ return $r; }
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
@ -492,119 +495,25 @@ class GreenBox extends BasicStor{
|
||||||
function addAudioClipToPlaylist($token, $acId, $sessid,
|
function addAudioClipToPlaylist($token, $acId, $sessid,
|
||||||
$fadeIn=NULL, $fadeOut=NULL)
|
$fadeIn=NULL, $fadeOut=NULL)
|
||||||
{
|
{
|
||||||
$acGunid = $this->_gunidFromId($acId);
|
require_once"Playlist.php";
|
||||||
if(PEAR::isError($acGunid)) return $acGunid;
|
$pl =& Playlist::recallByToken($this, $token);
|
||||||
$plGunid = $this->_gunidFromToken($token, 'download');
|
if(PEAR::isError($pl)) return $pl;
|
||||||
if(PEAR::isError($plGunid)) return $plGunid;
|
if('playlist' == ($type = $this->getFileType($acId))){
|
||||||
if(is_null($plGunid)){
|
|
||||||
return PEAR::raiseError(
|
return PEAR::raiseError(
|
||||||
"GreenBox::addClipToPlaylist: invalid token"
|
"GreenBox::addAudioClipToPlaylist: object type not supported".
|
||||||
|
" ($type)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$pl =& StoredFile::recallByGunid($this, $plGunid);
|
$res = $pl->addAudioClip($acId, $fadeIn, $fadeOut);
|
||||||
if(PEAR::isError($pl)){ return $pl; }
|
if(PEAR::isError($res)) return $res;
|
||||||
$id = $pl->getId();
|
return $res;
|
||||||
// get playlist length and record id:
|
|
||||||
$r = $pl->md->getMetadataEl('dcterms:extent');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
if(isset($r[0])){
|
|
||||||
$plLen = $r[0]['value'];
|
|
||||||
$plLenMid = $r[0]['mid'];
|
|
||||||
}else{
|
|
||||||
$plLen = '00:00:00.000000';
|
|
||||||
$plLenMid = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get audioClip legth and title
|
|
||||||
$ac =& StoredFile::recallByGunid($this, $acGunid);
|
|
||||||
if(PEAR::isError($ac)){ return $ac; }
|
|
||||||
$r = $ac->md->getMetadataEl('dcterms:extent');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$acLen = $r[0]['value'];
|
|
||||||
$r = $ac->md->getMetadataEl('dc:title');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$acTit = $r[0]['value'];
|
|
||||||
|
|
||||||
// get main playlist container
|
|
||||||
$r = $pl->md->getMetadataEl('playlist');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$parid = $r[0]['mid'];
|
|
||||||
if(is_null($parid)){
|
|
||||||
return PEAR::raiseError(
|
|
||||||
"GreenBox::addClipToPlaylist: can't find main container"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// get metadata container (optionally insert it)
|
|
||||||
$r = $pl->md->getMetadataEl('metadata');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$metaParid = $r[0]['mid'];
|
|
||||||
if(is_null($metaParid)){
|
|
||||||
$r = $pl->md->insertMetadataEl($parid, 'metadata');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$metaParid = $r;
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert new playlist element
|
|
||||||
$r = $pl->md->insertMetadataEl($parid, 'playlistElement');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$plElId = $r;
|
|
||||||
$plElGunid = StoredFile::_createGunid();
|
|
||||||
$r = $pl->md->insertMetadataEl($plElId, 'id', $plElGunid, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$r = $pl->md->insertMetadataEl(
|
|
||||||
$plElId, 'relativeOffset', $plLen, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
// insert audioClip element into playlistElement
|
|
||||||
$r = $pl->md->insertMetadataEl($plElId, 'audioClip');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$acId = $r;
|
|
||||||
$r = $pl->md->insertMetadataEl($acId, 'id', $acGunid, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$r = $pl->md->insertMetadataEl($acId, 'playlength', $acLen, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$r = $pl->md->insertMetadataEl($acId, 'title', $acTit, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
if(!is_null($fadeIn) || !is_null($fadeOut)){
|
|
||||||
// insert fadeInfo element into playlistElement
|
|
||||||
$r = $pl->md->insertMetadataEl($plElId, 'fadeInfo');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$fiId = $r;
|
|
||||||
$fiGunid = StoredFile::_createGunid();
|
|
||||||
$r = $pl->md->insertMetadataEl($fiId, 'id', $fiGunid, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$r = $pl->md->insertMetadataEl($fiId, 'fadeIn', $fadeIn, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$r = $pl->md->insertMetadataEl($fiId, 'fadeOut', $fadeOut, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
}
|
|
||||||
// calculate and insert total length:
|
|
||||||
$newPlLen = $this->_secsToPlTime(
|
|
||||||
$this->_plTimeToSecs($plLen) + $this->_plTimeToSecs($acLen)
|
|
||||||
);
|
|
||||||
if(is_null($plLenMid)){
|
|
||||||
$r = $pl->md->insertMetadataEl(
|
|
||||||
$metaParid, 'dcterms:extent', $newPlLen);
|
|
||||||
}else{
|
|
||||||
$r = $pl->md->setMetadataEl($plLenMid, $newPlLen);
|
|
||||||
}
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
/* commented - maybe useless (C++ part doesn't do it)
|
|
||||||
// set access to audio clip:
|
|
||||||
$r = $this->bsAccess(NULL, '', $acGunid, 'access');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
$acToken = $r['token'];
|
|
||||||
// insert token attribute:
|
|
||||||
$r = $pl->md->insertMetadataEl($acId, 'accessToken', $acToken, 'A');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
*/
|
|
||||||
return $plElGunid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove audioclip from playlist
|
* Remove audioclip from playlist
|
||||||
*
|
*
|
||||||
* @param token string, playlist access token
|
* @param token string, playlist access token
|
||||||
* <span style="color:red">
|
* <span style="color:green">
|
||||||
* @param plElGunid string, global id of deleted playlistElement
|
* @param plElGunid string, global id of deleted playlistElement
|
||||||
* </span>
|
* </span>
|
||||||
* @param sessid string, session ID
|
* @param sessid string, session ID
|
||||||
|
@ -612,90 +521,34 @@ class GreenBox extends BasicStor{
|
||||||
*/
|
*/
|
||||||
function delAudioClipFromPlaylist($token, $plElGunid, $sessid)
|
function delAudioClipFromPlaylist($token, $plElGunid, $sessid)
|
||||||
{
|
{
|
||||||
// $acGunid = $this->_gunidFromId($acId);
|
require_once"Playlist.php";
|
||||||
// if(PEAR::isError($acGunid)) return $acGunid;
|
$pl =& Playlist::recallByToken($this, $token);
|
||||||
$plGunid = $this->_gunidFromToken($token, 'download');
|
if(PEAR::isError($pl)) return $pl;
|
||||||
if(PEAR::isError($plGunid)) return $plGunid;
|
$res = $pl->delAudioClip($plElGunid);
|
||||||
if(is_null($plGunid)){
|
if(PEAR::isError($res)) return $res;
|
||||||
return PEAR::raiseError(
|
return $res;
|
||||||
"GreenBox::addClipToPlaylist: invalid token"
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
$pl =& StoredFile::recallByGunid($this, $plGunid);
|
|
||||||
if(PEAR::isError($pl)){ return $pl; }
|
|
||||||
$id = $pl->getId();
|
|
||||||
|
|
||||||
// get main playlist container:
|
/**
|
||||||
$r = $pl->md->getMetadataEl('playlist');
|
* <span style="color:red">
|
||||||
if(PEAR::isError($r)){ return $r; }
|
* Change fadInfo values
|
||||||
$parid = $r[0]['mid'];
|
*
|
||||||
if(is_null($parid)){
|
* @param token string, playlist access token
|
||||||
return PEAR::raiseError(
|
* @param plElGunid string, global id of deleted playlistElement
|
||||||
"GreenBox::addClipToPlaylist: can't find main container"
|
* @param fadeIn string, optional, in time format hh:mm:ss.ssssss
|
||||||
);
|
* @param fadeOut string, dtto
|
||||||
}
|
* @param sessid string, session ID
|
||||||
// get playlist length and record id:
|
* @return boolean
|
||||||
$r = $pl->md->getMetadataEl('dcterms:extent');
|
* </span>
|
||||||
if(PEAR::isError($r)){ return $r; }
|
*/
|
||||||
$plLen = $r[0]['value'];
|
function changeFadeInfo($token, $plElGunid, $fadeIn, $fadeOut, $sessid)
|
||||||
$plLenMid = $r[0]['mid'];
|
{
|
||||||
// get array of playlist elements:
|
require_once"Playlist.php";
|
||||||
$plElArr = $pl->md->getMetadataEl('playlistElement', $parid);
|
$pl =& Playlist::recallByToken($this, $token);
|
||||||
if(PEAR::isError($plElArr)){ return $plElArr; }
|
if(PEAR::isError($pl)) return $pl;
|
||||||
$found = FALSE;
|
$res = $pl->changeFadeInfo($plElGunid, $fadeIn, $fadeOut);
|
||||||
foreach($plElArr as $el){
|
if(PEAR::isError($res)) return $res;
|
||||||
$plElGunidArr = $pl->md->getMetadataEl('id', $el['mid']);
|
return $res;
|
||||||
if(PEAR::isError($plElGunidArr)){ return $plElGunidArr; }
|
|
||||||
// select playlist element to remove
|
|
||||||
if($plElGunidArr[0]['value'] == $plElGunid){
|
|
||||||
$acArr = $pl->md->getMetadataEl('audioClip', $el['mid']);
|
|
||||||
if(PEAR::isError($acArr)){ return $acArr; }
|
|
||||||
$storedAcMid = $acArr[0]['mid'];
|
|
||||||
$acLenArr = $pl->md->getMetadataEl('playlength', $storedAcMid);
|
|
||||||
if(PEAR::isError($acLenArr)){ return $acLenArr; }
|
|
||||||
$acLen = $acLenArr[0]['value'];
|
|
||||||
/*
|
|
||||||
$acTokArr = $pl->md->getMetadataEl('accessToken', $storedAcMid);
|
|
||||||
if(PEAR::isError($acTokArr)){ return $acTokArr; }
|
|
||||||
$acToken = $acTokArr[0]['value'];
|
|
||||||
*/
|
|
||||||
// remove playlist element:
|
|
||||||
$r = $pl->md->setMetadataEl($el['mid'], NULL);
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
/*
|
|
||||||
// release audioClip:
|
|
||||||
$r = $this->bsRelease($acToken, 'access');
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
*/
|
|
||||||
$found = TRUE;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if($found){
|
|
||||||
// corect relative offsets in remaining elements:
|
|
||||||
$acOffArr = $pl->md->getMetadataEl('relativeOffset', $el['mid']);
|
|
||||||
if(PEAR::isError($acOffArr)){ return $acOffArr; }
|
|
||||||
$newOff = $this->_secsToPlTime(
|
|
||||||
$this->_plTimeToSecs($acOffArr[0]['value'])
|
|
||||||
-
|
|
||||||
$this->_plTimeToSecs($acLen)
|
|
||||||
);
|
|
||||||
$r = $pl->md->setMetadataEl($acOffArr[0]['mid'], $newOff);
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!$found){
|
|
||||||
return PEAR::raiseError(
|
|
||||||
"GreenBox::delAudioClipFromPlaylist: playlistElement not found".
|
|
||||||
" ($plElGunid)"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// correct total length:
|
|
||||||
$newPlLen = $this->_secsToPlTime(
|
|
||||||
$this->_plTimeToSecs($plLen) - $this->_plTimeToSecs($acLen)
|
|
||||||
);
|
|
||||||
$r = $pl->md->setMetadataEl($plLenMid, $newPlLen);
|
|
||||||
if(PEAR::isError($r)){ return $r; }
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -720,35 +573,6 @@ class GreenBox extends BasicStor{
|
||||||
return $gunid;
|
return $gunid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert playlist time value to float seconds
|
|
||||||
*
|
|
||||||
* @param plt string, playlist time value (HH:mm:ss.dddddd)
|
|
||||||
* @return int, seconds
|
|
||||||
*/
|
|
||||||
function _plTimeToSecs($plt)
|
|
||||||
{
|
|
||||||
$arr = split(':', $plt);
|
|
||||||
if(isset($arr[2])){ return ($arr[0]*60 + $arr[1])*60 + $arr[2]; }
|
|
||||||
if(isset($arr[1])){ return $arr[0]*60 + $arr[1]; }
|
|
||||||
return $arr[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert float seconds value to playlist time format
|
|
||||||
*
|
|
||||||
* @param s0 int, seconds
|
|
||||||
* @return string, time in playlist time format (HH:mm:ss.dddddd)
|
|
||||||
*/
|
|
||||||
function _secsToPlTime($s0)
|
|
||||||
{
|
|
||||||
$m = intval($s0 / 60);
|
|
||||||
$r = $s0 - $m*60;
|
|
||||||
$h = $m / 60;
|
|
||||||
$m = $m % 60;
|
|
||||||
return sprintf("%02d:%02d:%09.6f", $h, $m, $r);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a Playlist metafile.
|
* Delete a Playlist metafile.
|
||||||
*
|
*
|
||||||
|
|
446
livesupport/modules/storageServer/var/Playlist.php
Normal file
446
livesupport/modules/storageServer/var/Playlist.php
Normal file
|
@ -0,0 +1,446 @@
|
||||||
|
<?php
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: tomas $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Playlist.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Playlist extends StoredFile{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function recallByToken(&$gb, $token, $className='Playlist')
|
||||||
|
{
|
||||||
|
return parent::recallByToken($gb, $token, $className);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get audioClip legth and title
|
||||||
|
*/
|
||||||
|
function getAcInfo($acId)
|
||||||
|
{
|
||||||
|
$ac =& StoredFile::recall($this->gb, $acId);
|
||||||
|
if(PEAR::isError($ac)){ return $ac; }
|
||||||
|
$acGunid = $ac->gunid;
|
||||||
|
$r = $ac->md->getMetadataEl('dcterms:extent');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
if(isset($r[0]['value'])) $acLen = $r[0]['value'];
|
||||||
|
else $acLen = '00:00:00.000000';
|
||||||
|
$r = $ac->md->getMetadataEl('dc:title');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
if(isset($r[0]['value'])) $acTit = $r[0]['value'];
|
||||||
|
else $acTit = $acGunid;
|
||||||
|
return compact('acGunid', 'acLen', 'acTit');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get
|
||||||
|
*/
|
||||||
|
function getPlInfo()
|
||||||
|
{
|
||||||
|
// get playlist length and record id:
|
||||||
|
$r = $this->md->getMetadataEl('dcterms:extent');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
if(isset($r[0])){
|
||||||
|
$plLen = $r[0]['value'];
|
||||||
|
$plLenMid = $r[0]['mid'];
|
||||||
|
}else{
|
||||||
|
$plLen = '00:00:00.000000';
|
||||||
|
$plLenMid = NULL;
|
||||||
|
}
|
||||||
|
// get main playlist container
|
||||||
|
$parid = $this->getContainer('playlist');
|
||||||
|
if(PEAR::isError($parid)){ return $parid; }
|
||||||
|
// get metadata container (optionally insert it)
|
||||||
|
$metaParid = $this->getContainer('metadata', $parid, TRUE);
|
||||||
|
if(PEAR::isError($metaParid)){ return $metaParid; }
|
||||||
|
return compact('plLen', 'plLenMid', 'parid', 'metaParid');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get
|
||||||
|
*/
|
||||||
|
function getContainer($containerName, $parid=NULL, $insertIfNone=FALSE)
|
||||||
|
{
|
||||||
|
$r = $this->md->getMetadataEl($containerName, $parid);
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$id = $r[0]['mid'];
|
||||||
|
if(!is_null($id)) return $id;
|
||||||
|
if(!$insertIfNone || is_null($parid)){
|
||||||
|
return PEAR::raiseError(
|
||||||
|
"Playlist::getContainer: can't find container ($containerName)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$id = $this->md->insertMetadataEl($parid, $containerName);
|
||||||
|
if(PEAR::isError($id)){ return $id; }
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get
|
||||||
|
*/
|
||||||
|
function insertPlaylistElement($parid, $offset,
|
||||||
|
$acGunid, $acLen, $acTit, $fadeIn=NULL, $fadeOut=NULL)
|
||||||
|
{
|
||||||
|
// insert playlistElement
|
||||||
|
$r = $this->md->insertMetadataEl($parid, 'playlistElement');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$plElId = $r;
|
||||||
|
// create and insert gunid (id attribute)
|
||||||
|
$plElGunid = StoredFile::_createGunid();
|
||||||
|
$r = $this->md->insertMetadataEl($plElId, 'id', $plElGunid, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
// insert relativeOffset
|
||||||
|
$r = $this->md->insertMetadataEl(
|
||||||
|
$plElId, 'relativeOffset', $offset, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
// insert audioClip element into playlistElement
|
||||||
|
$r = $this->md->insertMetadataEl($plElId, 'audioClip');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$acId = $r;
|
||||||
|
$r = $this->md->insertMetadataEl($acId, 'id', $acGunid, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$r = $this->md->insertMetadataEl($acId, 'playlength', $acLen, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$r = $this->md->insertMetadataEl($acId, 'title', $acTit, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$fadeInId=NULL;
|
||||||
|
$fadeOutId=NULL;
|
||||||
|
if(!is_null($fadeIn) || !is_null($fadeOut)){
|
||||||
|
// insert fadeInfo element into playlistElement
|
||||||
|
$r = $this->md->insertMetadataEl($plElId, 'fadeInfo');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$fiId = $r;
|
||||||
|
$fiGunid = StoredFile::_createGunid();
|
||||||
|
$r = $this->md->insertMetadataEl($fiId, 'id', $fiGunid, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$r = $this->md->insertMetadataEl($fiId, 'fadeIn', $fadeIn, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$fadeInId = $r;
|
||||||
|
$r = $this->md->insertMetadataEl($fiId, 'fadeOut', $fadeOut, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$fadeOutId = $r;
|
||||||
|
}
|
||||||
|
return compact('plElId', 'plElGunid', 'fadeInId', 'fadeOutId');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set
|
||||||
|
*/
|
||||||
|
function _getMidOrInsert($category, $parid, $value=NULL, $predxml='T')
|
||||||
|
{
|
||||||
|
$arr = $this->md->getMetadataEl($category, $parid);
|
||||||
|
if(PEAR::isError($arr)){ return $arr; }
|
||||||
|
$mid = NULL;
|
||||||
|
if(isset($arr[0]['mid'])) $mid = $arr[0]['mid'];
|
||||||
|
if(!is_null($mid)) return $mid;
|
||||||
|
$mid = $this->md->insertMetadataEl($parid, $category, $value, $predxml);
|
||||||
|
if(PEAR::isError($mid)){ return $mid; }
|
||||||
|
return $mid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set
|
||||||
|
*/
|
||||||
|
function _setValueOrInsert($mid, $value, $parid, $category)
|
||||||
|
{
|
||||||
|
if(is_null($mid)){
|
||||||
|
$r = $this->md->insertMetadataEl($parid, $category, $value);
|
||||||
|
}else{
|
||||||
|
$r = $this->md->setMetadataEl($mid, $value);
|
||||||
|
}
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set
|
||||||
|
*/
|
||||||
|
function setPlaylistLength($newPlLen, $plLenMid, $metaParid)
|
||||||
|
{
|
||||||
|
$r = $this->_setValueOrInsert(
|
||||||
|
$plLenMid, $newPlLen, $metaParid, 'dcterms:extent');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add audioclip specified by gunid to the playlist
|
||||||
|
*
|
||||||
|
* @param acId string, local ID of added file
|
||||||
|
* @param fadeIn string, optional, in time format hh:mm:ss.ssssss
|
||||||
|
* @param fadeOut string, dtto
|
||||||
|
* @return string, generated playlistElement gunid
|
||||||
|
*/
|
||||||
|
function addAudioClip($acId, $fadeIn=NULL, $fadeOut=NULL)
|
||||||
|
{
|
||||||
|
$plGunid = $this->gunid;
|
||||||
|
// get information about audioClip
|
||||||
|
$acInfo = $this->getAcInfo($acId);
|
||||||
|
if(PEAR::isError($acInfo)){ return $acInfo; }
|
||||||
|
extract($acInfo); // 'acGunid', 'acLen', 'acTit'
|
||||||
|
// get information about playlist and containers
|
||||||
|
$plInfo = $this->getPlInfo();
|
||||||
|
if(PEAR::isError($plInfo)){ return $plInfo; }
|
||||||
|
extract($plInfo); // 'plLen', 'plLenMid', 'parid', 'metaParid'
|
||||||
|
|
||||||
|
// insert new playlist element
|
||||||
|
$offset = $plLen;
|
||||||
|
$plElInfo = $this->insertPlaylistElement($parid, $offset,
|
||||||
|
$acGunid, $acLen, $acTit, $fadeIn, $fadeOut);
|
||||||
|
if(PEAR::isError($plElInfo)){ return $plElnfo; }
|
||||||
|
extract($plElInfo); // 'plElId', 'plElGunid', 'fadeInId', 'fadeOutId'
|
||||||
|
|
||||||
|
/* commented - maybe useless (C++ part doesn't do it)
|
||||||
|
// set access to audio clip:
|
||||||
|
$r = $this->bsAccess(NULL, '', $acGunid, 'access');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$acToken = $r['token'];
|
||||||
|
// insert token attribute:
|
||||||
|
$r = $this->md->insertMetadataEl($acId, 'accessToken', $acToken, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
*/
|
||||||
|
// recalculate offsets and total length:
|
||||||
|
$r = $this->recalculateTimes();
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
return $plElGunid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove audioclip from playlist
|
||||||
|
*
|
||||||
|
* @param token string, playlist access token
|
||||||
|
* @param plElGunid string, global id of deleted playlistElement
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function delAudioClip($plElGunid)
|
||||||
|
{
|
||||||
|
$plGunid = $this->gunid;
|
||||||
|
// get information about playlist and containers
|
||||||
|
$plInfo = $this->getPlInfo();
|
||||||
|
if(PEAR::isError($plInfo)){ return $plInfo; }
|
||||||
|
extract($plInfo); // 'plLen', 'plLenMid', 'parid', 'metaParid'
|
||||||
|
|
||||||
|
// get array of playlist elements:
|
||||||
|
$plElArr = $this->md->getMetadataEl('playlistElement', $parid);
|
||||||
|
if(PEAR::isError($plElArr)){ return $plElArr; }
|
||||||
|
$found = FALSE;
|
||||||
|
foreach($plElArr as $el){
|
||||||
|
$plElGunidArr = $this->md->getMetadataEl('id', $el['mid']);
|
||||||
|
if(PEAR::isError($plElGunidArr)){ return $plElGunidArr; }
|
||||||
|
// select playlist element to remove
|
||||||
|
if($plElGunidArr[0]['value'] == $plElGunid){
|
||||||
|
$acArr = $this->md->getMetadataEl('audioClip', $el['mid']);
|
||||||
|
if(PEAR::isError($acArr)){ return $acArr; }
|
||||||
|
$storedAcMid = $acArr[0]['mid'];
|
||||||
|
$acLenArr = $this->md->getMetadataEl('playlength', $storedAcMid);
|
||||||
|
if(PEAR::isError($acLenArr)){ return $acLenArr; }
|
||||||
|
$acLen = $acLenArr[0]['value'];
|
||||||
|
/*
|
||||||
|
$acTokArr = $this->md->getMetadataEl('accessToken', $storedAcMid);
|
||||||
|
if(PEAR::isError($acTokArr)){ return $acTokArr; }
|
||||||
|
$acToken = $acTokArr[0]['value'];
|
||||||
|
*/
|
||||||
|
// remove playlist element:
|
||||||
|
$r = $this->md->setMetadataEl($el['mid'], NULL);
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
/*
|
||||||
|
// release audioClip:
|
||||||
|
$r = $this->bsRelease($acToken, 'access');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
*/
|
||||||
|
$found = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!$found){
|
||||||
|
return PEAR::raiseError(
|
||||||
|
"Playlist::delAudioClip: playlistElement not found".
|
||||||
|
" ($plElGunid)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// recalculate offsets and total length:
|
||||||
|
$r = $this->recalculateTimes();
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function changeFadeInfo($plElGunid, $fadeIn, $fadeOut)
|
||||||
|
{
|
||||||
|
$plGunid = $this->gunid;
|
||||||
|
// get information about playlist and containers
|
||||||
|
$plInfo = $this->getPlInfo();
|
||||||
|
if(PEAR::isError($plInfo)){ return $plInfo; }
|
||||||
|
extract($plInfo); // 'plLen', 'plLenMid', 'parid', 'metaParid'
|
||||||
|
|
||||||
|
// get array of playlist elements:
|
||||||
|
$plElArr = $this->md->getMetadataEl('playlistElement', $parid);
|
||||||
|
if(PEAR::isError($plElArr)){ return $plElArr; }
|
||||||
|
$found = FALSE;
|
||||||
|
foreach($plElArr as $el){
|
||||||
|
$plElGunidArr = $this->md->getMetadataEl('id', $el['mid']);
|
||||||
|
if(PEAR::isError($plElGunidArr)){ return $plElGunidArr; }
|
||||||
|
// select playlist element:
|
||||||
|
if($plElGunidArr[0]['value'] != $plElGunid){ continue; }
|
||||||
|
// get fadeInfo:
|
||||||
|
$fiMid = $this->_getMidOrInsert('fadeInfo', $el['mid']);
|
||||||
|
if(PEAR::isError($fiMid)){ return $fiMid; }
|
||||||
|
$fiGunid = StoredFile::_createGunid();
|
||||||
|
$r = $this->_getMidOrInsert('id', $fiMid, $fiGunid, 'A');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$fadeInId = $this->_getMidOrInsert('fadeIn', $fiMid, NULL, 'A');
|
||||||
|
if(PEAR::isError($fadeInId)){ return $fadeInId; }
|
||||||
|
$fadeOutId = $this->_getMidOrInsert('fadeOut', $fiMid, NULL, 'A');
|
||||||
|
if(PEAR::isError($fadeOutId)){ return $fadeOutId; }
|
||||||
|
$r = $this->_setValueOrInsert(
|
||||||
|
$fadeInId, $fadeIn, $fiMid, 'fadeIn');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$r = $this->_setValueOrInsert(
|
||||||
|
$fadeOutId, $fadeOut, $fiMid, 'fadeOut');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
}
|
||||||
|
$r = $this->recalculateTimes();
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function recalculateTimes()
|
||||||
|
{
|
||||||
|
$plGunid = $this->gunid;
|
||||||
|
// get information about playlist and containers
|
||||||
|
$plInfo = $this->getPlInfo();
|
||||||
|
if(PEAR::isError($plInfo)){ return $plInfo; }
|
||||||
|
extract($plInfo); // 'plLen', 'plLenMid', 'parid', 'metaParid'
|
||||||
|
// get array of playlist elements:
|
||||||
|
$plElArr = $this->md->getMetadataEl('playlistElement', $parid);
|
||||||
|
if(PEAR::isError($plElArr)){ return $plElArr; }
|
||||||
|
$peArr = array();
|
||||||
|
$len = 0; $nextOffset = $len;
|
||||||
|
foreach($plElArr as $el){
|
||||||
|
$elId = $el['mid'];
|
||||||
|
// get playlistElement gunid:
|
||||||
|
$plElGunidArr = $this->md->getMetadataEl('id', $elId);
|
||||||
|
if(PEAR::isError($plElGunidArr)){ return $plElGunidArr; }
|
||||||
|
$plElGunid = $plElGunidArr[0]['value'];
|
||||||
|
// get relativeoffset:
|
||||||
|
$offArr = $this->md->getMetadataEl('relativeoffset', $elId);
|
||||||
|
if(PEAR::isError($offArr)){ return $offArr; }
|
||||||
|
$offsetId = $offArr[0]['mid'];
|
||||||
|
$offset = $offArr[0]['value'];
|
||||||
|
// get audioClip:
|
||||||
|
$acArr = $this->md->getMetadataEl('audioClip', $elId);
|
||||||
|
if(PEAR::isError($acArr)){ return $acArr; }
|
||||||
|
$storedAcMid = $acArr[0]['mid'];
|
||||||
|
// get playlength:
|
||||||
|
$acLenArr = $this->md->getMetadataEl('playlength', $storedAcMid);
|
||||||
|
if(PEAR::isError($acLenArr)){ return $acLenArr; }
|
||||||
|
$acLen = $acLenArr[0]['value'];
|
||||||
|
// get fadeInfo:
|
||||||
|
$fiArr = $this->md->getMetadataEl('fadeInfo', $elId);
|
||||||
|
if(PEAR::isError($fiArr)){ return $fiArr; }
|
||||||
|
if(isset($fiArr[0]['mid'])){
|
||||||
|
$fiMid = $fiArr[0]['mid'];
|
||||||
|
$fadeInArr = $this->md->getMetadataEl('fadeIn', $fiMid);
|
||||||
|
if(PEAR::isError($fadeInArr)){ return $fadeInArr; }
|
||||||
|
$fadeIn = $fadeInArr[0]['value'];
|
||||||
|
$fadeOutArr = $this->md->getMetadataEl('fadeOut', $fiMid);
|
||||||
|
if(PEAR::isError($fadeOutArr)){ return $fadeOutArr; }
|
||||||
|
$fadeOut = $fadeOutArr[0]['value'];
|
||||||
|
}else{
|
||||||
|
$fadeIn = '00:00:00.000000';
|
||||||
|
$fadeOut = '00:00:00.000000';
|
||||||
|
}
|
||||||
|
// $peArr[] = array('id'=>$elId, 'gunid'=>$plElGunid, 'len'=>$acLen,
|
||||||
|
// 'offset'=>$offset, 'offsetId'=>$offsetId,
|
||||||
|
// 'fadeIn'=>$fadeIn, 'fadeOut'=>$fadeOut);
|
||||||
|
// set relativeOffset:
|
||||||
|
$fadeInS = $this->_plTimeToSecs($fadeIn);
|
||||||
|
if($len>0) $len = $len - $fadeInS;
|
||||||
|
$newOffset = $this->_secsToPlTime($len);
|
||||||
|
$r = $this->_setValueOrInsert(
|
||||||
|
$offsetId, $newOffset, $elId, 'relativeOffset');
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
// $fadeInS = $this->_plTimeToSecs($fadeIn);
|
||||||
|
$acLenS = $this->_plTimeToSecs($acLen);
|
||||||
|
$len = $len + $acLenS;
|
||||||
|
}
|
||||||
|
$newPlLen = $this->_secsToPlTime($len);
|
||||||
|
$r = $this->setPlaylistLength($newPlLen, $plLenMid, $metaParid);
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert playlist time value to float seconds
|
||||||
|
*
|
||||||
|
* @param plt string, playlist time value (HH:mm:ss.dddddd)
|
||||||
|
* @return int, seconds
|
||||||
|
*/
|
||||||
|
function _plTimeToSecs($plt)
|
||||||
|
{
|
||||||
|
$arr = split(':', $plt);
|
||||||
|
if(isset($arr[2])){ return ($arr[0]*60 + $arr[1])*60 + $arr[2]; }
|
||||||
|
if(isset($arr[1])){ return $arr[0]*60 + $arr[1]; }
|
||||||
|
return $arr[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert float seconds value to playlist time format
|
||||||
|
*
|
||||||
|
* @param s0 int, seconds
|
||||||
|
* @return string, time in playlist time format (HH:mm:ss.dddddd)
|
||||||
|
*/
|
||||||
|
function _secsToPlTime($s0)
|
||||||
|
{
|
||||||
|
$m = intval($s0 / 60);
|
||||||
|
$r = $s0 - $m*60;
|
||||||
|
$h = $m / 60;
|
||||||
|
$m = $m % 60;
|
||||||
|
return sprintf("%02d:%02d:%09.6f", $h, $m, $r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* /
|
||||||
|
function ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue