ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
write.id3v1.php
Go to the documentation of this file.
1 <?php
4 // available at http://getid3.sourceforge.net //
5 // or http://www.getid3.org //
7 // See readme.txt for more details //
9 // //
10 // write.id3v1.php //
11 // module for writing ID3v1 tags //
12 // dependencies: module.tag.id3v1.php //
13 // ///
15 
16 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
17 
19 {
20  var $filename;
21  var $tag_data;
22  var $warnings = array(); // any non-critical errors will be stored here
23  var $errors = array(); // any critical errors will be stored here
24 
25  function getid3_write_id3v1() {
26  return true;
27  }
28 
29  function WriteID3v1() {
30  // File MUST be writeable - CHMOD(646) at least
31  if (is_writeable($this->filename)) {
32  if ($fp_source = @fopen($this->filename, 'r+b')) {
33 
34  fseek($fp_source, -128, SEEK_END);
35  if (fread($fp_source, 3) == 'TAG') {
36  fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag
37  } else {
38  fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag
39  }
40 
41  $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
42  @$this->tag_data['title'],
43  @$this->tag_data['artist'],
44  @$this->tag_data['album'],
45  @$this->tag_data['year'],
46  @$this->tag_data['genreid'],
47  @$this->tag_data['comment'],
48  @$this->tag_data['track']);
49  fwrite($fp_source, $new_id3v1_tag_data, 128);
50  fclose($fp_source);
51  return true;
52 
53  } else {
54  $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
55  return false;
56  }
57  }
58  $this->errors[] = 'File is not writeable: '.$this->filename;
59  return false;
60  }
61 
62  function FixID3v1Padding() {
63  // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces
64  // This function rewrites the ID3v1 tag with correct padding
65 
66  // Initialize getID3 engine
67  $getID3 = new getID3;
68  $ThisFileInfo = $getID3->analyze($this->filename);
69  if (isset($ThisFileInfo['tags']['id3v1'])) {
70  foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) {
71  $id3v1data[$key] = implode(',', $value);
72  }
73  $this->tag_data = $id3v1data;
74  return $this->WriteID3v1();
75  }
76  return false;
77  }
78 
79  function RemoveID3v1() {
80  // File MUST be writeable - CHMOD(646) at least
81  if (is_writeable($this->filename)) {
82  if ($fp_source = @fopen($this->filename, 'r+b')) {
83 
84  fseek($fp_source, -128, SEEK_END);
85  if (fread($fp_source, 3) == 'TAG') {
86  ftruncate($fp_source, filesize($this->filename) - 128);
87  } else {
88  // no ID3v1 tag to begin with - do nothing
89  }
90  fclose($fp_source);
91  return true;
92 
93  } else {
94  $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"';
95  }
96  } else {
97  $this->errors[] = $this->filename.' is not writeable';
98  }
99  return false;
100  }
101 
102 }
103 
104 ?>