Beispiel #1
0
 function FormatDataForID3v2($id3v2_majorversion)
 {
     $tag_data_id3v2 = array();
     $ID3v2_text_encoding_lookup[2] = array('ISO-8859-1' => 0, 'UTF-16' => 1);
     $ID3v2_text_encoding_lookup[3] = array('ISO-8859-1' => 0, 'UTF-16' => 1);
     $ID3v2_text_encoding_lookup[4] = array('ISO-8859-1' => 0, 'UTF-16' => 1, 'UTF-16BE' => 2, 'UTF-8' => 3);
     foreach ($this->tag_data as $tag_key => $valuearray) {
         $ID3v2_framename = getid3_write_id3v2::ID3v2ShortFrameNameLookup($id3v2_majorversion, $tag_key);
         switch ($ID3v2_framename) {
             case 'APIC':
                 foreach ($valuearray as $key => $apic_data_array) {
                     if (isset($apic_data_array['data']) && isset($apic_data_array['picturetypeid']) && isset($apic_data_array['description']) && isset($apic_data_array['mime'])) {
                         $tag_data_id3v2['APIC'][] = $apic_data_array;
                     } else {
                         $this->errors[] = 'ID3v2 APIC data is not properly structured';
                         return false;
                     }
                 }
                 break;
             case '':
                 $this->errors[] = 'ID3v2: Skipping "' . $tag_key . '" because cannot match it to a known ID3v2 frame type';
                 // some other data type, don't know how to handle it, ignore it
                 break;
             default:
                 // most other (text) frames can be copied over as-is
                 foreach ($valuearray as $key => $value) {
                     if (isset($ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding])) {
                         // source encoding is valid in ID3v2 - use it with no conversion
                         $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = $ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding];
                         $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value;
                     } else {
                         // source encoding is NOT valid in ID3v2 - convert it to an ID3v2-valid encoding first
                         if ($id3v2_majorversion < 4) {
                             // convert data from other encoding to UTF-16
                             $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 1;
                             $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16', $value);
                         } else {
                             // convert data from other encoding to UTF-8
                             $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 3;
                             $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
                         }
                     }
                     // These values are not needed for all frame types, but if they're not used no matter
                     $tag_data_id3v2[$ID3v2_framename][$key]['description'] = '';
                     $tag_data_id3v2[$ID3v2_framename][$key]['language'] = $this->id3v2_tag_language;
                 }
                 break;
         }
     }
     $this->MergeExistingTagData('id3v2', $tag_data_id3v2);
     return $tag_data_id3v2;
 }
