예제 #1
0
 public function processRecords()
 {
     // TODO bootstrap
     $success = function ($buffer) {
         /*echo '.'; */
     };
     $failure = function ($buffer) {
         echo 'ERROR: ' . $buffer;
     };
     // TODO retrieve stream format, e. g. ogg/vorbis for mephisto976, tag accordingly
     // http://stackoverflow.com/questions/23287341/how-to-get-mime-type-of-a-file-in-php-5-5/23287361#23287361
     $writer = new \GetId3\Write\Tags();
     $writer->tagformats = array('id3v2.3');
     $writer->tag_encoding = 'UTF-8';
     $streamrippers = array();
     // TODO cache that stuff
     foreach ($this->records as $request) {
         $record = array('station' => $this->stations[$request['station']], 'broadcast' => $this->broadcasts[$request['station']][$request['broadcast']], 'comment' => $request['comment']);
         /* BEGINN ALL DUE RECORDINGS, THEN WAIT ON FINISHED RECORDS TO TAG THEM */
         foreach ($record['broadcast']['cron'] as $cron) {
             if ($cron['due']) {
                 // TODO make class property $this->streamrippers
                 echo 'DUE: ' . $record['broadcast']['name'], PHP_EOL;
                 //var_dump($cron);
                 $record['active-cron'] = $cron;
                 $proceed = function ($file, $suceeded) use($writer, $record) {
                     // TODO mp3 conversion of aac files
                     //echo PHP_EOL, $suceeded ? 'DONE' : 'FAIL', ': ', $file, PHP_EOL;
                     $writer->filename = $file;
                     $writer->tag_data = array('ARTIST' => array($record['station']['name']), 'TITLE' => array(sprintf('%s: %s/%s/%s', $record['broadcast']['name'], $record['active-cron']['date']->format('d'), $record['active-cron']['date']->format('m'), $record['active-cron']['date']->format('Y'))), 'ALBUM' => array($record['broadcast']['name']), 'YEAR' => array($record['active-cron']['date']->format('Y')), 'COMMENT' => array('' ?: 'Radiorecorder 2014'), 'GENRE' => array(isset($record['broadcast']['tags'][0]) ? ucfirst(strtolower($record['broadcast']['tags'][0])) : ''));
                     if (!$writer->WriteTags()) {
                         echo 'Tags not written!', PHP_EOL;
                         // TODO handle failure
                     }
                     if ($writer->errors) {
                         var_dump('errors: ', $writer->errors);
                         // TODO handle failure
                     }
                     if ($writer->warnings) {
                         var_dump('warnings: ', $writer->warnings);
                         // TODO handle failure
                     }
                 };
                 $streamripper = $this->record($record);
                 // index by duration to ensure shortest broadcast are proceeded first
                 $streamrippers[$streamripper->getDuration()][] = array('instance' => $streamripper, 'proceed' => $proceed);
                 echo 'RECORDING STARTED', PHP_EOL;
             }
             $this->program[$record['station']['name']][$cron['date']->format('U')][] = array('cron' => $cron, 'record' => $record);
         }
     }
     // call wait and proceedures only after each recording has been started
     ksort($streamrippers);
     foreach ($streamrippers as $duration => $streamrippers_dur) {
         foreach ($streamrippers_dur as $streamripper) {
             $streamripper['instance']->waitAndProceed($success, $failure, $streamripper['proceed']);
         }
     }
 }
예제 #2
0
/////////////////////////////////////////////////////////////////
//                                                             //
// /demo/demo.simple.write.php - part of getID3()              //
// Sample script showing basic syntax for writing tags         //
// See readme.txt for more details                             //
//                                                            ///
/////////////////////////////////////////////////////////////////
die('Due to a security issue, this demo has been disabled. It can be enabled by removing line ' . __LINE__ . ' in ' . $_SERVER['PHP_SELF']);
$TaggingFormat = 'UTF-8';
require_once '../getid3/getid3.php';
// Initialize getID3 engine
$getID3 = new getID3();
$getID3->setOption(array('encoding' => $TaggingFormat));
require_once '../getid3/write.php';
// Initialize getID3 tag-writing module
$tagwriter = new GetId3\Write\Tags();
//$tagwriter->filename = '/path/to/file.mp3';
$tagwriter->filename = 'd:/file.mp3';
$tagwriter->filename = 'P:/webroot/_dev/getID3/testfiles/_writing/2011-02-02/test.mp3';
//$tagwriter->tagformats = array('id3v1', 'id3v2.3');
$tagwriter->tagformats = array('id3v2.3');
// set various options (optional)
$tagwriter->overwrite_tags = true;
$tagwriter->overwrite_tags = false;
$tagwriter->tag_encoding = $TaggingFormat;
$tagwriter->remove_other_tags = true;
// populate data array
$TagData = array('title' => array('My Song'), 'artist' => array('The Artist'), 'album' => array('Greatest Hits'), 'year' => array('2004'), 'genre' => array('Rock'), 'comment' => array('excellent!'), 'track' => array('04/16'));
$tagwriter->tag_data = $TagData;
// write tags
if ($tagwriter->WriteTags()) {
예제 #3
0
function SynchronizeAllTags($filename, $synchronizefrom = 'all', $synchronizeto = 'A12', &$errors)
{
    global $getID3;
    set_time_limit(30);
    $ThisFileInfo = $getID3->analyze($filename);
    getid3_lib::CopyTagsToComments($ThisFileInfo);
    if ($synchronizefrom == 'all') {
        $SourceArray = !empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : array();
    } elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) {
        $SourceArray = !empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : array();
    } else {
        die('ERROR: $ThisFileInfo[tags][' . $synchronizefrom . '] does not exist');
    }
    $SQLquery = 'DELETE FROM `' . mysql_real_escape_string(GETID3_DB_TABLE) . '`';
    $SQLquery .= ' WHERE (`filename` = "' . mysql_real_escape_string($filename) . '")';
    mysql_query_safe($SQLquery);
    $TagFormatsToWrite = array();
    if (strpos($synchronizeto, '2') !== false && $synchronizefrom != 'id3v2') {
        $TagFormatsToWrite[] = 'id3v2.3';
    }
    if (strpos($synchronizeto, 'A') !== false && $synchronizefrom != 'ape') {
        $TagFormatsToWrite[] = 'ape';
    }
    if (strpos($synchronizeto, 'L') !== false && $synchronizefrom != 'lyrics3') {
        $TagFormatsToWrite[] = 'lyrics3';
    }
    if (strpos($synchronizeto, '1') !== false && $synchronizefrom != 'id3v1') {
        $TagFormatsToWrite[] = 'id3v1';
    }
    getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.php', __FILE__, true);
    $tagwriter = new GetId3\Write\Tags();
    $tagwriter->filename = $filename;
    $tagwriter->tagformats = $TagFormatsToWrite;
    $tagwriter->overwrite_tags = true;
    $tagwriter->tag_encoding = $getID3->encoding;
    $tagwriter->tag_data = $SourceArray;
    if ($tagwriter->WriteTags()) {
        $errors = $tagwriter->errors;
        return true;
    }
    $errors = $tagwriter->errors;
    return false;
}