Location: PHPKode > projects > VideoDB > videodb/engines/dvdfr.php
<?php
/**
 * Dvdfr Parser
 *
 * Parses data from www.dvdfr.com (french site)
 * 2006-08-12 Update Sebastien Koechlin <hide@address.com>
 *
 * @package Engines
 * @author  tedemo  <hide@address.com>
 * @link    http://www.dvdfr.com  
 * @version $Id: dvdfr.php,v 1.3 2007/08/09 08:55:28 andig2 Exp $
 */

require_once './core/compatibility.php';

$GLOBALS['dvdfrServer']	= 'http://www.dvdfr.com';

/**
 * Get meta information about the engine
 *
 * @todo    Include image search capabilities etc in meta information
 */
function dvdfrMeta()
{
    return array('name' => 'Dvdfr (fr)', 'stable' => 0);
}

/**
 * Get Url to search Dvdfr for a movie
 *
 * @param   string    The search string
 * @return  string    The search URL (GET)
 */
function dvdfrSearchUrl($title)
{
	global $dvdfrServer;
	return $dvdfrServer.'/search/search.php?multiname='.urlencode($title);
}

/**
 * Get Url to visit Dvdfr for a specific movie
 *
 * @param   string	$id	The movie's external id
 * @return  string		The visit URL
 */
function dvdfrContentUrl($id)
{
    list($engineword, $dvdfrID) = split(":",$id,2);
	global $dvdfrServer;
	return $dvdfrServer.'/dvd/dvd.php?id='.$dvdfrID;
}

/**
 * Search a Movie
 *
 * Searches for a given title on Dvdfr and returns the found links in
 * an array
 *
 * @return  array     Associative array with id and title
 */
function dvdfrSearch($title)
{
    global $dvdfrServer;
    global $CLIENTERROR;

    $resp = httpClient(dvdfrSearchUrl($title), 1);
    if (!$resp['success']) $CLIENTERROR .= $resp['error']."\n";
    #print "<table border=3>". $resp['data']. "</table>";

    // direct match (redirecting to individual title)?
    $single = array();
    if (preg_match('/\/dvd\/dvd\.php\?id=(\d+)/', $resp['url'], $single))
    {
        $ary[0]['id']   = 'dvdfr:'.$single[1];
        preg_match('/<td><div class=\"dvd_title\">([^<]+)<\/div>[^<]*<div class=\"dvd_titlevo\">([^<]+)<\/div>[^<]*<div class=\"dvd_titleinfo\">([^<]+)</is', $resp['data'], $single);
        $ary[0]['title']= $single[1].' ('.$single[2].'/'.$single[3].')';
        return $ary;
    }

    // multiple matches
    preg_match_all('/<TD><A CLASS=\"searchText\" HREF=\"[^>]+\/dvd\/f(\d+)_[^>]+\.html\">([^<]+)<\/A><\/TD>[^<]*<TD[^>]*>([^<]+)<\/TD>[^<]*<TD[^>]*>([^<]+)<\/TD>[^<]*<TD[^>]*>([^<]+)<\/TD>/is', $resp['data'], $data, PREG_SET_ORDER);
    foreach ($data as $row) 
    {
        $info['id']     = 'dvdfr:'.$row[1];
        $info['title']  = trim($row[2]);
        // add year (helpful in case of multiple matches)
        if (isset($row[3]) || isset($row[4]) || isset($row[5])) $info['title'] .= ' (';
        if (isset($row[4])) $info['title'] .= trim($row[4]);		//Year
        if (isset($row[3])) $info['title'] .= '/'.trim($row[3]);	//Actors
        if (isset($row[5])) $info['title'] .= '/'.trim($row[5]);	//DVD status
        if (isset($row[3]) || isset($row[4]) || isset($row[5])) $info['title'] .= ')';
        $ary[]          = $info;
    }

    return $ary;
}

/**
 * Fetches the data for a given Dvdfr-ID
 *
 * @param   int   IMDB-ID
 * @return  array Result data
 */