Beispiel #2
0
 function FormatDataForID3v2($id3v2_majorversion)
 {
     $tag_data_id3v2 = array();
     $ID3v2_text_encoding_lookup[2] = array('ISO-8859-1' => 0, 'UTF-16' => 1);
     $ID3v2_text_encoding_lookup[3] = array('ISO-8859-1' => 0, 'UTF-16' => 1);
     $ID3v2_text_encoding_lookup[4] = array('ISO-8859-1' => 0, 'UTF-16' => 1, 'UTF-16BE' => 2, 'UTF-8' => 3);
     foreach ($this->tag_data as $tag_key => $valuearray) {
         $ID3v2_framename = getid3_write_id3v2::ID3v2ShortFrameNameLookup($id3v2_majorversion, $tag_key);
         switch ($ID3v2_framename) {
             case 'APIC':
                 foreach ($valuearray as $key => $apic_data_array) {
                     if (isset($apic_data_array['data']) && isset($apic_data_array['picturetypeid']) && isset($apic_data_array['description']) && isset($apic_data_array['mime'])) {
                         $tag_data_id3v2['APIC'][] = $apic_data_array;
                     } else {
                         $this->errors[] = 'ID3v2 APIC data is not properly structured';
                         return false;
                     }
                 }
                 break;
             case '':
                 $this->errors[] = 'ID3v2: Skipping "' . $tag_key . '" because cannot match it to a known ID3v2 frame type';
                 // some other data type, don't know how to handle it, ignore it
                 break;
             default:
                 // most other (text) frames can be copied over as-is
                 foreach ($valuearray as $key => $value) {
                     if (isset($ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding])) {
                         // source encoding is valid in ID3v2 - use it with no conversion
                         $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = $ID3v2_text_encoding_lookup[$id3v2_majorversion][$this->tag_encoding];
                         $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value;
                     } else {
                         // source encoding is NOT valid in ID3v2 - convert it to an ID3v2-valid encoding first
                         if ($id3v2_majorversion < 4) {
                             // convert data from other encoding to UTF-16 (with BOM)
                             // note: some software, notably Windows Media Player and iTunes are broken and treat files tagged with UTF-16BE (with BOM) as corrupt
                             // therefore we force data to UTF-16LE and manually prepend the BOM
                             $ID3v2_tag_data_converted = false;
                             if (!$ID3v2_tag_data_converted && $this->tag_encoding == 'ISO-8859-1') {
                                 // great, leave data as-is for minimum compatability problems
                                 $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0;
                                 $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value;
                                 $ID3v2_tag_data_converted = true;
                             }
                             if (!$ID3v2_tag_data_converted && $this->tag_encoding == 'UTF-8') {
                                 do {
                                     // if UTF-8 string does not include any characters above chr(127) then it is identical to ISO-8859-1
                                     for ($i = 0; $i < strlen($value); $i++) {
                                         if (ord($value[$i]) > 127) {
                                             break 2;
                                         }
                                     }
                                     $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0;
                                     $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value;
                                     $ID3v2_tag_data_converted = true;
                                 } while (false);
                             }
                             if (!$ID3v2_tag_data_converted) {
                                 $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 1;
                                 //$tag_data_id3v2[$ID3v2_framename][$key]['data']       = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16', $value); // output is UTF-16LE+BOM or UTF-16BE+BOM depending on system architecture
                                 $tag_data_id3v2[$ID3v2_framename][$key]['data'] = "ÿþ" . getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-16LE', $value);
                                 // force LittleEndian order version of UTF-16
                                 $ID3v2_tag_data_converted = true;
                             }
                         } else {
                             // convert data from other encoding to UTF-8
                             $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 3;
                             $tag_data_id3v2[$ID3v2_framename][$key]['data'] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value);
                         }
                     }
                     // These values are not needed for all frame types, but if they're not used no matter
                     $tag_data_id3v2[$ID3v2_framename][$key]['description'] = '';
                     $tag_data_id3v2[$ID3v2_framename][$key]['language'] = $this->id3v2_tag_language;
                 }
                 break;
         }
     }
     $this->MergeExistingTagData('id3v2', $tag_data_id3v2);
     return $tag_data_id3v2;
 }
