<commit_before><?php

namespace MediaScraper\Adapter\Movie;

use Symfony\Component\DomCrawler\Crawler;

class TheMovieDb extends AbstractAdapter
{
    const SEARCH_URL = "http://api.themoviedb.org/2.1/Movie.search/%s/xml/%s/%s";
    const FIND_URL   = 'http://api.themoviedb.org/2.1/Movie.getInfo/%s/xml/%s/%s';
    const IMDB_URL   = 'http://api.themoviedb.org/2.1/Movie.imdbLookup/%s/xml/%s/%s';
    
    protected $apikey;
    protected $lang;
    
    public function __construct($apikey, $lang = 'en')
    {
        $this->apikey = $apikey;
        $this->lang = $lang;
    }
    
    public function getSearchResult(Crawler $crawler)
    {
        $ret = array();
        $movies = $crawler->filter('movies > movie');
        
        foreach ($movies as $movie) {
            $title = $movie->getElementsByTagName('name')->item(0)->nodeValue;
            $released = $movie->getElementsByTagName('released')->item(0)->nodeValue;
            preg_match('/(\d\d\d\d)-\d\d-\d\d/', $released, $matches);
            $year = $matches[1];
            $id = $movie->getElementsByTagName('id')->item(0)->nodeValue;
            
            $ret[] = array(
                'name' => sprintf('%s (%s)', $title, $year),
                'url'  => sprintf(TheMovieDb::FIND_URL,
                    $this->lang,
                    $this->apikey,
                    $id)
                );
        }
        
        return $ret;
    }
    
    public function getDetails(Crawler $crawler)
    {
        // TODO
    }
    
    protected function getSearchMovieUrl($title, $year = false)<commit_msg>Got something working, but need some cleanup<commit_after><?php

namespace MediaScraper\Adapter\Movie;

use Symfony\Component\DomCrawler\Crawler;

class TheMovieDb extends AbstractAdapter
{
    const SEARCH_URL = "http://api.themoviedb.org/2.1/Movie.search/%s/xml/%s/%s";
    const FIND_URL   = 'http://api.themoviedb.org/2.1/Movie.getInfo/%s/xml/%s/%s';
    const IMDB_URL   = 'http://api.themoviedb.org/2.1/Movie.imdbLookup/%s/xml/%s/%s';
    
    protected $apikey;
    protected $lang;
    
    public function __construct($apikey, $lang = 'en')
    {
        $this->apikey = $apikey;
        $this->lang = $lang;
    }
    
    public function getSearchResult(Crawler $crawler)
    {
        $ret = array();
        $movies = $crawler->filter('movies > movie');
        
        foreach ($movies as $movie) {
            $title = $movie->getElementsByTagName('name')->item(0)->nodeValue;
            $released = $movie->getElementsByTagName('released')->item(0)->nodeValue;
            preg_match('/(\d\d\d\d)-\d\d-\d\d/', $released, $matches);
            $year = $matches[1];
            $id = $movie->getElementsByTagName('id')->item(0)->nodeValue;
            
            $ret[] = array(
                'name' => sprintf('%s (%s)', $title, $year),
                'url'  => sprintf(TheMovieDb::FIND_URL,
                    $this->lang,
                    $this->apikey,
                    $id)
                );
        }
        
        return $ret;
    }
    
    public function getDetails(Crawler $crawler)
    {
        $movies = $crawler->filter('movies > movie');
        $movie = $movies->first();
        
        // TODO : more info
        
        return array(
            'title' => $movie->filter('name')->text(),
            'year'  => $movie->filter('released')->text(),
            'plot'  => $movie->filter('overview')->text(),
            );
    }
    
    protected function getSearchMovieUrl($title, $year = false)
{'fraction_non_alphanumeric': 0.1670428893905192, 'fraction_numerical': 0.0056433408577878106, 'mean_word_length': 1.915296052631579, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264857', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1147, 'n_words': 178}