diff options
author | Paul Arthur <flowerysong00@yahoo.com> | 2011-02-21 15:13:08 -0500 |
---|---|---|
committer | Paul Arthur <flowerysong00@yahoo.com> | 2011-02-21 15:13:08 -0500 |
commit | fa505d770830902f7cce9fa2f42f9785273b7abc (patch) | |
tree | 31a25425b9af8c92f499f28c7d08d89799508f76 /lib/class/vainfo.class.php | |
parent | 997c05143c88f1a0964588a4c1506acf7c8c31ea (diff) | |
download | ampache-fa505d770830902f7cce9fa2f42f9785273b7abc.tar.gz ampache-fa505d770830902f7cce9fa2f42f9785273b7abc.tar.bz2 ampache-fa505d770830902f7cce9fa2f42f9785273b7abc.zip |
Add support for autodetecting encoding for broken id3v2 tags
Mostly untested. Must be enabled in config, so we won't be breaking
people's perfectly valid tags by default.
Diffstat (limited to 'lib/class/vainfo.class.php')
-rw-r--r-- | lib/class/vainfo.class.php | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/lib/class/vainfo.class.php b/lib/class/vainfo.class.php index f763912c..dace9874 100644 --- a/lib/class/vainfo.class.php +++ b/lib/class/vainfo.class.php @@ -221,7 +221,7 @@ class vainfo { } /* Use default mb_detect_order in php.ini or not */ - if (Config::get('mb_detect_override') == "1") { + if (Config::get('mb_detect_order')) { $mb_order = Config::get('mb_detect_order'); } elseif (function_exists('mb_detect_order')) { @@ -231,45 +231,68 @@ class vainfo { $mb_order = "auto"; } + $test_tags = array('artist', 'album', 'genre', 'title'); + if ($encoding_id3v1) { $this->encoding_id3v1 = $encoding_id3v1; } - elseif (function_exists('mb_detect_encoding')) { + else { + foreach ($test_tags as $tag) { + if ($value = $this->_raw['id3v1'][$tag]) { + $tags[$tag] = $value; + } + } + + $this->encoding_id3v1 = self::_detect_encoding($tags, $mb_order); + } + + if (Config::get('getid3_detect_id3v2_encoding')) { + foreach ($test_tags as $tag) { + if ($value = $this->_raw['id3v2']['comments'][$tag]) { + $tags[$tag] = $value; + } + } + + $this->encoding_id3v2 = self::_detect_encoding($tags, $mb_order); + $this->_getID3->encoding_id3v2 = $this->encoding_id3v2; + } + + $this->_getID3->encoding_id3v1 = $this->encoding_id3v1; + + } // vainfo + + /** + * _detect_encoding + * Takes an array of tags and attempts to automatically detect their + * encoding. + */ + private static function _detect_encoding($tags, $mb_order) { + if (function_exists('mb_detect_encoding')) { debug_event('vainfo', "id3v -> $id3v", 5); $encodings = array(); $tags = array('artist', 'album', 'genre', 'title'); foreach ($tags as $tag) { - if ($value = $this->_raw['id3v1'][$tag]) { - $encodings[mb_detect_encoding($value, $mb_order, true)]++; - } + $encodings[mb_detect_encoding($tag, $mb_order, true)]++; } - debug_event('vainfo', 'encoding detection (id3v1): ' . print_r($encodings, true), 5); + debug_event('vainfo', 'encoding detection: ' . print_r($encodings, true), 5); $high = 0; foreach ($encodings as $key => $value) { if ($value > $high) { - debug_event('vainfo', '$encoding_id3v1 set to ' . $key, 5); - $encoding_id3v1 = $key; + $encoding = $key; $high = $value; } } - if ($encoding_id3v1 != 'ASCII' && $encoding_id3v1 != '0') { - $this->encoding_id3v1 = $encoding_id3v1; + if ($encoding != 'ASCII' && $encoding != '0') { + return $encoding; } else { - $this->encoding_id3v1 = 'ISO-8859-1'; + return 'ISO-8859-1'; } - - debug_event('vainfo', 'encoding detection (id3v1) selected ' . $this->encoding_id3v1, 5); - } - else { - $this->encoding_id3v1 = 'ISO-8859-1'; } - - $this->_getID3->encoding_id3v1 = $this->encoding_id3v1; - - } // vainfo + return 'ISO-8859-1'; + } /** |