summaryrefslogtreecommitdiffstats
path: root/modules/id3/getid3/write.id3v1.php
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-06-09 16:34:40 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-06-09 16:34:40 +0000
commitbcad40a05ab2dc2a341a3227e30b96668bce4500 (patch)
tree6fca27588d53a1b24705bd2834e9e643bb729bd1 /modules/id3/getid3/write.id3v1.php
downloadampache-bcad40a05ab2dc2a341a3227e30b96668bce4500.tar.gz
ampache-bcad40a05ab2dc2a341a3227e30b96668bce4500.tar.bz2
ampache-bcad40a05ab2dc2a341a3227e30b96668bce4500.zip
New Import
Diffstat (limited to 'modules/id3/getid3/write.id3v1.php')
-rw-r--r--modules/id3/getid3/write.id3v1.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/modules/id3/getid3/write.id3v1.php b/modules/id3/getid3/write.id3v1.php
new file mode 100644
index 00000000..21252148
--- /dev/null
+++ b/modules/id3/getid3/write.id3v1.php
@@ -0,0 +1,104 @@
+<?php
+/////////////////////////////////////////////////////////////////
+/// getID3() by James Heinrich <info@getid3.org> //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// write.id3v1.php //
+// module for writing ID3v1 tags //
+// dependencies: module.tag.id3v1.php //
+// ///
+/////////////////////////////////////////////////////////////////
+
+getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
+
+class getid3_write_id3v1
+{
+ var $filename;
+ var $tag_data;
+ var $warnings = array(); // any non-critical errors will be stored here
+ var $errors = array(); // any critical errors will be stored here
+
+ function getid3_write_id3v1() {
+ return true;
+ }
+
+ function WriteID3v1() {
+ // File MUST be writeable - CHMOD(646) at least
+ if (is_writeable($this->filename)) {
+ 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); // overwrite existing ID3v1 tag
+ } else {
+ fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag
+ }
+
+ $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
+ @$this->tag_data['title'],
+ @$this->tag_data['artist'],
+ @$this->tag_data['album'],
+ @$this->tag_data['year'],
+ @$this->tag_data['genreid'],
+ @$this->tag_data['comment'],
+ @$this->tag_data['track']);
+ fwrite($fp_source, $new_id3v1_tag_data, 128);
+ fclose($fp_source);
+ return true;
+
+ } else {
+ $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
+ return false;
+ }
+ }
+ $this->errors[] = 'File is not writeable: '.$this->filename;
+ return false;
+ }
+
+ function FixID3v1Padding() {
+ // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces
+ // This function rewrites the ID3v1 tag with correct padding
+
+ // Initialize getID3 engine
+ $getID3 = new getID3;
+ $ThisFileInfo = $getID3->analyze($this->filename);
+ if (isset($ThisFileInfo['tags']['id3v1'])) {
+ foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
+ $id3v1data[$key] = implode(',', $value);
+ }
+ $this->tag_data = $id3v1data;
+ return $this->WriteID3v1();
+ }
+ return false;
+ }
+
+ function RemoveID3v1() {
+ // File MUST be writeable - CHMOD(646) at least
+ if (is_writeable($this->filename)) {
+ if ($fp_source = @fopen($this->filename, 'r+b')) {
+
+ fseek($fp_source, -128, SEEK_END);
+ if (fread($fp_source, 3) == 'TAG') {
+ ftruncate($fp_source, filesize($this->filename) - 128);
+ } else {
+ // no ID3v1 tag to begin with - do nothing
+ }
+ fclose($fp_source);
+ return true;
+
+ } else {
+ $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
+ }
+ } else {
+ $this->errors[] = $this->filename.' is not writeable';
+ }
+ return false;
+ }
+
+}
+
+?> \ No newline at end of file