123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- if (!defined('GETID3_INCLUDEPATH')) {
- exit;
- }
- getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
- class getid3_write_id3v1
- {
-
- public $filename;
-
- public $filesize;
-
- public $tag_data;
-
- public $warnings = array();
-
- public $errors = array();
- public function __construct() {
- }
-
- public function WriteID3v1() {
-
- if (!empty($this->filename) && is_readable($this->filename) && getID3::is_writable($this->filename) && is_file($this->filename)) {
- $this->setRealFileSize();
- if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) {
- $this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
- return false;
- }
- if ($fp_source = fopen($this->filename, 'r+b')) {
- fseek($fp_source, -128, SEEK_END);
- if (fread($fp_source, 3) == 'TAG') {
- fseek($fp_source, -128, SEEK_END);
- } else {
- fseek($fp_source, 0, SEEK_END);
- }
- $this->tag_data['track_number'] = (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : '');
- $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
- (isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''),
- (isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''),
- (isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''),
- (isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''),
- (isset($this->tag_data['genreid'] ) ? $this->tag_data['genreid'] : ''),
- (isset($this->tag_data['comment'] ) ? $this->tag_data['comment'] : ''),
- (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : ''));
- fwrite($fp_source, $new_id3v1_tag_data, 128);
- fclose($fp_source);
- return true;
- } else {
- $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
- return false;
- }
- }
- $this->errors[] = 'File is not writeable: '.$this->filename;
- return false;
- }
-
- public function FixID3v1Padding() {
-
-
-
- $getID3 = new getID3;
- $getID3->option_tag_id3v2 = false;
- $getID3->option_tag_apetag = false;
- $getID3->option_tags_html = false;
- $getID3->option_extra_info = false;
- $getID3->option_tag_id3v1 = true;
- $ThisFileInfo = $getID3->analyze($this->filename);
- if (isset($ThisFileInfo['tags']['id3v1'])) {
- $id3v1data = array();
- foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
- $id3v1data[$key] = implode(',', $value);
- }
- $this->tag_data = $id3v1data;
- return $this->WriteID3v1();
- }
- return false;
- }
-
- public function RemoveID3v1() {
-
- if (!empty($this->filename) && is_readable($this->filename) && getID3::is_writable($this->filename) && is_file($this->filename)) {
- $this->setRealFileSize();
- if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) {
- $this->errors[] = 'Unable to RemoveID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
- return false;
- }
- if ($fp_source = fopen($this->filename, 'r+b')) {
- fseek($fp_source, -128, SEEK_END);
- if (fread($fp_source, 3) == 'TAG') {
- ftruncate($fp_source, $this->filesize - 128);
- } else {
-
- }
- fclose($fp_source);
- return true;
- } else {
- $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
- }
- } else {
- $this->errors[] = $this->filename.' is not writeable';
- }
- return false;
- }
-
- public function setRealFileSize() {
- if (PHP_INT_MAX > 2147483647) {
- $this->filesize = filesize($this->filename);
- return true;
- }
-
-
- $getID3 = new getID3;
- $getID3->option_tag_id3v1 = false;
- $getID3->option_tag_id3v2 = false;
- $getID3->option_tag_apetag = false;
- $getID3->option_tags_html = false;
- $getID3->option_extra_info = false;
- $ThisFileInfo = $getID3->analyze($this->filename);
- $this->filesize = $ThisFileInfo['filesize'];
- return true;
- }
- }
|