SSLTrack::guessLengthFromFile PHP Method

guessLengthFromFile() protected method

Not sure why; perhaps files that have never been analysed. So, let's attempt to guess it by analysing the full file.
protected guessLengthFromFile ( )
    protected function guessLengthFromFile()
    {
        $fullpath = $this->getFullpath();
        if (strlen($fullpath) == 0) {
            L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Guessing MP3 length from file failed: full path was empty. Perhaps this entry was manually added?', array());
            return "0:00";
        }
        if (!$this->file_exists($fullpath)) {
            L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Guessing MP3 length from file failed: file not found (%s)', array($fullpath));
            return "0:00";
        }
        $external_factory = Inject::the(new ExternalRepo());
        /* @var $external_factory ExternalFactory */
        $getid3 = $external_factory->newGetID3();
        /* @var $getid3 getid3 */
        $getid3->option_tag_lyrics3 = false;
        $getid3->option_tag_apetag = false;
        $getid3->option_extra_info = true;
        $getid3->encoding = 'UTF-8';
        try {
            $info = $getid3->Analyze($fullpath);
            $playtime = $info['playtime_seconds'];
            if ($playtime) {
                L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Guessed MP3 length %d seconds from file.', array($playtime));
                $minutes = floor($playtime / 60);
                $seconds = $playtime % 60;
                return sprintf("%d:%02d", $minutes, $seconds);
            }
            L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Guessing MP3 length from file failed for an unknown reason. Hmmph.', array());
        } catch (getid3_exception $e) {
            // MP3 couldn't be analyzed.
            L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Guessing MP3 length from file failed: %s', array($e->getMessage()));
        }
        return "0:00";
    }