Exemplo n.º 1
0
 function DeleteTags($TagFormatsToDelete)
 {
     foreach ($TagFormatsToDelete as $DeleteTagFormat) {
         $success = false;
         // overridden if tag deletion is successful
         switch ($DeleteTagFormat) {
             case 'id3v1':
                 $id3v1_writer = new getid3_write_id3v1();
                 $id3v1_writer->filename = $this->filename;
                 if (($success = $id3v1_writer->RemoveID3v1()) === false) {
                     $this->errors[] = 'RemoveID3v1() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $id3v1_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             case 'id3v2':
                 $id3v2_writer = new getid3_write_id3v2();
                 $id3v2_writer->filename = $this->filename;
                 if (($success = $id3v2_writer->RemoveID3v2()) === false) {
                     $this->errors[] = 'RemoveID3v2() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $id3v2_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             case 'ape':
                 $ape_writer = new getid3_write_apetag();
                 $ape_writer->filename = $this->filename;
                 if (($success = $ape_writer->DeleteAPEtag()) === false) {
                     $this->errors[] = 'DeleteAPEtag() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $ape_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             case 'vorbiscomment':
                 $vorbiscomment_writer = new getid3_write_vorbiscomment();
                 $vorbiscomment_writer->filename = $this->filename;
                 if (($success = $vorbiscomment_writer->DeleteVorbisComment()) === false) {
                     $this->errors[] = 'DeleteVorbisComment() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $vorbiscomment_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             case 'metaflac':
                 $metaflac_writer = new getid3_write_metaflac();
                 $metaflac_writer->filename = $this->filename;
                 if (($success = $metaflac_writer->DeleteMetaFLAC()) === false) {
                     $this->errors[] = 'DeleteMetaFLAC() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $metaflac_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             case 'lyrics3':
                 $lyrics3_writer = new getid3_write_lyrics3();
                 $lyrics3_writer->filename = $this->filename;
                 if (($success = $lyrics3_writer->DeleteLyrics3()) === false) {
                     $this->errors[] = 'DeleteLyrics3() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $lyrics3_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             case 'real':
                 $real_writer = new getid3_write_real();
                 $real_writer->filename = $this->filename;
                 if (($success = $real_writer->RemoveReal()) === false) {
                     $this->errors[] = 'RemoveReal() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $real_writer->errors)) . '</LI></UL></PRE>';
                 }
                 break;
             default:
                 $this->errors[] = 'Invalid tag format to delete: "' . $tagformat . '"';
                 return false;
                 break;
         }
         if (!$success) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 2
0
 function WriteTags()
 {
     if (empty($this->filename)) {
         $this->errors[] = 'filename is undefined in getid3_writetags';
         return false;
     } elseif (!file_exists($this->filename)) {
         $this->errors[] = 'filename set to non-existant file "' . $this->filename . '" in getid3_writetags';
         return false;
     }
     if (!is_array($this->tagformats)) {
         $this->errors[] = 'tagformats must be an array in getid3_writetags';
         return false;
     }
     if (filesize($this->filename) == 0) {
         // empty file special case - allow any tag format, don't check existing format
         // could be useful if you want to generate tag data for a non-existant file
         $this->ThisFileInfo = array('fileformat' => '');
         $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3');
     } else {
         $getID3 = new getID3();
         $getID3->encoding = $this->tag_encoding;
         $this->ThisFileInfo = $getID3->analyze($this->filename);
         // check for what file types are allowed on this fileformat
         switch (@$this->ThisFileInfo['fileformat']) {
             case 'mp3':
             case 'mp2':
             case 'mp1':
                 $AllowedTagFormats = array('id3v1', 'id3v2.2', 'id3v2.3', 'id3v2.4', 'ape', 'lyrics3');
                 break;
             case 'mpc':
                 $AllowedTagFormats = array('ape');
                 break;
             case 'flac':
                 $AllowedTagFormats = array('metaflac');
                 break;
             case 'real':
                 $AllowedTagFormats = array('real');
                 break;
             case 'ogg':
                 switch (@$this->ThisFileInfo['audio']['dataformat']) {
                     case 'flac':
                         //$AllowedTagFormats = array('metaflac');
                         $this->errors[] = 'metaflac is not (yet) compatible with OggFLAC files';
                         return false;
                         break;
                     case 'vorbis':
                         $AllowedTagFormats = array('vorbiscomment');
                         break;
                     default:
                         $this->errors[] = 'metaflac is not (yet) compatible with Ogg files other than OggVorbis';
                         return false;
                         break;
                 }
                 break;
             default:
                 $AllowedTagFormats = array();
                 break;
         }
         foreach ($this->tagformats as $requested_tag_format) {
             if (!in_array($requested_tag_format, $AllowedTagFormats)) {
                 $errormessage = 'Tag format "' . $requested_tag_format . '" is not allowed on "' . @$this->ThisFileInfo['fileformat'];
                 if (@$this->ThisFileInfo['fileformat'] != @$this->ThisFileInfo['audio']['dataformat']) {
                     $errormessage .= '.' . @$this->ThisFileInfo['audio']['dataformat'];
                 }
                 $errormessage .= '" files';
                 $this->errors[] = $errormessage;
                 return false;
             }
         }
         // List of other tag formats, removed if requested
         $TagFormatsToRemove = array();
         if ($this->remove_other_tags) {
             foreach ($AllowedTagFormats as $AllowedTagFormat) {
                 switch ($AllowedTagFormat) {
                     case 'id3v2.2':
                     case 'id3v2.3':
                     case 'id3v2.4':
                         if (!in_array('id3v2', $TagFormatsToRemove) && !in_array('id3v2.2', $this->tagformats) && !in_array('id3v2.3', $this->tagformats) && !in_array('id3v2.4', $this->tagformats)) {
                             $TagFormatsToRemove[] = 'id3v2';
                         }
                         break;
                     default:
                         if (!in_array($AllowedTagFormat, $this->tagformats)) {
                             $TagFormatsToRemove[] = $AllowedTagFormat;
                         }
                         break;
                 }
             }
         }
     }
     $WritingFilesToInclude = array_merge($this->tagformats, $TagFormatsToRemove);
     // Check for required include files and include them
     foreach ($WritingFilesToInclude as $tagformat) {
         switch ($tagformat) {
             case 'ape':
                 $GETID3_ERRORARRAY =& $this->errors;
                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.apetag.php', __FILE__, false)) {
                     return false;
                 }
                 break;
             case 'id3v1':
             case 'lyrics3':
             case 'vorbiscomment':
             case 'metaflac':
             case 'real':
                 $GETID3_ERRORARRAY =& $this->errors;
                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.' . $tagformat . '.php', __FILE__, false)) {
                     return false;
                 }
                 break;
             case 'id3v2.2':
             case 'id3v2.3':
             case 'id3v2.4':
             case 'id3v2':
                 $GETID3_ERRORARRAY =& $this->errors;
                 if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.id3v2.php', __FILE__, false)) {
                     return false;
                 }
                 break;
             default:
                 $this->errors[] = 'unknown tag format "' . $tagformat . '" in $tagformats in WriteTags()';
                 return false;
                 break;
         }
     }
     // Validation of supplied data
     if (!is_array($this->tag_data)) {
         $this->errors[] = '$tag_data is not an array in WriteTags()';
         return false;
     }
     // convert supplied data array keys to upper case, if they're not already
     foreach ($this->tag_data as $tag_key => $tag_array) {
         if (strtoupper($tag_key) !== $tag_key) {
             $this->tag_data[strtoupper($tag_key)] = $this->tag_data[$tag_key];
             unset($this->tag_data[$tag_key]);
         }
     }
     // convert source data array keys to upper case, if they're not already
     if (!empty($this->ThisFileInfo['tags'])) {
         foreach ($this->ThisFileInfo['tags'] as $tag_format => $tag_data_array) {
             foreach ($tag_data_array as $tag_key => $tag_array) {
                 if (strtoupper($tag_key) !== $tag_key) {
                     $this->ThisFileInfo['tags'][$tag_format][strtoupper($tag_key)] = $this->ThisFileInfo['tags'][$tag_format][$tag_key];
                     unset($this->ThisFileInfo['tags'][$tag_format][$tag_key]);
                 }
             }
         }
     }
     // Convert "TRACK" to "TRACKNUMBER" (if needed) for compatability with all formats
     if (isset($this->tag_data['TRACK']) && !isset($this->tag_data['TRACKNUMBER'])) {
         $this->tag_data['TRACKNUMBER'] = $this->tag_data['TRACK'];
         unset($this->tag_data['TRACK']);
     }
     // Remove all other tag formats, if requested
     if ($this->remove_other_tags) {
         $this->DeleteTags($TagFormatsToRemove);
     }
     // Write data for each tag format
     foreach ($this->tagformats as $tagformat) {
         $success = false;
         // overridden if tag writing is successful
         switch ($tagformat) {
             case 'ape':
                 $ape_writer = new getid3_write_apetag();
                 if (($ape_writer->tag_data = $this->FormatDataForAPE()) !== false) {
                     $ape_writer->filename = $this->filename;
                     if (($success = $ape_writer->WriteAPEtag()) === false) {
                         $this->errors[] = 'WriteAPEtag() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $ape_writer->errors)) . '</LI></UL></PRE>';
                     }
                 } else {
                     $this->errors[] = 'FormatDataForAPE() failed';
                 }
                 break;
             case 'id3v1':
                 $id3v1_writer = new getid3_write_id3v1();
                 if (($id3v1_writer->tag_data = $this->FormatDataForID3v1()) !== false) {
                     $id3v1_writer->filename = $this->filename;
                     if (($success = $id3v1_writer->WriteID3v1()) === false) {
                         $this->errors[] = 'WriteID3v1() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $id3v1_writer->errors)) . '</LI></UL></PRE>';
                     }
                 } else {
                     $this->errors[] = 'FormatDataForID3v1() failed';
                 }
                 break;
             case 'id3v2.2':
             case 'id3v2.3':
             case 'id3v2.4':
                 $id3v2_writer = new getid3_write_id3v2();
                 $id3v2_writer->majorversion = intval(substr($tagformat, -1));
                 $id3v2_writer->paddedlength = $this->id3v2_paddedlength;
                 if (($id3v2_writer->tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion)) !== false) {
                     $id3v2_writer->filename = $this->filename;
                     if (($success = $id3v2_writer->WriteID3v2()) === false) {
                         $this->errors[] = 'WriteID3v2() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $id3v2_writer->errors)) . '</LI></UL></PRE>';
                     }
                 } else {
                     $this->errors[] = 'FormatDataForID3v2() failed';
                 }
                 break;
             case 'vorbiscomment':
                 $vorbiscomment_writer = new getid3_write_vorbiscomment();
                 if (($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) !== false) {
                     $vorbiscomment_writer->filename = $this->filename;
                     if (($success = $vorbiscomment_writer->WriteVorbisComment()) === false) {
                         $this->errors[] = 'WriteVorbisComment() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $vorbiscomment_writer->errors)) . '</LI></UL></PRE>';
                     }
                 } else {
                     $this->errors[] = 'WriteVorbisComment() failed';
                 }
                 break;
             case 'metaflac':
                 $metaflac_writer = new getid3_write_metaflac();
                 if (($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) !== false) {
                     $metaflac_writer->filename = $this->filename;
                     if (($success = $metaflac_writer->WriteMetaFLAC()) === false) {
                         $this->errors[] = 'WriteMetaFLAC() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $metaflac_writer->errors)) . '</LI></UL></PRE>';
                     }
                 } else {
                     $this->errors[] = 'FormatDataForMetaFLAC() failed';
                 }
                 break;
             case 'real':
                 $real_writer = new getid3_write_real();
                 if (($real_writer->tag_data = $this->FormatDataForReal()) !== false) {
                     $real_writer->filename = $this->filename;
                     if (($success = $real_writer->WriteReal()) === false) {
                         $this->errors[] = 'WriteReal() failed with message(s):<PRE><UL><LI>' . trim(implode('</LI><LI>', $real_writer->errors)) . '</LI></UL></PRE>';
                     }
                 } else {
                     $this->errors[] = 'FormatDataForReal() failed';
                 }
                 break;
             default:
                 $this->errors[] = 'Invalid tag format to write: "' . $tagformat . '"';
                 return false;
                 break;
         }
         if (!$success) {
             return false;
         }
     }
     return true;
 }