AllocineFRBridge.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class AllocineFRBridge extends BridgeAbstract {
  3. const MAINTAINER = 'superbaillot.net';
  4. const NAME = 'Allo Cine Bridge';
  5. const CACHE_TIMEOUT = 25200; // 7h
  6. const URI = 'http://www.allocine.fr/';
  7. const DESCRIPTION = 'Bridge for allocine.fr';
  8. const PARAMETERS = array( 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 Séries' => 'tueurs-en-serie'
  19. )
  20. )
  21. ));
  22. public function getURI(){
  23. if(!is_null($this->getInput('category'))) {
  24. switch($this->getInput('category')) {
  25. case 'faux-raccord':
  26. $uri = static::URI . 'video/programme-12284/saison-32180/';
  27. break;
  28. case 'top-5':
  29. $uri = static::URI . 'video/programme-12299/saison-29561/';
  30. break;
  31. case 'tueurs-en-serie':
  32. $uri = static::URI . 'video/programme-12286/saison-22938/';
  33. break;
  34. }
  35. return $uri;
  36. }
  37. return parent::getURI();
  38. }
  39. public function getName(){
  40. if(!is_null($this->getInput('category'))) {
  41. return self::NAME . ' : '
  42. .array_search(
  43. $this->getInput('category'),
  44. self::PARAMETERS[$this->queriedContext]['category']['values']
  45. );
  46. }
  47. return parent::getName();
  48. }
  49. public function collectData(){
  50. $html = getSimpleHTMLDOM($this->getURI())
  51. or returnServerError('Could not request ' . $this->getURI() . ' !');
  52. $category = array_search(
  53. $this->getInput('category'),
  54. self::PARAMETERS[$this->queriedContext]['category']['values']
  55. );
  56. foreach($html->find('.media-meta-list figure.media-meta-fig') as $element) {
  57. $item = array();
  58. $title = $element->find('div.titlebar h3.title a', 0);
  59. $content = trim($element->innertext);
  60. $figCaption = strpos($content, $category);
  61. if($figCaption !== false) {
  62. $content = str_replace('src="/', 'src="' . static::URI, $content);
  63. $content = str_replace('href="/', 'href="' . static::URI, $content);
  64. $content = str_replace('src=\'/', 'src=\'' . static::URI, $content);
  65. $content = str_replace('href=\'/', 'href=\'' . static::URI, $content);
  66. $item['content'] = $content;
  67. $item['title'] = trim($title->innertext);
  68. $item['uri'] = static::URI . $title->href;
  69. $this->items[] = $item;
  70. }
  71. }
  72. }
  73. }