Beispiel #3
0
function kpgenerateid3v2tag($sid)
{
    global $cfg, $phpenv, $setctl;
    if ($cfg['enablegetid3']) {
        $f2 = new file2($sid, true);
        switch (GETID3_V) {
            case 16:
                require_once GETID3_INCLUDEPATH . 'getid3.id3v2.php';
                $data['id3v2']['TIT2'][0]['encodingid'] = 0;
                $data['id3v2']['TIT2'][0]['data'] = $f2->id3['title'];
                $data['id3v2']['TPE1'][0]['encodingid'] = 0;
                $data['id3v2']['TPE1'][0]['data'] = $f2->id3['artist'];
                $data['id3v2']['TALB'][0]['encodingid'] = 0;
                $data['id3v2']['TALB'][0]['data'] = $f2->id3['album'];
                $data['id3v2']['TRCK'][0]['encodingid'] = 0;
                $data['id3v2']['TRCK'][0]['data'] = $f2->id3['track'];
                $data['id3v2']['COM'][0]['encodingid'] = 0;
                $data['id3v2']['COM'][0]['data'] = $f2->id3['comment'];
                $data['id3v2']['TYER'][0]['encodingid'] = 0;
                $data['id3v2']['TYER'][0]['data'] = $f2->id3['year'];
                return GenerateID3v2Tag($data['id3v2'], 3, 0, 0, '', false, false, false);
                break;
            case 19:
            case 17:
                $tagformat = 'UTF-8';
                $major = 3;
                $getID3 = new getID3();
                $getID3->encoding = $tagformat;
                if (!defined('GETID3_INCLUDEPATH')) {
                    define('GETID3_INCLUDEPATH', dirname($cfg['getid3include']) . '/');
                }
                if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v2.php', __FILE__, false) && getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.php', __FILE__, false) && getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.id3v2.php', __FILE__, false)) {
                    $tagwriter = new getid3_writetags();
                    $tagwriter->tagformats = array('id3v2.3');
                    $tagwriter->filename = $f2->fullpath;
                    if (GETID3_V == 17) {
                        $tagwriter->overwrite_tags = false;
                    }
                    $tagwriter->tag_encoding = $tagformat;
                    $tagwriter->remove_other_tags = false;
                    $TagData['title'][0] = $f2->id3['title'];
                    $TagData['artist'][0] = $f2->id3['artist'];
                    $TagData['album'][0] = $f2->id3['album'];
                    if (vernum($f2->id3['year']) != 0) {
                        $TagData['year'][0] = vernum($f2->id3['year']);
                    }
                    $TagData['comment'][0] = $f2->id3['comment'];
                    $TagData['track'][0] = vernum($f2->id3['track']);
                    if (empty($TagData['title'][0])) {
                        $TagData['title'][0] = $f2->fname;
                    }
                    if (empty($TagData['artist'][0])) {
                        $TagData['artist'][0] = 'Unknown';
                    }
                    if (empty($TagData['album'][0])) {
                        $exp = explode('/', dirname($f2->fullpath));
                        if (count($exp) > 1) {
                            $TagData['album'][0] = $exp[count($exp) - 1];
                        }
                    }
                    $ci = new coverinterface();
                    $ci->setartist($f2->id3['artist'], $f2->id3['album']);
                    $ci->setlocation($f2->drive, $f2->relativepath);
                    if ($ci->coverexists()) {
                        if ($cfg['id3v2albumresize']) {
                            $rs = true;
                        } else {
                            $rs = false;
                        }
                        $imgdata = $ci->getimagedata($rs);
                        if (strlen($imgdata) > 0) {
                            if ($cfg['maxtagimagesize'] == 0 || strlen($imgdata) <= $cfg['maxtagimagesize']) {
                                $TagData['attached_picture'][0]['data'] = $imgdata;
                                $TagData['attached_picture'][0]['picturetypeid'] = 3;
                                $TagData['attached_picture'][0]['encodingid'] = 0;
                                $TagData['attached_picture'][0]['description'] = 'ART';
                                $TagData['attached_picture'][0]['mime'] = 'image/jpeg';
                            }
                        }
                    }
                    $tagwriter->tag_data = $TagData;
                    $id3v2_writer = new getid3_write_id3v2();
                    $id3v2_writer->majorversion = $major;
                    $id3v2_writer->paddedlength = 0;
                    if (($id3v2_writer->tag_data = $tagwriter->FormatDataForID3v2($major)) !== false) {
                        return $id3v2_writer->GenerateID3v2Tag();
                    }
                }
                break;
        }
    }
    return '';
}
// | Authors: James Heinrich <infoØgetid3*org>                            |
// |          Allan Hansen <ahØartemis*dk>                                |
// +----------------------------------------------------------------------+
// | demo.write.id3v2.php                                                 |
// | getID3() demo file - showing how to write id3v2 tags with getID3().  |
// +----------------------------------------------------------------------+
//
// $Id: demo.write.id3v2.php,v 1.1 2006/12/03 23:58:31 ah Exp $
// Enter your filename here
$filename = '/data/getid3/test.mp3';
// Include getID3() library (can be in a different directory if full path is specified)
require_once '../getid3/getid3.php';
// Include desired writer module
require_once '../getid3/write.id3v2.php';
// Instantiate desired tag class
$tw = new getid3_write_id3v2($filename);
// Attempt to read current tag
if ($tw->read()) {
    print 'File contains tag already; artist is "' . $tw->artist . '"<br>';
}
// Attempt to write new tag  -- NOTE: all values must be in ISO-8859-1
try {
    $tw->title = 'title';
    $tw->artist = 'artist';
    $tw->album = 'album';
    $tw->year = 2005;
    $tw->genre = 'Techno';
    unset($tw->genre_id);
    $tw->comment = 'comment';
    $tw->track = 11;
    $tw->write();