function dvdfrData($imdbID) 
{
    global $dvdfrServer;
    global $CLIENTERROR;

    $data= array();	// result
    $ary = array();	// temp

    // fetch mainpage
    $resp = httpClient(dvdfrContentUrl($imdbID), 1);		// added trailing / to avoid redirect
    if (!$resp['success']) $CLIENTERROR .= $resp['error']."\n";

    // Titles
    preg_match('/<div class="dvd_title">([^<]+)<\/div>/is', $resp['data'], $ary);
    $data['title']    = mb_convert_case(trim($ary[1]), MB_CASE_TITLE);
    preg_match('/<div class="dvd_titlevo">([^<]+)<\/div>/is', $resp['data'], $ary);
    $data['subtitle']    = $ary[1];    
    // I found: <div class="dvd_titleinfo">USA, Royaume-Uni , 2004<br />R&D TV, Sky TV, USA Cable Entertainment</div>
    preg_match('/<div class=\"dvd_titleinfo\">([^0-9]+?),(\s*(\d+))?\s*<br[^>]*>([^<]+)<\/div>/is', $resp['data'], $ary);
    $data['country'] = trim($ary[1]);
    $data['year'] = $ary[2];

    // Year
    if (empty ($data['year']))
    {
	    preg_match('/Date de sortie en salle[^\n]+\n[^\n]+([12]\d\d\d)/i', $resp['data'], $ary);
	    if (!empty($ary[1]))
	    {
	        $data['year'] = trim($ary[1]);
	    }
    }

    // Cover URL
    preg_match('/<img[^>]+src="\.\.(\/images\/dvd\/cover_200x280\/[^"]+)"/i', $resp['data'], $ary);
    $data['coverurl'] = $dvdfrServer . $ary[1];

    // Runtime
    preg_match('/<img alt="Dur.e"[^\n]+\n\s*<TD>(\d+) min/i', $resp['data'], $ary);
    $data['runtime']  = $ary[1];

    // Director (only the first one)
    preg_match('/R.alisation<\/div>[^\n]*\n[^<]*<div[^>]*>\s*<a [^>]*>([^<]+)<\/a>/i', $resp['data'], $ary);
    $data['director'] = trim($ary[1]);

    // Plot
    preg_match('/Synopsis<\/div>[^<]+<div[^>]+>([^<]+)/is', $resp['data'], $ary);
    if (!empty($ary[1])) $data['plot'] = trim($ary[1]);
    // And cleanup
    $data['plot'] = preg_replace('/[\n\r]/',' ', $data['plot']);
    $data['plot'] = preg_replace('/  /',' ', $data['plot']);
    $data['plot'] = trim($data['plot']);

    // maps dvdfr category ids to videodb category names
    $category_map = array 
    (
        "1" => "Action",
        "2" => "Animation",
        "61" => "", //  "Autres séries"
        "3" => "Adventure",
        "72" => "", //"Beaux-Arts"
        "81" => "Musical", //"Bollywood"
        "4" => "Comedy",
        "5" => "Drama", // "Comédie dramatique"
        "6" => "Musical", //"Comédie musicale"
        "74" => "Romance", // "Comédie romantique"
        "7" => "Music", //"Concert"
        "8" => "" , //"Conte"
        "9" => "Short", //"Court-Métrage"
        "10" => "Documentary", //"Culture"
        "78" => "Documentary", //"Culture Gay"
        "11" => "Music", //"Danse"
        "12" => "", //"Divers"
        "13" => "Documentary", //"Documentaire"
        "14" => "Drama", //"Drame"
        "73" => "Drama", //"Emotion"
        "15" => "Adult", //"Erotique"
        "16" => "Action", //"Espionnage"
        "17" => "Sci-Fi", //"Fantastique"
        "30" => "Musical", //"Film musical"
        "83" => "Sport", //"Freefight"
        "18" => "War", //"Guerre"
        "19" => "Musical", //"Hard-rock"
        "20" => "History", //"Historique"
        "21" => "Horror", //"Horreur"
        "22" => "Comedy", //"Humour"
        "23" => "Animation", //"Japanimation"
        "24" => "Adult", //"Japanimation érotique"
        "25" => "Music", //"Jazz &amp; Blues"
        "79" => "", //"Jeux"
        "26" => "Music", //"Karaoke"
        "27" => "Action", //"Kung Fu"
        "28" => "", //"Méthode"
        "57" => "", //"Mini-series / Feuilletons"
        "29" => "Documentary", //"Muet"
        "32" => "Music", //"Musique Classique"
        "71" => "Music", //"Musiques du monde"
        "31" => "Music", //"Opéra"
        "33" => "War", //"Péplum"
        "34" => "Crime", //"Policier"
        "54" => "", //"Pour enfants"
        "76" => "Music", //"R&amp;B &amp; Soul"
        "55" => "Music", //"Rap"
        "56" => "Sci-Fi", //"Science Fiction"
        "60" => "", //"Série Anime / OAV"
        "75" => "", //"Série d'animation enfants"
        "58" => "", //"Série TV"
        "59" => "", //"Sitcom"
        "62" => "", //"Spectacle"
        "63" => "Sport",
        "82" => "Sport", //"Sports mécaniques"
        "64" => "Music", //"Techno / Electro"
        "65" => "", //"Theatre"
        "66" => "Thriller",
        "67" => "Music", //"Variété française"
        "68" => "Music", //"Variété internationale"
        "69" => "Documentary", //"Voyages"
        "70" => "Western"
    );

    // Genres (as Array)
    if (preg_match_all('/<a[^>]+"\.\.\/search\/search.php\?categorie=(\d+)[^>]+>([^<]+)<\/a>/i', $resp['data'], $ary, PREG_PATTERN_ORDER) > 0)
    {
        $count = 0;
    	while (isset($ary[1][$count])) 
    	{
              $data['genres'][]  = $category_map[$ary[1][$count]];
              $count ++;
        }
    }

    // Cast
    preg_match('/Avec\.\.\.<\/div>[^\n]*\n(.*)/i', $resp['data'], $Section);
    preg_match_all('/<a[^>]+\/search\/s(\d+)[^>]+>([^>]+)<\/a>/i', $Section[1], $ary,PREG_PATTERN_ORDER);

    $count = 0;
    while (isset($ary[1][$count])) 
    {
	    $cast  .= $ary[2][$count]."::::dvdfr:".$ary[1][$count]."\n";
        $count++;
    }
    $data['cast'] = trim($cast);

    return $data;
}

/**
 * Parses Actor-Details
 *
 * Find image and detail URL for actor, not sure if this can be made
 * a one-step process?  Completion waiting on update of actor
 * functionality to support more than one engine.
 *
 * @param  string  $name  Name of the Actor
 * @return array          array with Actor-URL and Thumbnail
 */
function dvdfrActor($name, $actorengineid)
{
    global $dvdfrServer;
	
    return;
}

?>
Return current item: VideoDB