Mercurial > judyates
diff e2gallerypro/e2upload/Backend/Assets/getid3/module.tag.id3v1.php @ 3:3f6b44aa6b35 judyates
[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author | rlm |
---|---|
date | Mon, 22 Feb 2010 08:02:39 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.tag.id3v1.php Mon Feb 22 08:02:39 2010 -0500 1.3 @@ -0,0 +1,324 @@ 1.4 +<?php 1.5 +// +----------------------------------------------------------------------+ 1.6 +// | PHP version 5 | 1.7 +// +----------------------------------------------------------------------+ 1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen | 1.9 +// +----------------------------------------------------------------------+ 1.10 +// | This source file is subject to version 2 of the GPL license, | 1.11 +// | that is bundled with this package in the file license.txt and is | 1.12 +// | available through the world-wide-web at the following url: | 1.13 +// | http://www.gnu.org/copyleft/gpl.html | 1.14 +// +----------------------------------------------------------------------+ 1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org | 1.16 +// +----------------------------------------------------------------------+ 1.17 +// | Authors: James Heinrich <infoØgetid3*org> | 1.18 +// | Allan Hansen <ahØartemis*dk> | 1.19 +// +----------------------------------------------------------------------+ 1.20 +// | module.tag.id3v1.php | 1.21 +// | module for analyzing ID3v1 tags | 1.22 +// | dependencies: NONE | 1.23 +// +----------------------------------------------------------------------+ 1.24 +// 1.25 +// $Id: module.tag.id3v1.php,v 1.6 2006/11/16 16:19:52 ah Exp $ 1.26 + 1.27 + 1.28 + 1.29 +class getid3_id3v1 extends getid3_handler 1.30 +{ 1.31 + 1.32 + public function Analyze() { 1.33 + 1.34 + $getid3 = $this->getid3; 1.35 + 1.36 + fseek($getid3->fp, -256, SEEK_END); 1.37 + $pre_id3v1 = fread($getid3->fp, 128); 1.38 + $id3v1_tag = fread($getid3->fp, 128); 1.39 + 1.40 + if (substr($id3v1_tag, 0, 3) == 'TAG') { 1.41 + 1.42 + $getid3->info['avdataend'] -= 128; 1.43 + 1.44 + // Shortcut 1.45 + $getid3->info['id3v1'] = array (); 1.46 + $info_id3v1 = &$getid3->info['id3v1']; 1.47 + 1.48 + $info_id3v1['title'] = getid3_id3v1::cutfield(substr($id3v1_tag, 3, 30)); 1.49 + $info_id3v1['artist'] = getid3_id3v1::cutfield(substr($id3v1_tag, 33, 30)); 1.50 + $info_id3v1['album'] = getid3_id3v1::cutfield(substr($id3v1_tag, 63, 30)); 1.51 + $info_id3v1['year'] = getid3_id3v1::cutfield(substr($id3v1_tag, 93, 4)); 1.52 + $info_id3v1['comment'] = substr($id3v1_tag, 97, 30); // can't remove nulls yet, track detection depends on them 1.53 + $info_id3v1['genreid'] = ord(substr($id3v1_tag, 127, 1)); 1.54 + 1.55 + // If second-last byte of comment field is null and last byte of comment field is non-null then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number 1.56 + if (($id3v1_tag{125} === "\x00") && ($id3v1_tag{126} !== "\x00")) { 1.57 + $info_id3v1['track'] = ord(substr($info_id3v1['comment'], 29, 1)); 1.58 + $info_id3v1['comment'] = substr($info_id3v1['comment'], 0, 28); 1.59 + } 1.60 + $info_id3v1['comment'] = getid3_id3v1::cutfield($info_id3v1['comment']); 1.61 + 1.62 + $info_id3v1['genre'] = getid3_id3v1::LookupGenreName($info_id3v1['genreid']); 1.63 + if (!empty($info_id3v1['genre'])) { 1.64 + unset($info_id3v1['genreid']); 1.65 + } 1.66 + if (empty($info_id3v1['genre']) || (@$info_id3v1['genre'] == 'Unknown')) { 1.67 + unset($info_id3v1['genre']); 1.68 + } 1.69 + 1.70 + foreach ($info_id3v1 as $key => $value) { 1.71 + $key != 'comments' and $info_id3v1['comments'][$key][0] = $value; 1.72 + } 1.73 + 1.74 + $info_id3v1['tag_offset_end'] = filesize($getid3->filename); 1.75 + $info_id3v1['tag_offset_start'] = $info_id3v1['tag_offset_end'] - 128; 1.76 + } 1.77 + 1.78 + if (substr($pre_id3v1, 0, 3) == 'TAG') { 1.79 + // The way iTunes handles tags is, well, brain-damaged. 1.80 + // It completely ignores v1 if ID3v2 is present. 1.81 + // This goes as far as adding a new v1 tag *even if there already is one* 1.82 + 1.83 + // A suspected double-ID3v1 tag has been detected, but it could be that the "TAG" identifier is a legitimate part of an APE or Lyrics3 tag 1.84 + if (substr($pre_id3v1, 96, 8) == 'APETAGEX') { 1.85 + // an APE tag footer was found before the last ID3v1, assume false "TAG" synch 1.86 + } elseif (substr($pre_id3v1, 119, 6) == 'LYRICS') { 1.87 + // a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch 1.88 + } else { 1.89 + // APE and Lyrics3 footers not found - assume double ID3v1 1.90 + $getid3->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes.'); 1.91 + $getid3->info['avdataend'] -= 128; 1.92 + } 1.93 + } 1.94 + 1.95 + return true; 1.96 + } 1.97 + 1.98 + 1.99 + 1.100 + public static function cutfield($str) { 1.101 + 1.102 + return trim(substr($str, 0, strcspn($str, "\x00"))); 1.103 + } 1.104 + 1.105 + 1.106 + 1.107 + public static function ArrayOfGenres($allow_SCMPX_extended=false) { 1.108 + 1.109 + static $lookup = array ( 1.110 + 0 => 'Blues', 1.111 + 1 => 'Classic Rock', 1.112 + 2 => 'Country', 1.113 + 3 => 'Dance', 1.114 + 4 => 'Disco', 1.115 + 5 => 'Funk', 1.116 + 6 => 'Grunge', 1.117 + 7 => 'Hip-Hop', 1.118 + 8 => 'Jazz', 1.119 + 9 => 'Metal', 1.120 + 10 => 'New Age', 1.121 + 11 => 'Oldies', 1.122 + 12 => 'Other', 1.123 + 13 => 'Pop', 1.124 + 14 => 'R&B', 1.125 + 15 => 'Rap', 1.126 + 16 => 'Reggae', 1.127 + 17 => 'Rock', 1.128 + 18 => 'Techno', 1.129 + 19 => 'Industrial', 1.130 + 20 => 'Alternative', 1.131 + 21 => 'Ska', 1.132 + 22 => 'Death Metal', 1.133 + 23 => 'Pranks', 1.134 + 24 => 'Soundtrack', 1.135 + 25 => 'Euro-Techno', 1.136 + 26 => 'Ambient', 1.137 + 27 => 'Trip-Hop', 1.138 + 28 => 'Vocal', 1.139 + 29 => 'Jazz+Funk', 1.140 + 30 => 'Fusion', 1.141 + 31 => 'Trance', 1.142 + 32 => 'Classical', 1.143 + 33 => 'Instrumental', 1.144 + 34 => 'Acid', 1.145 + 35 => 'House', 1.146 + 36 => 'Game', 1.147 + 37 => 'Sound Clip', 1.148 + 38 => 'Gospel', 1.149 + 39 => 'Noise', 1.150 + 40 => 'Alt. Rock', 1.151 + 41 => 'Bass', 1.152 + 42 => 'Soul', 1.153 + 43 => 'Punk', 1.154 + 44 => 'Space', 1.155 + 45 => 'Meditative', 1.156 + 46 => 'Instrumental Pop', 1.157 + 47 => 'Instrumental Rock', 1.158 + 48 => 'Ethnic', 1.159 + 49 => 'Gothic', 1.160 + 50 => 'Darkwave', 1.161 + 51 => 'Techno-Industrial', 1.162 + 52 => 'Electronic', 1.163 + 53 => 'Pop-Folk', 1.164 + 54 => 'Eurodance', 1.165 + 55 => 'Dream', 1.166 + 56 => 'Southern Rock', 1.167 + 57 => 'Comedy', 1.168 + 58 => 'Cult', 1.169 + 59 => 'Gangsta Rap', 1.170 + 60 => 'Top 40', 1.171 + 61 => 'Christian Rap', 1.172 + 62 => 'Pop/Funk', 1.173 + 63 => 'Jungle', 1.174 + 64 => 'Native American', 1.175 + 65 => 'Cabaret', 1.176 + 66 => 'New Wave', 1.177 + 67 => 'Psychedelic', 1.178 + 68 => 'Rave', 1.179 + 69 => 'Showtunes', 1.180 + 70 => 'Trailer', 1.181 + 71 => 'Lo-Fi', 1.182 + 72 => 'Tribal', 1.183 + 73 => 'Acid Punk', 1.184 + 74 => 'Acid Jazz', 1.185 + 75 => 'Polka', 1.186 + 76 => 'Retro', 1.187 + 77 => 'Musical', 1.188 + 78 => 'Rock & Roll', 1.189 + 79 => 'Hard Rock', 1.190 + 80 => 'Folk', 1.191 + 81 => 'Folk/Rock', 1.192 + 82 => 'National Folk', 1.193 + 83 => 'Swing', 1.194 + 84 => 'Fast-Fusion', 1.195 + 85 => 'Bebob', 1.196 + 86 => 'Latin', 1.197 + 87 => 'Revival', 1.198 + 88 => 'Celtic', 1.199 + 89 => 'Bluegrass', 1.200 + 90 => 'Avantgarde', 1.201 + 91 => 'Gothic Rock', 1.202 + 92 => 'Progressive Rock', 1.203 + 93 => 'Psychedelic Rock', 1.204 + 94 => 'Symphonic Rock', 1.205 + 95 => 'Slow Rock', 1.206 + 96 => 'Big Band', 1.207 + 97 => 'Chorus', 1.208 + 98 => 'Easy Listening', 1.209 + 99 => 'Acoustic', 1.210 + 100 => 'Humour', 1.211 + 101 => 'Speech', 1.212 + 102 => 'Chanson', 1.213 + 103 => 'Opera', 1.214 + 104 => 'Chamber Music', 1.215 + 105 => 'Sonata', 1.216 + 106 => 'Symphony', 1.217 + 107 => 'Booty Bass', 1.218 + 108 => 'Primus', 1.219 + 109 => 'Porn Groove', 1.220 + 110 => 'Satire', 1.221 + 111 => 'Slow Jam', 1.222 + 112 => 'Club', 1.223 + 113 => 'Tango', 1.224 + 114 => 'Samba', 1.225 + 115 => 'Folklore', 1.226 + 116 => 'Ballad', 1.227 + 117 => 'Power Ballad', 1.228 + 118 => 'Rhythmic Soul', 1.229 + 119 => 'Freestyle', 1.230 + 120 => 'Duet', 1.231 + 121 => 'Punk Rock', 1.232 + 122 => 'Drum Solo', 1.233 + 123 => 'A Cappella', 1.234 + 124 => 'Euro-House', 1.235 + 125 => 'Dance Hall', 1.236 + 126 => 'Goa', 1.237 + 127 => 'Drum & Bass', 1.238 + 128 => 'Club-House', 1.239 + 129 => 'Hardcore', 1.240 + 130 => 'Terror', 1.241 + 131 => 'Indie', 1.242 + 132 => 'BritPop', 1.243 + 133 => 'Negerpunk', 1.244 + 134 => 'Polsk Punk', 1.245 + 135 => 'Beat', 1.246 + 136 => 'Christian Gangsta Rap', 1.247 + 137 => 'Heavy Metal', 1.248 + 138 => 'Black Metal', 1.249 + 139 => 'Crossover', 1.250 + 140 => 'Contemporary Christian', 1.251 + 141 => 'Christian Rock', 1.252 + 142 => 'Merengue', 1.253 + 143 => 'Salsa', 1.254 + 144 => 'Trash Metal', 1.255 + 145 => 'Anime', 1.256 + 146 => 'JPop', 1.257 + 147 => 'Synthpop', 1.258 + 1.259 + 255 => 'Unknown', 1.260 + 1.261 + 'CR' => 'Cover', 1.262 + 'RX' => 'Remix' 1.263 + ); 1.264 + 1.265 + static $lookupSCMPX = array (); 1.266 + if ($allow_SCMPX_extended && empty($lookupSCMPX)) { 1.267 + $lookupSCMPX = $lookup; 1.268 + // http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended 1.269 + // Extended ID3v1 genres invented by SCMPX 1.270 + // Note that 255 "Japanese Anime" conflicts with standard "Unknown" 1.271 + $lookupSCMPX[240] = 'Sacred'; 1.272 + $lookupSCMPX[241] = 'Northern Europe'; 1.273 + $lookupSCMPX[242] = 'Irish & Scottish'; 1.274 + $lookupSCMPX[243] = 'Scotland'; 1.275 + $lookupSCMPX[244] = 'Ethnic Europe'; 1.276 + $lookupSCMPX[245] = 'Enka'; 1.277 + $lookupSCMPX[246] = 'Children\'s Song'; 1.278 + $lookupSCMPX[247] = 'Japanese Sky'; 1.279 + $lookupSCMPX[248] = 'Japanese Heavy Rock'; 1.280 + $lookupSCMPX[249] = 'Japanese Doom Rock'; 1.281 + $lookupSCMPX[250] = 'Japanese J-POP'; 1.282 + $lookupSCMPX[251] = 'Japanese Seiyu'; 1.283 + $lookupSCMPX[252] = 'Japanese Ambient Techno'; 1.284 + $lookupSCMPX[253] = 'Japanese Moemoe'; 1.285 + $lookupSCMPX[254] = 'Japanese Tokusatsu'; 1.286 + //$lookupSCMPX[255] = 'Japanese Anime'; 1.287 + } 1.288 + 1.289 + return ($allow_SCMPX_extended ? $lookupSCMPX : $lookup); 1.290 + } 1.291 + 1.292 + 1.293 + 1.294 + public static function LookupGenreName($genre_id, $allow_SCMPX_extended=true) { 1.295 + 1.296 + switch ($genre_id) { 1.297 + case 'RX': 1.298 + case 'CR': 1.299 + break; 1.300 + default: 1.301 + $genre_id = intval($genre_id); // to handle 3 or '3' or '03' 1.302 + break; 1.303 + } 1.304 + $lookup = getid3_id3v1::ArrayOfGenres($allow_SCMPX_extended); 1.305 + return (isset($lookup[$genre_id]) ? $lookup[$genre_id] : false); 1.306 + } 1.307 + 1.308 + 1.309 + public static function LookupGenreID($genre, $allow_SCMPX_extended=false) { 1.310 + 1.311 + $lookup = getid3_id3v1::ArrayOfGenres($allow_SCMPX_extended); 1.312 + $lower_case_no_space_search_term = strtolower(str_replace(' ', '', $genre)); 1.313 + foreach ($lookup as $key => $value) { 1.314 + foreach ($lookup as $key => $value) { 1.315 + if (strtolower(str_replace(' ', '', $value)) == $lower_case_no_space_search_term) { 1.316 + return $key; 1.317 + } 1.318 + } 1.319 + return false; 1.320 + } 1.321 + return (isset($lookup[$genre_id]) ? $lookup[$genre_id] : false); 1.322 + } 1.323 + 1.324 +} 1.325 + 1.326 + 1.327 +?> 1.328 \ No newline at end of file