AllocineFRBridge.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class AllocineFRBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "superbaillot.net";
  5. $this->name = "Allo Cine Bridge";
  6. $this->uri = "http://www.allocine.fr";
  7. $this->description = "Bridge for allocine.fr";
  8. $this->parameters[] = array(
  9. 'category'=>array(
  10. 'name'=>'category',
  11. 'type'=>'list',
  12. 'required'=>true,
  13. 'exampleValue'=>'Faux Raccord',
  14. 'title'=>'Select your category',
  15. 'values'=>array(
  16. 'Faux Raccord'=>'faux-raccord',
  17. 'Top 5'=>'top-5',
  18. 'Tueurs En Serie'=>'tuers-en-serie'
  19. )
  20. )
  21. );
  22. }
  23. public function collectData(array $params){
  24. // Check all parameters
  25. if(!isset($params['category']))
  26. $this->returnClientError('You must specify a valid category (&category= )!');
  27. $category = '';
  28. switch($params['category']){
  29. case 'faux-raccord':
  30. $this->uri = 'http://www.allocine.fr/video/programme-12284/saison-24580/';
  31. $category = 'Faux Raccord';
  32. break;
  33. case 'top-5':
  34. $this->uri = 'http://www.allocine.fr/video/programme-12299/saison-22542/';
  35. $category = 'Top 5';
  36. break;
  37. case 'tuers-en-serie':
  38. $this->uri = 'http://www.allocine.fr/video/programme-12286/saison-22938/';
  39. $category = 'Tueurs en Séries';
  40. break;
  41. default:
  42. $this->returnClientError('You must select a valid category!');
  43. }
  44. // Update bridge name to match selection
  45. $this->name .= ' : ' . $category;
  46. $html = $this->getSimpleHTMLDOM($this->uri) or $this->returnServerError("Could not request {$this->uri}!");
  47. foreach($html->find('figure.media-meta-fig') as $element)
  48. {
  49. $item = array();
  50. $title = $element->find('div.titlebar h3.title a', 0);
  51. $content = trim($element->innertext);
  52. $figCaption = strpos($content, $category);
  53. if($figCaption !== false)
  54. {
  55. $content = str_replace('src="/', 'src="http://www.allocine.fr/', $content);
  56. $content = str_replace('href="/', 'href="http://www.allocine.fr/', $content);
  57. $content = str_replace('src=\'/', 'src=\'http://www.allocine.fr/', $content);
  58. $content = str_replace('href=\'/', 'href=\'http://www.allocine.fr/', $content);
  59. $item['content'] = $content;
  60. $item['title'] = trim($title->innertext);
  61. $item['uri'] = "http://www.allocine.fr" . $title->href;
  62. $this->items[] = $item;
  63. }
  64. }
  65. }
  66. public function getCacheDuration(){
  67. return 25200; // 7 hours
  68. }
  69. }