tboothman / imdbphp

PHP library for retrieving film and tv information from IMDb
253 stars 84 forks source link

Alternate versions method adjustments #225

Closed duck7000 closed 3 years ago

duck7000 commented 3 years ago

I have a few adjustments for alternate versions method Sometimes there are still list items in the output, some of it is useful, most is not. this filters out most of it.

I don't think it will be necessary to make a pull request for such small adjustments? @tboothman maybe you can/will make this to a commit? at least if you think it is useful off course.

    /**
     * Get the Alternate Versions for a given movie
     * @return array Alternate Version (array[0..n] of string)
     * @see IMDB page /alternateversions
     */
    public function alternateVersions()
    {
        if (empty($this->moviealternateversions)) {
            $page = $this->getPage('AlternateVersions');

            if (false !== strpos($page, 'id="no_content"')) {
                return array();
            }
            $check = array("<ul><li>", "</li><li>");
            if (preg_match_all('!<div class="soda (odd|even)">\s*(.*?)\s*</div>!ims', $page, $matches)) {
                foreach ($matches[2] as $match) {
                    $alt = strip_tags(trim(str_replace("\n", " ", $match)), $check);
                    $this->moviealternateversions[] = $alt;
                }
            }
        }
        return $this->moviealternateversions;
    }
duck7000 commented 3 years ago

I ended up with a pull request, rewrote to new xpath function as well.