Clase IMDB Grabber por Fabian Beiner -

Uno de mis lectores, Fabian Beiner, llevó mi scriptIMDB Grabber basado en PHP un paso más allá y lo convirtió en una clase útil. La clase también tiene la capacidad de obtener más información que mi guión. ¡Échale un vistazo!

PHP

?php/** * @author Fabian Beiner fabianDOTbeinerATgmailDOTcom * @version 2.1alpha * * @comment Idea original de David Walsh davidATdavidwalshDOTname, ¡gracias! Tu blog es genial ;) * Hice este guión en medio de la noche mientras estaba enfermo, ¡no hay garantía de nada! * * @license http://creativecommons.org/licenses/by-sa/3.0/de/deed.en_US * Creative Commons Attribution-Share Alike 3.0 Argentina * * Sí, después de dos días IMDB cambió su diseño... ¡Genial! :( También se agregó un respaldo si falta cURL. */class IMDB { function __construct($url) { $this-gotCurl = extension_loaded('curl'); $imdb_content = $this-imdbHandler($url); $this- movie = trim($this-getMatch('|title(.*) ((.*))/title|Uis', $imdb_content)); $this-director = trim($this-getMatch('|h5Director:/ h5a href="https://soloprogramadores.top/clase-imdb-grabber-por-fabian-beiner/(.*)"(.*)/abr/|Uis', $imdb_content, 2)); $this-url_director = trim($this-getMatch('|h5Director:/h5a href="(. *)"(.*)/abr/|Uis', $imdb_content)); $this-plot = trim($this-getMatch('|h5Plot:/h5(.*) a|Uis', $imdb_content)) ; $this-release_date = trim($this-getMatch('|h5Fecha de lanzamiento:/h5 (.*) ((.*)) a|Uis', $imdb_content)); $this-mpaa = trim($this- getMatch('|h5a href="http://soloprogramadores.top/mpaa"MPAA/a:/h5 (.*)/div|Uis', $imdb_content)); $this-run_time = trim($this-getMatch('|Runtime:/h5 (.*) (.*)/div|Uis',$imdb_content)); $this-rating = trim($this-getMatch('|divb(.*)/b|Uis', $imdb_content)); $ this-votes = trim($this-getMatch('| a href="ratings"(.*) votos/a|Uis', $imdb_content)); $this-country = trim($this-getMatch('|h5Country :/h5a href="https://soloprogramadores.top/clase-imdb-grabber-por-fabian-beiner/(.*)"(.*)/a/div|Uis', $imdb_content, 2)); $this-url_country = trim($this-getMatch('|h5Country:/h5a href="https://soloprogramadores.top/clase-imdb-grabber-por-fabian-beiner/(.*)"(.*)/a/div|Uis', $imdb_content)); } función imdbHandler($entrada) { if (!$this-getMatch('|^http://(.*)$|Uis', $entrada)) { $tmpUrl="http://us.imdb.com /find?s=allq=".str_replace(' ', '+', $entrada).'x=0y=0'; if ($this-gotCurl) { $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL = $tmpUrl, CURLOPT_HEADER = falso, CURLOPT_RETURNTRANSFER = verdadero, CURLOPT_TIMEOUT = 10)); $datos = curl_exec($ch); curl_close($ch); } más { $datos = file_get_contents($tmpUrl); } $foundMatch = $this-getMatch('|pbMedia de a href="https://soloprogramadores.top/clase-imdb-grabber-por-fabian-beiner/(.*)"(.*)/a ((.*))/b/p|Uis', $data); si ($foundMatch) { $esta-url="http://www.imdb.com". $ encontradoCoincidencia; } else { $esta-url=""; devolver 0; } } else { $esta-url = $entrada; } if ($this-gotCurl) { $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL = $esta-url, CURLOPT_HEADER = falso, CURLOPT_RETURNTRANSFER = verdadero, CURLOPT_TIMEOUT = 10)); $datos = curl_exec($ch); curl_close($ch); } else { $datos = file_get_contents($esta-url); } return str_replace("n",'',(cadena)$datos); } función getMatch($regex, $content, $index=1) { preg_match($regex, $content, $matches); return $coincidencias[(int)$index]; } función showOutput() { if ($esta-url) { $content.= 'h2Film/h2p'.$esta-película.'/p'; $content.= 'h2Director/h2pa href="http://www.imdb.com'.$this-url_director.'"'.$this-director.'/a/p'; $content.= 'h2Plot/h2p'.$this-plot.'/p'; $content.= 'h2Fecha de lanzamiento/h2p'.$this-release_date.'/p'; $content.= 'h2MPAA/h2p'.$this-mpaa.'/p'; $content.= 'h2Run Time/h2p'.$this-run_time.' minutos/p'; $content.= 'h2Detalles completos/h2pa href="'.$esta-url.'"'.$esta-url.'/a/p'; $content.= 'h2Rating/h2p'.$this-rating.'/p'; $content.= 'h2Votes/h2p'.$this-votes.' votos/p'; $content.= 'h2Country/h2pa href="http://www.imdb.com'.$this-url_country.'"'.$this-country.'/a/p'; eco $contenido; } else { echo 'Lo sentimos, ¡no se encontró nada! :('; } }}// Ejemplos :)$imdb = new IMDB('http://www.imdb.com/title/tt0367882/');print($imdb-showOutput());echo 'hr' ;$imdb = new IMDB('Cruel Intentions');print($imdb-showOutput());echo 'hr';$imdb = new IMDB('Supongo que el nombre de esta película no existe');print($imdb- mostrarSalida());? CURLOPT_TIMEOUT = 10 ) ); $datos = curl_exec($ch); curl_close($ch); } else { $datos = file_get_contents($esta-url); } return str_replace("n",'',(cadena)$datos); } función getMatch($regex, $content, $index=1) { preg_match($regex, $content, $matches); return $coincidencias[(int)$index]; } función showOutput() { if ($esta-url) { $content.= 'h2Film/h2p'.$esta-película.'/p'; $content.= 'h2Director/h2pa href="http://www.imdb.com'.$this-url_director.'"'.$this-director.'/a/p'; $content.= 'h2Plot/h2p'.$this-plot.'/p'; $content.= 'h2Fecha de lanzamiento/h2p'.$this-release_date.'/p'; $content.= 'h2MPAA/h2p'.$this-mpaa.'/p'; $content.= 'h2Run Time/h2p'.$this-run_time.' minutos/p'; $content.= 'h2Detalles completos/h2pa href="'.$esta-url.'"'.$esta-url.'/a/p'; $content.= 'h2Rating/h2p'.$this-rating.'/p'; $content.= 'h2Votes/h2p'.$this-votes.' votos/p'; $content.= 'h2Country/h2pa href="http://www.imdb.com'.$this-url_country.'"'.$this-country.'/a/p'; eco $contenido; } else { echo 'Lo sentimos, ¡no se encontró nada! :('; } }}// Ejemplos :)$imdb = new IMDB('http://www.imdb.com/title/tt0367882/');print($imdb-showOutput());echo 'hr' ;$imdb = new IMDB('Cruel Intentions');print($imdb-showOutput());echo 'hr';$imdb = new IMDB('Supongo que el nombre de esta película no existe');print($imdb- mostrarSalida());? CURLOPT_TIMEOUT = 10 ) ); $datos = curl_exec($ch); curl_close($ch); } else { $datos = file_get_contents($esta-url); } return str_replace("n",'',(cadena)$datos); } función getMatch($regex, $content, $index=1) { preg_match($regex, $content, $matches); return $coincidencias[(int)$index]; } función showOutput() { if ($esta-url) { $content.= 'h2Film/h2p'.$esta-película.'/p'; $content.= 'h2Director/h2pa href="http://www.imdb.com'.$this-url_director.'"'.$this-director.'/a/p'; $content.= 'h2Plot/h2p'.$this-plot.'/p'; $content.= 'h2Fecha de lanzamiento/h2p'.$this-release_date.'/p'; $content.= 'h2MPAA/h2p'.$this-mpaa.'/p'; $content.= 'h2Run Time/h2p'.$this-run_time.' minutos/p'; $content.= 'h2Detalles completos/h2pa href="'.$esta-url.'"'.$esta-url.'/a/p'; $content.= 'h2Rating/h2p'.$this-rating.'/p'; $content.= 'h2Votes/h2p'.$this-votes.' votos/p'; $content.= 'h2Country/h2pa href="http://www.imdb.com'.$this-url_country.'"'.$this-country.'/a/p'; eco $contenido; } else { echo 'Lo sentimos, ¡no se encontró nada! :('; } }}// Ejemplos :)$imdb = new IMDB('http://www.imdb.com/title/tt0367882/');print($imdb-showOutput());echo 'hr' ;$imdb = new IMDB('Cruel Intentions');print($imdb-showOutput());echo 'hr';$imdb = new IMDB('Supongo que el nombre de esta película no existe');print($imdb- mostrarSalida());?

¡Gracias a Fabián por compartir! ¡Disfruta!

Te podría interesar...

Deja una respuesta

Subir