Itunes m4a tag reading error

The place for "I can't figure out how to..." questions.
Post Reply
nakinigit
User
Posts: 6
Joined: Tue Jun 10, 2014 12:45 am
Are you a spambot?: no

Itunes m4a tag reading error

Post by nakinigit » Tue Jun 10, 2014 2:24 am

I have searched on this topic, and I see that there have been problems similar to what I'm currently seeing, but have been solved. I have music that I had purchased from itunes before I knew better, the files are m4a. Getid3 is failing to properly read the tags:

Code: Select all

2014-05-06 20:41:19 [admin] (vainfo.class.php) -> getId3 file {"\/home\/naknight\/Data\/Multimedia\/Music\/Mayer Hawthorne\/A Strange Arrangement\/08 One Track Mind.m4a"} - analyze {{"GETID3_VERSION":"1.10.0-20140319","filesize":4005067,"filepath":"\/home\/naknight\/Data\/Multimedia\/Music\/Mayer Hawthorne\/A Strange Arrangement","filename":"08 One Track Mind.m4a","filenamepath":"\/home\/naknight\/Data\/Multimedia\/Music\/Mayer Hawthorne\/A Strange Arrangement\/08 One Track Mind.m4a","avdataoffset":28672,"avdataend":4005067,"fileformat":"quicktime","encoding":"UTF-8","mime_type":"video\/quicktime","quicktime":{"hinting":false,"controller":"standard","ftyp":{"hierarchy":"ftyp","name":"ftyp","size":32,"offset":0,"signature":false,"unknown_1":false,"fourcc":false},"moov":{"hierarchy":"moov","name":"moov","size":26262,"offset":32,"subatoms":false},"free":{"hierarchy":"free","name":"free","size":2370,"offset":26294},"mdat":{"hierarchy":"mdat","name":"mdat","size":3976403,"offset":28664},"encoding":"UTF-8"}}} 
2014-05-06 20:41:19 [admin] (vainfo) -> encoding detection: [] 
2014-05-06 20:41:19 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:19 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:19 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:19 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:19 [admin] (vainfo) -> /(.+?)\/(.+?)\/([0-9]+?)\-(.+?)\..+$/ matched  on Mayer Hawthorne/A Strange Arrangement/08 One Track Mind.m4a 
2014-05-06 20:41:19 [ampache] (PHP) -> [Runtime Error] Invalid argument supplied for foreach() in file /usr/share/ampache/lib/class/vainfo.class.php(264) 
2014-05-06 20:41:19 [admin] (Plugins) -> Plugin ChartLyrics is not installed, skipping 
2014-05-06 20:41:30 [admin] (tag-read) -> Reading tags from /home/naknight/Data/Multimedia/Music/Calexico/The Black Light/14 Stray.m4a 
2014-05-06 20:41:30 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:30 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:30 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671) 
2014-05-06 20:41:30 [ampache] (PHP) -> [Runtime Error] fread(): Length parameter must be greater than 0 in file /usr/share/ampache/modules/getid3/getid3.php(1671
If I were to convert these files to flac, tags are read just fine. A few details of my system:
getid3 version 1.9.6-1, installed on ubuntu 13.10
php version 5.5.3

I see that there are a number of known problems with itunes incorrectly writing tags, and maybe this problem is related to that. If so, is there a way I can clean them up? Tried deleting tags with atomic parsley, then re-creating them with musicbrainz picard. No luck.

James Heinrich
getID3() v1 developer
Posts: 1424
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Itunes m4a tag reading error

Post by James Heinrich » Tue Jun 10, 2014 2:48 am

There aren't any known problems with tag reading such as what you describe.

You might want to update to the most current getID3 release (v1.9.8) -- if that doesn't solve your problem please send me a copy of said file for analysis.

nakinigit
User
Posts: 6
Joined: Tue Jun 10, 2014 12:45 am
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by nakinigit » Wed Jun 11, 2014 11:06 pm

Ok, I tried running demo.browse.php from both my original version of getid3 and the latest version... they both were able to read the tags. So now I don't know where the problem lies. Is "demo.browse.php" a valid test?

James Heinrich
getID3() v1 developer
Posts: 1424
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Itunes m4a tag reading error

Post by James Heinrich » Thu Jun 12, 2014 12:45 am

If demo.browse can read the file without problem then that would tend to indicate there's not a problem in getID3. Perhaps if you post the code snippet where you call getID3 that might give a clue? With the current version of getID3, do you still get that "fread(): Length parameter must be greater than 0" error? If so, on what line number?

nakinigit
User
Posts: 6
Joined: Tue Jun 10, 2014 12:45 am
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by nakinigit » Thu Jun 12, 2014 6:12 pm

Is there a way to enable logging?

James Heinrich
getID3() v1 developer
Posts: 1424
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Itunes m4a tag reading error

Post by James Heinrich » Thu Jun 12, 2014 6:55 pm

Logging of what?

nakinigit
User
Posts: 6
Joined: Tue Jun 10, 2014 12:45 am
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by nakinigit » Fri Jun 13, 2014 12:34 am

You had asked if I'm still getting "fread(): Length parameter must be greater than 0" error. I don't see it in the html file generated, but I don't know if the html file would include all of the errors encountered. Does it?

The reason I ask is per request of the Ampache maintainer, have changed the line in demo.browse.php that read:

Code: Select all

$getID3->setOption(array('encoding' => $PageEncoding));
to:

Code: Select all

$getID3->option_md5_data = false;
$getID3->option_md5_data_source = false;
$getID3->option_tags_html = false;
$getID3->option_extra_info = true;
$getID3->option_tag_lyrics3 = true;
$getID3->option_tags_process = true;
$getID3->encoding = "UTF-8";
And this, I suspect, is how Ampache calls getid3.

It's a mystery; demo.browse.php seems to do fine with the changes I have made, Yet Ampache stumbles on m4a's. Please bear with me on this, I am working with Ampache, as well as you on this. And it's me because so far, no one else has reported this problem.

James Heinrich
getID3() v1 developer
Posts: 1424
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Itunes m4a tag reading error

Post by James Heinrich » Fri Jun 13, 2014 1:35 am

Errors such as the fread one are PHP errors and would be located wherever your PHP errors are logged (depends on your php.ini configuration settings, notably the error_log directive).

nakinigit
User
Posts: 6
Joined: Tue Jun 10, 2014 12:45 am
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by nakinigit » Thu Jul 03, 2014 1:36 am

James Heinrich wrote:If demo.browse can read the file without problem then that would tend to indicate there's not a problem in getID3. Perhaps if you post the code snippet where you call getID3 that might give a clue? With the current version of getID3, do you still get that "fread(): Length parameter must be greater than 0" error? If so, on what line number?
I am still getting the "fread(): Length parameter must be greater than 0" error" with the latest, and it is on getid3.php, line 1671. Here a snippet of code I think call getid3. Not all that familiar with php, so I'm hoping something might look obvious to you:

Code: Select all

<?php

 * This class takes the information pulled from getID3 and returns it in a
 * Ampache-friendly way.
 *
 */
class vainfo
{
    public $encoding = '';
    public $encoding_id3v1 = '';
    public $encoding_id3v2 = '';

    public $filename = '';
    public $type = '';
    public $tags = array();
    public $islocal;

    protected $_raw = array();
    protected $_getID3 = '';
    protected $_forcedSize = 0;

    protected $_file_encoding = '';
    protected $_file_pattern = '';
    protected $_dir_pattern = '';

    private $_pathinfo;
    private $_broken = false;

    /**
     * Constructor
     *
     * This function just sets up the class, it doesn't pull the information.
     *
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function __construct($file, $encoding = null, $encoding_id3v1 = null, $encoding_id3v2 = null, $dir_pattern = '', $file_pattern ='', $islocal = true)
    {
        $this->islocal = $islocal;
        $this->filename = $file;
        $this->encoding = $encoding ?: AmpConfig::get('site_charset');

        /* These are needed for the filename mojo */
        $this->_file_pattern = $file_pattern;
        $this->_dir_pattern  = $dir_pattern;

        // FIXME: This looks ugly and probably wrong
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
            $this->_pathinfo = str_replace('%3A', ':', urlencode($this->filename));
            $this->_pathinfo = pathinfo(str_replace('%5C', '\\', $this->_pathinfo));
        } else {
            $this->_pathinfo = pathinfo(str_replace('%2F', '/', urlencode($this->filename)));
        }
        $this->_pathinfo['extension'] = strtolower($this->_pathinfo['extension']);

        if ($this->islocal) {
            // Initialize getID3 engine
            $this->_getID3 = new getID3();

            $this->_getID3->option_md5_data = false;
            $this->_getID3->option_md5_data_source = false;
            $this->_getID3->option_tags_html = false;
            $this->_getID3->option_extra_info = true;
            $this->_getID3->option_tag_lyrics3 = true;
            $this->_getID3->option_tags_process = true;
            $this->_getID3->encoding = $this->encoding;

            // get id3tag encoding (try to work around off-spec id3v1 tags)
            try {
                $this->_raw = $this->_getID3->analyze(Core::conv_lc_file($file));
		debug_event('vainfo.class.php', "getId3 file {". json_encode($file)."} - analyze {". json_encode($this->_raw)."}", 5);
            } catch (Exception $error) {
                debug_event('getID3', "Broken file detected: $file: " . $error->getMessage(), 1);
                $this->_broken = true;
                return false;
            }

            if (AmpConfig::get('mb_detect_order')) {
                $mb_order = AmpConfig::get('mb_detect_order');
            } elseif (function_exists('mb_detect_order')) {
                $mb_order = implode(", ", mb_detect_order());
            } else {
                $mb_order = "auto";
            }

            $test_tags = array('artist', 'album', 'genre', 'title');

            if ($encoding_id3v1) {
                $this->encoding_id3v1 = $encoding_id3v1;
            } else {
                $tags = array();
                foreach ($test_tags as $tag) {
                    if ($value = $this->_raw['id3v1'][$tag]) {
                        $tags[$tag] = $value;
                    }
                }

                $this->encoding_id3v1 = self::_detect_encoding($tags, $mb_order);
            }

            if (AmpConfig::get('getid3_detect_id3v2_encoding')) {
                // The user has told us to be moronic, so let's do that thing
                $tags = array();
                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;
        }
    }

    public function forceSize($size)
    {
        $this->_forcedSize = $size;
    }

    /**
     * _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')) {
            $encodings = array();
            if (is_array($tags)) {
                foreach ($tags as $tag) {
                    $encodings[mb_detect_encoding($tag, $mb_order, true)]++;
                }
            }

            debug_event('vainfo', 'encoding detection: ' . json_encode($encodings), 5);
            $high = 0;
            $encoding = '';
            foreach ($encodings as $key => $value) {
                if ($value > $high) {
                    $encoding = $key;
                    $high = $value;
                }
            }

            if ($encoding != 'ASCII' && $encoding != '0') {
                return $encoding;
            } else {
                return 'ISO-8859-1';
            }
        }
        return 'ISO-8859-1';
    }


    /**
     * get_info
     *
     * This function runs the various steps to gathering the metadata
     */
    public function get_info()
    {
        // If this is broken, don't waste time figuring it out a second
        // time, just return their rotting carcass of a media file.
        if ($this->_broken) {
            $this->tags = $this->set_broken();
            return true;
        }

        if ($this->islocal) {
            try {
                $this->_raw = $this->_getID3->analyze(Core::conv_lc_file($this->filename));
            } catch (Exception $error) {
                debug_event('getID2', 'Unable to catalog file: ' . $error->getMessage(), 1);
            }
        }

        /* Figure out what type of file we are dealing with */
        $this->type = $this->_get_type();

        $enabled_sources = (array) AmpConfig::get('metadata_order');

        if (in_array('filename', $enabled_sources)) {
            $this->tags['filename'] = $this->_parse_filename($this->filename);
        }

        if (in_array('getID3', $enabled_sources) && $this->islocal) {
            $this->tags['getID3'] = $this->_get_tags();
        }

        $this->_get_plugin_tags();

    } // get_info

    /**
     * get_tag_type
     *
     * This takes the result set and the tag_order defined in your config
     * file and tries to figure out which tag type(s) it should use. If your
     * tag_order doesn't match anything then it throws up its hands and uses
     * everything in random order.
     */
    public static function get_tag_type($results, $config_key = 'metadata_order')
    {
        $order = (array) AmpConfig::get($config_key);

        // Iterate through the defined key order adding them to an ordered array.
        $returned_keys = array();
        foreach ($order as $key) {
            if ($results[$key]) {
                $returned_keys[] = $key;
            }
        }

        // If we didn't find anything then default to everything.
        if (!isset($returned_keys)) {
            $returned_keys = array_keys($results);
            $returned_keys = sort($returned_keys);
        }

        // Unless they explicitly set it, add bitrate/mode/mime/etc.
        if (is_array($returned_keys)) {
            if (!in_array('general', $returned_keys)) {
                $returned_keys[] = 'general';
            }
        }

        return $returned_keys;
    }

davist
User
Posts: 2
Joined: Fri Jul 11, 2014 12:42 pm
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by davist » Fri Jul 11, 2014 1:31 pm

I've been getting the exact same error since upgrading getID3 from 1.8.5 to 1.9.8. demo.browse.php worked, but my code errored. The difference was that my code was running from the command line rather than in the web server.

Added some debugging and tracked the problem down to PHP's memory_limit parameter. in the php.ini for cli this is set to -1 (unlimited), whereas the php.ini for apache uses 128M.

line 137 in getid3.php recognises this value:

if ($this->memory_limit <= 0) {
// memory limits probably disabled

but module.audio-video.quicktime.php line 71 doesn't:

$this->fread(min($atomsize, round($this->getid3->memory_limit / 2)))

nakinigit
User
Posts: 6
Joined: Tue Jun 10, 2014 12:45 am
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by nakinigit » Wed Jul 16, 2014 7:48 pm

@davist: Thanks for pointing me in the right direction!

On my installation, php.ini for cli was 128M. I had previously set php.ini for apache2 to -1, as I was having trouble streaming songs > 15 min. Changed it back to 128M. Fixed the problem.

James Heinrich
getID3() v1 developer
Posts: 1424
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Itunes m4a tag reading error

Post by James Heinrich » Fri Jul 18, 2014 12:24 pm


Brean
User
Posts: 1
Joined: Thu Jan 14, 2016 11:11 am
Are you a spambot?: no

Re: Itunes m4a tag reading error

Post by Brean » Fri Jan 15, 2016 1:08 pm

nakinigit wrote: I see that there are a number of known problems with itunes incorrectly writing tags, and maybe this problem is related to that. If so, is there a way I can clean them up? Tried deleting tags with atomic parsley, then re-creating them with musicbrainz picard. No luck.
Hi nakinigit some of my tags are wrong and some are missing completely. I'm running 1.9.11. Did you figure out how to fix this little issue?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests