login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Overige scripts > MovieDB

MovieDB

Auteur: Wim - 19 september 2007 - 13:52 - Gekeurd door: Stijn - Hits: 1976 - Aantal punten: (0 stemmen)


Dit systeem heb ik geschreven om alles op dvd terug te vinden.
Er zit geen admin gedeelte bij aangezien ik dit zelf overbodig vindt.

in de tabel 'dvd' voeg je de naam van de dvd toe, in mijn geval is dat FILM001, FILM002, ...

In de tabel contents voeg je de films toe die op de dvd staan. in het veld dvd zet je het id van de naam van de dvd -dat vindt je terug in de tabel dvd, kolom id-, bij title zet je de titel. Persoonlijk zet ik achter de titel ook het jaartal. In de kolom imdb zet je de VOLLEDIGE link naar de pagina op IMDB (in deze vorm: http://www.imdb.com/title/tt0317740/)

Op de index zullen alle films weergegeven worden. Er kan gezocht worden op titel, en de informatie wordt via de imdb parser van Bernd Essl uitgelezen.

Een voorbeeldje vindt je op http://www.gdx.be/moviedb
Het icoontje van de search-knop (wat met een image werkt) vindt je op http://www.gdx.be/moviedb/searchicon.png

Meer info over de klasse vindt je hier: http://codein.at/projects/imdb_parser-class/

Wim Mariën

//edit 8/11/2007 (v1.1)
- Error handling toegevoegd
- kleine wijziging aan de sql tabellen (met name waar de primary key's starten)
- wijziging aan de klasse om zo deftig gebruik te maken van het object en minder code te hebben :-)
- configuratiearray voor de MySQL verbinding toegevoegd

Code:

  1. CREATE TABLE `contents` (
  2. `id` int(10) NOT NULL AUTO_INCREMENT,
  3. `dvd` int(5) NOT NULL DEFAULT '0',
  4. `title` varchar(100) NOT NULL DEFAULT '',
  5. `imdb` varchar(36) NOT NULL DEFAULT '',
  6. PRIMARY KEY (`id`)
  7. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
  8.  
  9. CREATE TABLE `dvd` (
  10. `id` int(5) NOT NULL AUTO_INCREMENT,
  11. `label` varchar(10) NOT NULL DEFAULT '',
  12. PRIMARY KEY (`id`),
  13. UNIQUE KEY `label` (`label`)
  14. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;



  1. <?php
  2. $_LOGIN = array( // voor het admin gedeelte
  3. 'username' => '',
  4. 'password' => ''
  5. );
  6.  
  7. $_SQL = array(
  8. 'host' => '127.0.0.1',
  9. 'user' => '',
  10. 'passwd' => '',
  11. 'db' => ''
  12. );
  13.  
  14. //deze 3 regeltjes laten doen
  15. define ('DEBUG', 2);
  16. define ('ERRMESSAGE', 1);
  17. define ('SILENT', 0);
  18.  
  19.  
  20. define ('ERRORREPORTING', DEBUG); // DEBUG (errormessage + file + line), ERRMESSAGE (only errormessage) or SILENT (standard error message)
  21.  
  22. // base64 codering van het zoekicoontje, om externe bestanden te omzeilen :-)
  23. $searchicon = 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAUEAIAAAC9uT0nAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5n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qlzUvithWaNjkWepp8+CLHwtnoIlPmV5RmKMukc96NtdE5/boxxt/mRnHUIjjqnmqh1FdluCdpeuEwUFKScmlkzmz9V/g3agBu1hjYxcOYWmorRRqigVZ/YhFU+tR5z/vtyn0qMt1CBV3FdcLTjGtbE2Leg8azpm42S7alrdQO8JaIzprJw5w0kSjG5eLxCuX7NtAFPivng0vARzU4+6RPlQ4l68fHVm3gI6z7fHwNHxLKzZSmntrS6zy8quPSof82Or34ny9I/cWL9tLSghBbTw0hDj9Y+aZVkjsZd3nfZ1Vtgl9mImOmMBx3p0oMaiq1ji0nVPlWyf+H583FZ/eXhVpBbqoPdViJ+AD7tJLZoy7RyM6B3nTabBh5Y2FF6vlV6pvNvWPpXuWBiW/1m2Pz28NZILZVADHfBKwR7ek701bKJhd5LnXSm/a0TRRENb3xQZ4/7pZnvRklXrhBEblLAFRLAdXgOY4VfKxtAkB1nGaFLPQFNJhSUtgOXEEvlbhNRtrqe54lJaGrw2/hwAAUyL2Sf0w7MAAAAASUVORK5CYII=';
  24.  
  25.  
  26. if($_GET['view'] == 'searchicon') // voor het zoekicoontje
  27. {
  28. die(base64_decode($searchicon));
  29. }
  30.  
  31. try{
  32. if(!($sqlCon = mysql_connect($_SQL['host'], $_SQL['user'], $_SQL['passwd'])))
  33. throw new exception('We couldn\'t create a database connection!', 000);
  34. if(!mysql_select_db($_SQL['db'], $sqlCon))
  35. throw new exception('MySQL error! Couldn\'t find the db!', 001);
  36.  
  37. unset ($_SQL); // hebben we niet meer nodig, en deze gegevens zijn te gevoelig!
  38. }
  39. catch (exception $e)
  40. {
  41. error($e);
  42. }
  43.  
  44.  
  45.  
  46. //////// real code starts here
  47.  
  48. function error($e)
  49. {
  50. switch (ERRORREPORTING)
  51. {
  52. case ERRMESSAGE:
  53. $str = "<font color=\"red\">".$e->getMessage()." (".$e->getCode().")</font>";
  54. break;
  55. case DEBUG:
  56. $str = "<font color=\"red\">".$e->getMessage()." (".$e->getCode().")</font><br /><br /><em>(in file <strong>".$e->getFile()."</strong> on line <strong>".$e->getLine()."</strong>)</em>";
  57. case SILENT:
  58. $str = "We won't tell you where or why<br />\nLazy programmers";
  59. break;
  60. }
  61.  
  62. die("<h1>An error has occured!</h1><br /><br />".$str);
  63. }
  64.  
  65. if(is_numeric($_GET['movie']) && isset($_GET['movie']))
  66. {
  67. require_once('imdb.class.php');
  68. try
  69. {
  70. $query = mysql_query('SELECT contents.imdb AS imdb, dvd.label AS dvd '
  71. .'FROM contents '
  72. .'INNER JOIN dvd '
  73. .'ON (dvd.id = contents.dvd) '
  74. .'WHERE contents.id = \''.$_GET['movie'].'\' '
  75. .'LIMIT 1') or die(mysql_error());
  76. if(mysql_num_rows($query) != 1)
  77. {
  78. throw new Exception('Movie not found!', 100);
  79. }
  80.  
  81. if(!($movie = mysql_fetch_object($query)))
  82. throw new Exception('Unable to recieve the movie records', 101);
  83. if(!($imdb = new IMDB_Parser($movie->imdb)))
  84. throw new Exception('Unable to initialize the IMDB-information handler', 400);
  85.  
  86.  
  87. print ('<table width="760" border="0" cellspacing="0" cellpadding="0">');
  88.  
  89. print ('<tr>');
  90. print ('<td><strong>DVD</strong></td>');
  91. print ('<td><strong>'.$movie->dvd.'</strong></td>');
  92. print ('</tr>');
  93.  
  94. print ('<tr>');
  95. print ('<td><strong>Title</strong></td>');
  96. print ('<td>'.$imdb->getMovieTitle().'</td>');
  97. print ('</tr>');
  98.  
  99. print ('<tr>');
  100. print ('<td><strong>Language</strong></td>');
  101. print ('<td>'.implode(', ', $imdb->getMovieLanguage()).'</td>');
  102. print ('</tr>');
  103.  
  104. print ('<tr>');
  105. print ('<td><strong>Tagline</strong></td>');
  106. print ('<td>'.$imdb->getMovieTagline().'</td>');
  107. print ('</tr>');
  108.  
  109. print ('<tr>');
  110. print ('<td><strong>Plot</strong></td>');
  111. print ('<td>'.$imdb->getMoviePlot().'</td>');
  112. print ('</tr>');
  113.  
  114. print ('<tr>');
  115. print ('<td><strong>IMDB Rating</strong></td>');
  116. print ('<td>'.$imdb->getMovieRating().'</td>');
  117. print ('</tr>');
  118.  
  119. print ('<tr>');
  120. print ('<td><strong>Country</strong></td>');
  121. print ('<td>'.implode(', ', $imdb->getMovieCountry()).'</td>');
  122. print ('</tr>');
  123.  
  124. print ('<tr>');
  125. print ('<td><strong>Runtime</strong></td>');
  126. print ('<td>'.$imdb->getMovieRuntime().'</td>');
  127. print ('</tr>');
  128.  
  129. print ('<tr>');
  130. print ('<td>&nbsp;</td>');
  131. print ('<td>&nbsp;</td>');
  132. print ('</tr>');
  133.  
  134. print ('<tr>');
  135. print ('<td>&nbsp;</td>');
  136. print ('<td><a href="'.$movie->imdb.'" target="_blank"><strong>IMDB Link</strong></a></td>');
  137. print ('</tr>');
  138.  
  139. print ('<tr>');
  140. print ('<td>&nbsp;</td>');
  141. print ('<td>&nbsp;</td>');
  142. print ('</tr>');
  143.  
  144. print ('<tr>');
  145. print ('<td>&nbsp;</td>');
  146. print ('<td>&nbsp;</td>');
  147. print ('</tr>');
  148.  
  149. print ('<tr>');
  150. print ('<td>&nbsp;</td>');
  151. print ('<td>&nbsp;</td>');
  152. print ('</tr>');
  153.  
  154. print ('<tr>');
  155. print ('<td>&nbsp;</td>');
  156. print ('<td><em>Info powered by <a href="http://www.imdb.com/" target="_blank">IMDB</a></em></td>');
  157. print ('</tr>');
  158.  
  159. print ('</table>');
  160. }
  161. catch (Exception $e)
  162. {
  163. // movie details
  164. error($e);
  165. }
  166.  
  167. }
  168. elseif ($_GET['action'] == 'add')
  169. {
  170. try
  171. {
  172. if($_SERVER['PHP_AUTH_USER'] != $_LOGIN['username'] || $_SERVER['PHP_AUTH_PW'] != $_LOGIN['password'])
  173. {
  174. header("WWW-Authenticate: Basic realm=\"MovieDB ADMIN\"");
  175. header("HTTP/1.0 401 Unauthorized");
  176. throw new exception ('ACCESS DENIED!', 69);
  177. }
  178.  
  179. if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['adddvd']))
  180. {
  181. if(mysql_query('INSERT INTO dvd (label) VALUES (\''.mysql_real_escape_string($_POST['dvdname']).'\')'))
  182. print ('dvd added<br /><br />');
  183. else
  184. throw new exception('I was not able to add your dvd to the collection!', 300);
  185. }
  186. elseif($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['addmovie']))
  187. {
  188. if(!mysql_query('INSERT INTO contents (dvd,title,imdb) VALUES (\''.mysql_real_escape_string($_POST['dvd']).'\', \''.mysql_real_escape_string($_POST['title']).'\', \''.mysql_real_escape_string($_POST['imdb']).'\')'))
  189. throw new exception('I was not able to add this movie to the database!', 301);
  190. else
  191. print ('film toegevoegd!');
  192. }
  193.  
  194. print ('<strong>ADD DVD:</strong><form method="post"><input type="text" name="dvdname" /><input type="submit" name="adddvd" value="Add DVD!" /></form><br /><br />');
  195.  
  196. print ('<strong>ADD MOVIE:</strong><form method="post">Title: <input type="text" name="title" /><br />IMDB:<input type="text" name="imdb" /><br /><select name="dvd">');
  197.  
  198.  
  199. if(!($query = mysql_query('SELECT id,label FROM dvd')))
  200. throw new exception ('I was not able to select your DVD-index!', 200);
  201. if(!($n = mysql_num_rows($query)))
  202. throw new exception ('I was not able to retrieve the database info', 201);
  203. $i = 1;
  204. while ($dvd = mysql_fetch_object($query))
  205. {
  206. $selected = (($i++ == $n) ? ' selected' : NULL);
  207. print ('<option value="'.$dvd->id.'"'.$selected.'>'.$dvd->label.'</option>');
  208. }
  209.  
  210. print('</select><br /><input type="submit" name="addmovie" value="Add Movie!" /></form>');
  211. }
  212. catch (Exception $e)
  213. {
  214. // admin::add
  215. error($e);
  216. }
  217. }
  218. else
  219. {
  220. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  221. {
  222. $search = 'WHERE contents.title LIKE \'%'.mysql_real_escape_string($_POST['searchstring']).'%\' ';
  223. $noResults = 'No movies found!';
  224. }
  225. else
  226. {
  227. $search = NULL;
  228. $noResults = 'No movies added yet!';
  229. }
  230. // list ALL
  231. $query = 'SELECT contents.id AS id, contents.title AS title, contents.imdb AS imdb, dvd.label AS dvd '
  232. .'FROM contents '
  233. .'INNER JOIN dvd '
  234. .'ON (dvd.id = contents.dvd) '
  235. .$search // if we've hitted the search button, the WHERE-clausule will be added!
  236. .'ORDER BY dvd,title ASC';
  237.  
  238. if(!($query = mysql_query($query)))
  239. throw new exception ('Unable to search the database for matching records!');
  240. if(mysql_num_rows($query) < 1)
  241. {
  242. throw new exception ($noResults);
  243. }
  244. elseif(mysql_num_rows($query) == 1)
  245. {
  246. if(!($movie = mysql_fetch_object($query)))
  247. throw new exception('Unable to complete your search command!');
  248. header('location: ?movie='.$movie->id);
  249. }
  250.  
  251. print ('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
  252. print ('<tr>');
  253. print ('<td><strong>Titel</strong></td>');
  254. print ('<td><strong>DVD</strong></td>');
  255. print ('<td><strong>IMDB</strong></td>');
  256. print ('</tr>');
  257.  
  258. while ($movie = mysql_fetch_object($query))
  259. {
  260. print ('<tr>');
  261. print ('<td><a href="?movie='.$movie->id.'">[INFO]</a> '.$movie->title.'</td>');
  262. print ('<td>'.$movie->dvd.'</td>');
  263. print ('<td><a href="'.$movie->imdb.'" target="_blank">'.$movie->imdb.'</a></td>');
  264. print ('</tr>');
  265. $i++;
  266. }
  267.  
  268. print ('</table>');
  269. print ('<br /><br />'.$i.' movies in database');
  270. }
  271.  
  272. print ('<br /><br /><form method="post"><input type="text" name="searchstring" /><input type="image" src="?view=searchicon" value="search" alt="Search the database!"></form>');



imdb.class.php
  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6. * class.imdb_parser.php (php4)
  7. * Parse information of any film - need a fetched imdb.com video-detail-site
  8. * @author Bernd Essl <bernd@codein.at>
  9. * @copyright Bernd Essl <bernd@codein.at>
  10. * @license license http://gnu.org/copyleft/gpl.html GNU GPL
  11. * @link http://codein.at/
  12. */
  13.  
  14.  
  15. class IMDB_Parser
  16. {
  17.  
  18. var $imdbpage = NULL;
  19.  
  20.  
  21. function IMDB_Parser ($imdburl) // php 4
  22. {
  23. if(function_exists('file_get_contents'))
  24. {
  25. $this->imdbpage = file_get_contents($imdburl);
  26. }
  27. else
  28. {
  29. $f = fopen($imdburl, 'r');
  30. while (!feof($f))
  31. $this->imdbpage .= fread($f, 4096); //4KiB
  32. fclose($f);
  33. }
  34. }
  35.  
  36. function getMovieActors($name_and_id=False)
  37. {
  38. if (preg_match('/<table class="cast">(.+)<\/table>/', $this->imdbpage, $hit))
  39. {
  40. if ($name_and_id === True)
  41. {
  42. #name and id
  43. if (preg_match_all('/<a href="\/name\/(nm\d{1,8})\/">([^<]+)<\/a>/',$hit[0],$results, PREG_PATTERN_ORDER))
  44. {
  45. return $results;
  46. }
  47. else
  48. {
  49. return False;
  50. }
  51. }
  52. else
  53. {
  54. #only name, old version
  55. if (preg_match_all('/<a href="\/name\/nm\d{1,8}\/">([^<]+)<\/a>/',$hit[0],$results, PREG_PATTERN_ORDER))
  56. {
  57. return $results[1];
  58. }
  59. else
  60. {
  61. return False;
  62. }
  63. }
  64. }
  65. else
  66. {
  67. return False;
  68. }
  69. }
  70.  
  71.  
  72. function getMovieDirectedBy($all_directors=False)
  73. {
  74. if ($all_directors === True)
  75. {
  76. return False;
  77. }
  78. else
  79. {
  80. if (preg_match('/Director:<\/h5>.?<a href="\/name\/[a-z0-9]+\/">(.+)<\/a>/sU', $this->imdbpage, $hit))
  81. {
  82. return $hit[1];
  83. }
  84. else
  85. {
  86. return False;
  87. }
  88. }
  89. }
  90.  
  91.  
  92. function getMovieColor()
  93. {
  94. if (preg_match('/<a href="\/List\?color-info=.+">(.+)<\/a>/', $this->imdbpage, $hit))
  95. {
  96. return $hit[1];
  97. }
  98. else
  99. {
  100. return False;
  101. }
  102. }
  103.  
  104.  
  105. function getMovieCountry()
  106. {
  107. if (preg_match_all('/<a href="\/Sections\/Countries\/([a-z]+)\/">/i',$this->imdbpage,$results, PREG_PATTERN_ORDER))
  108. {
  109. return $results[1];
  110. }
  111. else
  112. {
  113. return False;
  114. }
  115. }
  116.  
  117.  
  118. function getMovieLanguage()
  119. {
  120. if (preg_match_all('/<a href="\/Sections\/Languages\/([a-z]+)\/">/i',$this->imdbpage,$results, PREG_PATTERN_ORDER))
  121. {
  122. return $results[1];
  123. }
  124. else
  125. {
  126. return False;
  127. }
  128. }
  129.  
  130.  
  131. function getMovieRating()
  132. {
  133. if (preg_match('/<b>([0-9]{1,2}\.[0-9]{1,2}\/10)<\/b>/', $this->imdbpage, $hit))
  134. {
  135. return $hit[1];
  136. }
  137. else
  138. {
  139. return False;
  140. }
  141. }
  142.  
  143.  
  144. function getMovieGenres()
  145. {
  146. if (preg_match_all('/\/Sections\/Genres\/(.+?)\//', $this->imdbpage, $hit, PREG_PATTERN_ORDER))
  147. {
  148. return $hit[1];
  149. }
  150. else
  151. {
  152. return False;
  153. }
  154. }
  155.  
  156.  
  157. function getMoviePlot()
  158. {
  159. //sometimes "Plot Outline" or "Plot Summary"
  160. if (preg_match('/\/h5>([^<]*)\<a class="tn15more inline" href="\/rg\/title-tease\/plotsummary/', $this->imdbpage, $hit))
  161. {
  162. return $hit[1];
  163. }
  164. else
  165. {
  166. return False;
  167. }
  168. }
  169.  
  170.  
  171. function getMovieTagline()
  172. {
  173. if (preg_match('/h5>([^<]*)\<a class="tn15more inline" href="\/rg\/title-tease\/taglines/', $this->imdbpage, $hit))
  174. {
  175. return $hit[1];
  176. }
  177. else
  178. {
  179. return False;
  180. }
  181. }
  182.  
  183.  
  184. function getMovieTitle()
  185. {
  186. if (preg_match('/\<title\>([^"]*)\<\/title\>/', $this->imdbpage, $hit))
  187. {
  188. return $hit[1];
  189. }
  190. else
  191. {
  192. return False;
  193. }
  194. }
  195.  
  196.  
  197. function getMoviePictureHtml()
  198. {
  199. if (preg_match('/<a name="poster".+title=".+">(.+)<\/a>/', $this->imdbpage, $hit))
  200. {
  201. return str_replace('ec.', '', $hit[1]);
  202. }
  203. else
  204. {
  205. return False;
  206. }
  207. }
  208.  
  209.  
  210. function getMoviePicture()
  211. {
  212. if (preg_match('/ src="([^"]*)/', $this->getMoviePictureHtml($this->imdbpage), $hit))
  213. {
  214. return $hit[1];
  215. }
  216. else
  217. {
  218. return False;
  219. }
  220. }
  221.  
  222.  
  223. function getMovieYear()
  224. {
  225. if (preg_match('/\/Sections\/Years\/([^"]*)/', $this->imdbpage, $hit))
  226. {
  227. return $hit[1];
  228. }
  229. else
  230. {
  231. return False;
  232. }
  233. }
  234.  
  235.  
  236. function getMovieRuntime()
  237. {
  238. #contributed by Guvenc KAPLAN
  239. if (preg_match('/Runtime:<\/h5>([^<]+)<\/div>/', $this->imdbpage, $hit))
  240. {
  241. return $hit[1];
  242. }
  243. else
  244. {
  245. return False;
  246. }
  247. }
  248.  
  249.  
  250. function getMovieStars()
  251. {
  252. if (preg_match('/<b>([0-9]{1,2}\.[0-9]{1,2})\/10<\/b>/', $this->imdbpage, $hit))
  253. {
  254. return $hit[1];
  255. }
  256. else
  257. {
  258. return False;
  259. }
  260. }
  261.  
  262.  
  263. function getMovieAka()
  264. {
  265. if (preg_match('/Also Known As:<\/h5>(.+)<br>/', $this->imdbpage, $hit))
  266. {
  267. return $hit[1];
  268. }
  269. else
  270. {
  271. return False;
  272. }
  273. }
  274. }

Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd

 Reacties
Post een reactie
Lees de reacties  ( 3 )
© 2002-2012 Sitemasters.be - Regels - Gehost door: Vircon - Laadtijd: 0.216s