wp/wp-includes/ID3/module.tag.apetag.php
author ymh <ymh.work@gmail.com>
Tue, 27 Sep 2022 16:37:53 +0200
changeset 19 3d72ae0968f4
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
permissions -rw-r--r--
upgrade wordpress to 6.0.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     2
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
/////////////////////////////////////////////////////////////////
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
/// getID3() by James Heinrich <info@getid3.org>               //
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
//  available at https://github.com/JamesHeinrich/getID3       //
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     6
//            or https://www.getid3.org                        //
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     7
//            or http://getid3.sourceforge.net                 //
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     8
//  see readme.txt for more details                            //
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/////////////////////////////////////////////////////////////////
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
//                                                             //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
// module.tag.apetag.php                                       //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
// module for analyzing APE tags                               //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
// dependencies: NONE                                          //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
//                                                            ///
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
/////////////////////////////////////////////////////////////////
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    17
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    18
	exit;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    19
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    20
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class getid3_apetag extends getid3_handler
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
{
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    23
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    24
	 * true: return full data for all attachments;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    25
	 * false: return no data for all attachments;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    26
	 * integer: return data for attachments <= than this;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    27
	 * string: save as file to this directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    28
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    29
	 * @var int|bool|string
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    30
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    31
	public $inline_attachments = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    32
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	public $overrideendoffset  = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    35
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    36
	 * @return bool
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    37
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	public function Analyze() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		$info = &$this->getid3->info;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		if (!getid3_lib::intValueSupported($info['filesize'])) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    42
			$this->warning('Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		$id3v1tagsize     = 128;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		$apetagheadersize = 32;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$lyrics3tagsize   = 10;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		if ($this->overrideendoffset == 0) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
			$this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
			$APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
			//if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
			if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
				// APE tag found before ID3v1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
				$info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			//} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			} elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
				// APE tag found, no ID3v1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
				$info['ape']['tag_offset_end'] = $info['filesize'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
			$this->fseek($this->overrideendoffset - $apetagheadersize);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
			if ($this->fread(8) == 'APETAGEX') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
				$info['ape']['tag_offset_end'] = $this->overrideendoffset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		if (!isset($info['ape']['tag_offset_end'])) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
			// APE tag not found
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
			unset($info['ape']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		// shortcut
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
		$thisfile_ape = &$info['ape'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
		$this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
		$APEfooterData = $this->fread(32);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
			$this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
			$this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
			$thisfile_ape['tag_offset_start'] = $this->ftell();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
			$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
			$thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
			$this->fseek($thisfile_ape['tag_offset_start']);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
			$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		$info['avdataend'] = $thisfile_ape['tag_offset_start'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
			$this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			unset($info['id3v1']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
			foreach ($info['warning'] as $key => $value) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
				if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
					unset($info['warning'][$key]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
					sort($info['warning']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		$offset = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
				$offset += $apetagheadersize;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
			} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
				$this->error('Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		// shortcut
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		$info['replay_gain'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		$thisfile_replaygain = &$info['replay_gain'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			$value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			$offset += 4;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			$item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
			$offset += 4;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
			if (strstr(substr($APEtagData, $offset), "\x00") === false) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
				$this->error('Cannot find null-byte (0x00) separator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset));
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
			$ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
			$item_key      = strtolower(substr($APEtagData, $offset, $ItemKeyLength));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
			// shortcut
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			$thisfile_ape['items'][$item_key] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
			$thisfile_ape_items_current = &$thisfile_ape['items'][$item_key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
			$thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
			$offset += ($ItemKeyLength + 1); // skip 0x00 terminator
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			$thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
			$offset += $value_size;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			$thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			switch ($thisfile_ape_items_current['flags']['item_contents_raw']) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
				case 0: // UTF-8
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   157
				case 2: // Locator (URL, filename, etc), UTF-8 encoded
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   158
					$thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   161
				case 1:  // binary data
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
				default:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
			switch (strtolower($item_key)) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
				// http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
				case 'replaygain_track_gain':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   169
					if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   170
						$thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
						$thisfile_replaygain['track']['originator'] = 'unspecified';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   172
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   173
						$this->warning('MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   174
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
				case 'replaygain_track_peak':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   178
					if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   179
						$thisfile_replaygain['track']['peak']       = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
						$thisfile_replaygain['track']['originator'] = 'unspecified';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
						if ($thisfile_replaygain['track']['peak'] <= 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
							$this->warning('ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   185
						$this->warning('MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
				case 'replaygain_album_gain':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   190
					if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   191
						$thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
						$thisfile_replaygain['album']['originator'] = 'unspecified';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   194
						$this->warning('MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
				case 'replaygain_album_peak':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   199
					if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   200
						$thisfile_replaygain['album']['peak']       = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   201
						$thisfile_replaygain['album']['originator'] = 'unspecified';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   202
						if ($thisfile_replaygain['album']['peak'] <= 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
							$this->warning('ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
						$this->warning('MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
				case 'mp3gain_undo':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
					if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
						list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   213
						$thisfile_replaygain['mp3gain']['undo_left']  = intval($mp3gain_undo_left);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
						$thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
						$thisfile_replaygain['mp3gain']['undo_wrap']  = (($mp3gain_undo_wrap == 'Y') ? true : false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
						$this->warning('MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
				case 'mp3gain_minmax':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   222
					if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
						list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   224
						$thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
						$thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   227
						$this->warning('MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
				case 'mp3gain_album_minmax':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
					if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
						list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   234
						$thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   235
						$thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   236
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
						$this->warning('MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
				case 'tracknumber':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
					if (is_array($thisfile_ape_items_current['data'])) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
						foreach ($thisfile_ape_items_current['data'] as $comment) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   244
							$thisfile_ape['comments']['track_number'][] = $comment;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
				case 'cover art (artist)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
				case 'cover art (back)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
				case 'cover art (band logo)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
				case 'cover art (band)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
				case 'cover art (colored fish)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
				case 'cover art (composer)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
				case 'cover art (conductor)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
				case 'cover art (front)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
				case 'cover art (icon)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
				case 'cover art (illustration)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
				case 'cover art (lead)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
				case 'cover art (leaflet)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
				case 'cover art (lyricist)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
				case 'cover art (media)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
				case 'cover art (movie scene)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
				case 'cover art (other icon)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
				case 'cover art (other)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
				case 'cover art (performance)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				case 'cover art (publisher logo)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
				case 'cover art (recording)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
				case 'cover art (studio)':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
					// list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
					if (is_array($thisfile_ape_items_current['data'])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   272
						$this->warning('APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   273
						$thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   274
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
					list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
					$thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
					$thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   279
					do {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   280
						$thisfile_ape_items_current['image_mime'] = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   281
						$imageinfo = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
						$imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   283
						if (($imagechunkcheck === false) || !isset($imagechunkcheck[2])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   284
							$this->warning('APEtag "'.$item_key.'" contains invalid image data');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   285
							break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   286
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   287
						$thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
						if ($this->inline_attachments === false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
							// skip entirely
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
							unset($thisfile_ape_items_current['data']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
							break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
						if ($this->inline_attachments === true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
							// great
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
						} elseif (is_int($this->inline_attachments)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
							if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
								// too big, skip
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   299
								$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
								unset($thisfile_ape_items_current['data']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
								break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
						} elseif (is_string($this->inline_attachments)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
							$this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   305
							if (!is_dir($this->inline_attachments) || !getID3::is_writable($this->inline_attachments)) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
								// cannot write, skip
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
								$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
								unset($thisfile_ape_items_current['data']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
								break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
						// if we get this far, must be OK
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
						if (is_string($this->inline_attachments)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
							$destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
							if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
								file_put_contents($destination_filename, $thisfile_ape_items_current['data']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
							} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   318
								$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
							$thisfile_ape_items_current['data_filename'] = $destination_filename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
							unset($thisfile_ape_items_current['data']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
						} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
							if (!isset($info['ape']['comments']['picture'])) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
								$info['ape']['comments']['picture'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
							}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
							$comments_picture_data = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
							foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
								if (isset($thisfile_ape_items_current[$picture_key])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
									$comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   331
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
							$info['ape']['comments']['picture'][] = $comments_picture_data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
							unset($comments_picture_data);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
					} while (false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
				default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
					if (is_array($thisfile_ape_items_current['data'])) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
						foreach ($thisfile_ape_items_current['data'] as $comment) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
							$thisfile_ape['comments'][strtolower($item_key)][] = $comment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		if (empty($thisfile_replaygain)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
			unset($info['replay_gain']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   354
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   355
	 * @param string $APEheaderFooterData
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   356
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   357
	 * @return array|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   358
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
	public function parseAPEheaderFooter($APEheaderFooterData) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		// http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		// shortcut
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   363
		$headerfooterinfo = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		$headerfooterinfo['raw'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
		$headerfooterinfo_raw = &$headerfooterinfo['raw'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
		$headerfooterinfo_raw['footer_tag']   =                  substr($APEheaderFooterData,  0, 8);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
		if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
		$headerfooterinfo_raw['version']      = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData,  8, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		$headerfooterinfo_raw['tagsize']      = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
		$headerfooterinfo_raw['tag_items']    = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		$headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
		$headerfooterinfo_raw['reserved']     =                              substr($APEheaderFooterData, 24, 8);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		$headerfooterinfo['tag_version']         = $headerfooterinfo_raw['version'] / 1000;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		if ($headerfooterinfo['tag_version'] >= 2) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			$headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
		return $headerfooterinfo;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   384
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   385
	 * @param int $rawflagint
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   386
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   387
	 * @return array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   388
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	public function parseAPEtagFlags($rawflagint) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		// "Note: APE Tags 1.0 do not use any of the APE Tag flags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
		// All are set to zero on creation and ignored on reading."
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
		// http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   393
		$flags                      = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
		$flags['header']            = (bool) ($rawflagint & 0x80000000);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
		$flags['footer']            = (bool) ($rawflagint & 0x40000000);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
		$flags['this_is_header']    = (bool) ($rawflagint & 0x20000000);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
		$flags['item_contents_raw'] =        ($rawflagint & 0x00000006) >> 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
		$flags['read_only']         = (bool) ($rawflagint & 0x00000001);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		$flags['item_contents']     = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
		return $flags;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   405
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   406
	 * @param int $contenttypeid
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   407
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   408
	 * @return string
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   409
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	public function APEcontentTypeFlagLookup($contenttypeid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
		static $APEcontentTypeFlagLookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			0 => 'utf-8',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			1 => 'binary',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			2 => 'external',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
			3 => 'reserved'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   420
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   421
	 * @param string $itemkey
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   422
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   423
	 * @return bool
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   424
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	public function APEtagItemIsUTF8Lookup($itemkey) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
		static $APEtagItemIsUTF8Lookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
			'title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
			'subtitle',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
			'artist',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
			'album',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
			'debut album',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			'publisher',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
			'conductor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
			'track',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
			'composer',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
			'comment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
			'copyright',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
			'publicationright',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
			'file',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			'year',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
			'record date',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
			'record location',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
			'genre',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
			'media',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
			'related',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
			'isrc',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
			'abstract',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
			'language',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
			'bibliography'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
		return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   454
}