Converted comments to Phpdocumentor format. Added @author, @version, @package, and @subpackage doc tags. Reformatted code to Campware PHP coding conventions.
This commit is contained in:
parent
9370f5c88d
commit
da81b6e80c
|
@ -8,7 +8,7 @@
|
|||
<body>
|
||||
<h1>Preface</h1>
|
||||
This document is part of the
|
||||
<a href="http://livesupport.campware.org/">LiveSupport</a>
|
||||
<a href="http://campcaster.campware.org/">Campcaster</a>
|
||||
project, Copyright © 2004 <a href="http://www.mdlf.org/">Media
|
||||
Development Loan Fund</a>, under the GNU <a
|
||||
href="http://www.gnu.org/licenses/gpl.html">GPL</a>.<br>
|
||||
|
|
|
@ -10,31 +10,35 @@ define('INDCH', ' ');
|
|||
* @subpackage StorageServer
|
||||
*/
|
||||
class M3uPlaylist {
|
||||
|
||||
/**
|
||||
* Parse M3U file or string
|
||||
* Parse M3U file or string
|
||||
*
|
||||
* @param data string, local path to M3U file or M3U string
|
||||
* @param loc string, location: 'file'|'string'
|
||||
* @return array reference, parse result tree (or PEAR::error)
|
||||
* @param string $data
|
||||
* local path to M3U file or M3U string
|
||||
* @param string $loc
|
||||
* location: 'file'|'string'
|
||||
* @return array
|
||||
* reference, parse result tree (or PEAR::error)
|
||||
*/
|
||||
function &parse($data='', $loc='file')
|
||||
{
|
||||
switch($loc){
|
||||
case"file":
|
||||
if(!is_file($data)){
|
||||
switch ($loc) {
|
||||
case "file":
|
||||
if (!is_file($data)) {
|
||||
return PEAR::raiseError(
|
||||
"M3uPlaylist::parse: file not found ($data)"
|
||||
);
|
||||
}
|
||||
if(!is_readable($data)){
|
||||
if (!is_readable($data)) {
|
||||
return PEAR::raiseError(
|
||||
"M3uPlaylist::parse: can't read file ($data)"
|
||||
);
|
||||
}
|
||||
$data = file_get_contents($data);
|
||||
case"string":
|
||||
case "string":
|
||||
$arr = preg_split("|\n#EXTINF: |", $data);
|
||||
if($arr[0] != '#EXTM3U'){
|
||||
if ($arr[0] != '#EXTM3U') {
|
||||
return PEAR::raiseError(
|
||||
"M3uPlaylist::parse: invalid M3U header"
|
||||
);
|
||||
|
@ -49,81 +53,109 @@ class M3uPlaylist {
|
|||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import M3U file to storage
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param aPath string, absolute path part of imported file
|
||||
* (e.g. /home/user/campcaster)
|
||||
* @param rPath string, relative path/filename part of imported file
|
||||
* (e.g. playlists/playlist_1.smil)
|
||||
* @param gunids hasharray, hash relation from filenames to gunids
|
||||
* @param plid string, playlist gunid
|
||||
* @param parid int, destination folder local id
|
||||
* @param subjid int, local subject (user) id (id of user doing the import)
|
||||
* @return instance of Playlist object
|
||||
* @param GreenBox $gb
|
||||
* @param string $aPath
|
||||
* absolute path part of imported file (e.g. /home/user/campcaster)
|
||||
* @param string $rPath
|
||||
* relative path/filename part of imported file
|
||||
* (e.g. playlists/playlist_1.smil)
|
||||
* @param array $gunids
|
||||
* hash relation from filenames to gunids
|
||||
* @param string $plid
|
||||
* playlist gunid
|
||||
* @param int $parid
|
||||
* destination folder local id
|
||||
* @param int $subjid
|
||||
* local subject (user) id (id of user doing the import)
|
||||
* @return Playlist
|
||||
*/
|
||||
function import(&$gb, $aPath, $rPath, &$gunids, $plid, $parid, $subjid=NULL){
|
||||
function import(&$gb, $aPath, $rPath, &$gunids, $plid, $parid, $subjid=NULL)
|
||||
{
|
||||
$path = realpath("$aPath/$rPath");
|
||||
if(FALSE === $path){
|
||||
if (FALSE === $path) {
|
||||
return PEAR::raiseError(
|
||||
"M3uPlaylist::import: file doesn't exist ($aPath/$rPath)"
|
||||
);
|
||||
}
|
||||
$arr = $r = M3uPlaylist::parse($path);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
require_once "Playlist.php";
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
require_once("Playlist.php");
|
||||
$pl = $r =& Playlist::create($gb, $plid, "imported_M3U", $parid);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$r = $pl->lock($gb, $subjid);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
foreach($arr as $i=>$it){
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
foreach ($arr as $i => $it) {
|
||||
list($md, $uri) = preg_split("|\n|", $it);
|
||||
list($length, $title) = preg_split("|, *|", $md);
|
||||
// $gunid = StoredFile::_createGunid();
|
||||
$gunid = ( isset($gunids[basename($uri)]) ? $gunids[basename($uri)] : NULL);
|
||||
$acId = $r = $gb->_idFromGunid($gunid);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$length = Playlist::_secsToPlTime($length);
|
||||
$offset = '???';
|
||||
if(preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)){
|
||||
switch(strtolower($ext = $va[1])){
|
||||
case"lspl":
|
||||
case"xml":
|
||||
case"smil":
|
||||
case"m3u":
|
||||
if (preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)) {
|
||||
switch (strtolower($ext = $va[1])) {
|
||||
case "lspl":
|
||||
case "xml":
|
||||
case "smil":
|
||||
case "m3u":
|
||||
$acId = $r = $gb->bsImportPlaylistRaw($parid, $gunid,
|
||||
$aPath, $uri, $ext, $gunids, $subjid);
|
||||
if(PEAR::isError($r)) break;
|
||||
if (PEAR::isError($r)) {
|
||||
break;
|
||||
}
|
||||
//no break!
|
||||
default:
|
||||
if(is_null($gunid)){
|
||||
if (is_null($gunid)) {
|
||||
return PEAR::raiseError(
|
||||
"M3uPlaylist::import: no gunid");
|
||||
}
|
||||
$r = $pl->addAudioClip($acId);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$r = $pl->unLock($gb);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
return $pl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import M3U file to storage
|
||||
* Import M3U file to storage
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param data string, local path to M3U file
|
||||
* @return XML string - playlist in Campcaster playlist format
|
||||
* @param GreenBox $gb
|
||||
* @param string $data
|
||||
* local path to M3U file
|
||||
* @return string
|
||||
* XML playlist in Campcaster playlist format
|
||||
*/
|
||||
function convert2lspl(&$gb, $data){
|
||||
function convert2lspl(&$gb, $data)
|
||||
{
|
||||
$arr = $r = M3uPlaylist::parse($data);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
$ind = ''; $ind2 = $ind.INDCH; $ind3 = $ind2.INDCH;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$ind = '';
|
||||
$ind2 = $ind.INDCH;
|
||||
$ind3 = $ind2.INDCH;
|
||||
$res = '';
|
||||
foreach($arr as $i=>$it){
|
||||
foreach ($arr as $i => $it) {
|
||||
list($md, $uri) = preg_split("|\n|", $it);
|
||||
list($length, $title) = preg_split("|, *|", $md);
|
||||
$gunid = StoredFile::_createGunid();
|
||||
|
@ -131,12 +163,12 @@ class M3uPlaylist {
|
|||
$length = Playlist::_secsToPlTime($length);
|
||||
$offset = '???';
|
||||
$uri_h = preg_replace("|--|", "d;d;", htmlspecialchars("$uri"));
|
||||
if(preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)){
|
||||
switch(strtolower($ext = $va[1])){
|
||||
case"lspl":
|
||||
case"xml":
|
||||
case"smil":
|
||||
case"m3u":
|
||||
if (preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)) {
|
||||
switch (strtolower($ext = $va[1])) {
|
||||
case "lspl":
|
||||
case "xml":
|
||||
case "smil":
|
||||
case "m3u":
|
||||
$acOrPl = "$ind3<playlist id=\"$gunid2\" ".
|
||||
"playlength=\"$length\" title=\"$title\"/> ".
|
||||
"<!-- $uri_h -->\n";
|
||||
|
@ -159,18 +191,23 @@ class M3uPlaylist {
|
|||
"$ind</playlist>\n";
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
} // class M3uPlaylist
|
||||
|
||||
|
||||
/**
|
||||
* Several auxiliary classes follows
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class M3uPlaylistBodyElement{
|
||||
function convert2lspl(&$tree, $ind=''){
|
||||
class M3uPlaylistBodyElement {
|
||||
function convert2lspl(&$tree, $ind='')
|
||||
{
|
||||
$ind2 = $ind.INDCH;
|
||||
if($tree->name != 'body'){
|
||||
if ($tree->name != 'body') {
|
||||
return PEAR::raiseError("M3uPlaylist::parse: body tag expected");
|
||||
}
|
||||
if(isset($tree->children[1])){
|
||||
if (isset($tree->children[1])) {
|
||||
return PEAR::raiseError(sprintf(
|
||||
"M3uPlaylist::parse: unexpected tag %s in tag body",
|
||||
$tree->children[1]->name
|
||||
|
@ -178,9 +215,11 @@ class M3uPlaylistBodyElement{
|
|||
}
|
||||
$res = $r =
|
||||
M3uPlaylistParElement::convert2lspl($tree->children[0], $ind2);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
$gunid = StoredFile::_createGunid();
|
||||
$playlength = '???'; # ***
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$gunid = StoredFile::_createGunid();
|
||||
$playlength = '???'; // ***
|
||||
$res = "$ind<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
|
||||
"$ind<playlist id=\"$gunid\" playlength=\"$playlength\" title=\"\">\n".
|
||||
"$ind2<metadata/>\n".
|
||||
|
@ -190,49 +229,75 @@ class M3uPlaylistBodyElement{
|
|||
}
|
||||
}
|
||||
|
||||
class M3uPlaylistParElement{
|
||||
function convert2lspl(&$tree, $ind=''){
|
||||
if($tree->name != 'par'){
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class M3uPlaylistParElement {
|
||||
function convert2lspl(&$tree, $ind='')
|
||||
{
|
||||
if ($tree->name != 'par') {
|
||||
return PEAR::raiseError("M3uPlaylist::parse: par tag expected");
|
||||
}
|
||||
$res = '';
|
||||
foreach($tree->children as $i=>$ch){
|
||||
foreach ($tree->children as $i => $ch) {
|
||||
$ch =& $tree->children[$i];
|
||||
$r = M3uPlaylistAudioElement::convert2lspl($ch, $ind.INDCH);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
$res .= $r;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
class M3uPlaylistAudioElement{
|
||||
function convert2lspl(&$tree, $ind=''){
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class M3uPlaylistAudioElement {
|
||||
function convert2lspl(&$tree, $ind='')
|
||||
{
|
||||
$ind2 = $ind.INDCH;
|
||||
if($tree->name != 'audio'){
|
||||
if ($tree->name != 'audio') {
|
||||
return PEAR::raiseError("M3uPlaylist::parse: audio tag expected");
|
||||
}
|
||||
if(isset($tree->children[2])){
|
||||
if (isset($tree->children[2])) {
|
||||
return PEAR::raiseError(sprintf(
|
||||
"M3uPlaylist::parse: unexpected tag %s in tag audio",
|
||||
$tree->children[2]->name
|
||||
));
|
||||
}
|
||||
$res = ''; $fadeIn = 0; $fadeOut = 0;
|
||||
foreach($tree->children as $i=>$ch){
|
||||
foreach ($tree->children as $i => $ch) {
|
||||
$ch =& $tree->children[$i];
|
||||
$r = M3uPlaylistAnimateElement::convert2lspl($ch, $ind2);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
switch($r['type']){
|
||||
case"fadeIn": $fadeIn = $r['val']; break;
|
||||
case"fadeOut": $fadeOut = $r['val']; break;
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
switch ($r['type']) {
|
||||
case "fadeIn":
|
||||
$fadeIn = $r['val'];
|
||||
break;
|
||||
case "fadeOut":
|
||||
$fadeOut = $r['val'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($fadeIn > 0 || $fadeOut > 0){
|
||||
if ($fadeIn > 0 || $fadeOut > 0) {
|
||||
$fadeIn = Playlist::_secsToPlTime($fadeIn);
|
||||
$fadeOut = Playlist::_secsToPlTime($fadeOut);
|
||||
$fInfo = "$ind2<fadeInfo fadeIn=\"$fadeIn\" fadeOut=\"$fadeOut\"/>\n";
|
||||
}else $fInfo = '';
|
||||
} else {
|
||||
$fInfo = '';
|
||||
}
|
||||
$plElGunid = StoredFile::_createGunid();
|
||||
$aGunid = StoredFile::_createGunid();
|
||||
$title = basename($tree->attrs['src']->val);
|
||||
|
@ -244,31 +309,38 @@ class M3uPlaylistAudioElement{
|
|||
"$ind</playlistElement>\n";
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
} // class M3uPlaylistAudioElement
|
||||
|
||||
class M3uPlaylistAnimateElement{
|
||||
function convert2lspl(&$tree, $ind=''){
|
||||
if($tree->name != 'animate'){
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class M3uPlaylistAnimateElement {
|
||||
function convert2lspl(&$tree, $ind='') {
|
||||
if ($tree->name != 'animate') {
|
||||
return PEAR::raiseError("M3uPlaylist::parse: animate tag expected");
|
||||
}
|
||||
if($tree->attrs['attributeName']->val == 'soundLevel' &&
|
||||
if ($tree->attrs['attributeName']->val == 'soundLevel' &&
|
||||
$tree->attrs['from']->val == '0%' &&
|
||||
$tree->attrs['to']->val == '100%' &&
|
||||
$tree->attrs['calcMode']->val == 'linear' &&
|
||||
$tree->attrs['fill']->val == 'freeze' &&
|
||||
$tree->attrs['begin']->val == '0s' &&
|
||||
preg_match("|^([0-9.]+)s$|", $tree->attrs['end']->val, $va)
|
||||
){
|
||||
) {
|
||||
return array('type'=>'fadeIn', 'val'=>$va[1]);
|
||||
}
|
||||
if($tree->attrs['attributeName']->val == 'soundLevel' &&
|
||||
if ($tree->attrs['attributeName']->val == 'soundLevel' &&
|
||||
$tree->attrs['from']->val == '100%' &&
|
||||
$tree->attrs['to']->val == '0%' &&
|
||||
$tree->attrs['calcMode']->val == 'linear' &&
|
||||
$tree->attrs['fill']->val == 'freeze' &&
|
||||
preg_match("|^([0-9.]+)s$|", $tree->attrs['begin']->val, $vaBegin) &&
|
||||
preg_match("|^([0-9.]+)s$|", $tree->attrs['end']->val, $vaEnd)
|
||||
){
|
||||
) {
|
||||
return array('type'=>'fadeOut', 'val'=>($vaEnd[1] - $vaBegin[1]));
|
||||
}
|
||||
return PEAR::raiseError(
|
||||
|
|
|
@ -122,7 +122,10 @@ class SmilPlaylist {
|
|||
|
||||
|
||||
/**
|
||||
* Several auxiliary classes follows
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class SmilPlaylistBodyElement {
|
||||
|
||||
|
@ -157,6 +160,12 @@ class SmilPlaylistBodyElement {
|
|||
} // class SmilPlaylistBodyElement
|
||||
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class SmilPlaylistParElement {
|
||||
|
||||
function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='')
|
||||
|
@ -179,6 +188,13 @@ class SmilPlaylistParElement {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class SmilPlaylistAudioElement {
|
||||
function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='')
|
||||
{
|
||||
|
@ -256,6 +272,12 @@ class SmilPlaylistAudioElement {
|
|||
} // class SmilPlaylistAudioElement
|
||||
|
||||
|
||||
/**
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
* @package Campcaster
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
class SmilPlaylistAnimateElement {
|
||||
|
||||
function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='')
|
||||
|
|
Loading…
Reference in New Issue