DailymotionBridge.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. class DailymotionBridge extends BridgeAbstract{
  3. const MAINTAINER = "mitsukarenai";
  4. const NAME = "Dailymotion Bridge";
  5. const URI = "https://www.dailymotion.com/";
  6. const CACHE_TIMEOUT = 10800; // 3h
  7. const DESCRIPTION = "Returns the 5 newest videos by username/playlist or search";
  8. const PARAMETERS = array (
  9. 'By username' => array(
  10. 'u'=>array(
  11. 'name'=>'username',
  12. 'required'=>true
  13. )
  14. ),
  15. 'By playlist id' => array(
  16. 'p'=>array(
  17. 'name'=>'playlist id',
  18. 'required'=>true
  19. )
  20. ),
  21. 'From search results' => array(
  22. 's'=>array(
  23. 'name'=>'Search keyword',
  24. 'required'=>true
  25. ),
  26. 'pa'=>array(
  27. 'name'=>'Page',
  28. 'type'=>'number'
  29. )
  30. )
  31. );
  32. function getMetadata($id) {
  33. $metadata=array();
  34. $html2 = getSimpleHTMLDOM(self::URI.'video/'.$id);
  35. if(!$html2){
  36. return $metadata;
  37. }
  38. $metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
  39. $metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') );
  40. $metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
  41. $metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
  42. return $metadata;
  43. }
  44. public function collectData(){
  45. $html = '';
  46. $limit = 5;
  47. $count = 0;
  48. $html = getSimpleHTMLDOM($this->getURI())
  49. or returnServerError('Could not request Dailymotion.');
  50. foreach($html->find('div.media a.preview_link') as $element) {
  51. if($count < $limit) {
  52. $item = array();
  53. $item['id'] = str_replace('/video/', '', strtok($element->href, '_'));
  54. $metadata = $this->getMetadata($item['id']);
  55. if(empty($metadata)){
  56. continue;
  57. }
  58. $item['uri'] = $metadata['uri'];
  59. $item['title'] = $metadata['title'];
  60. $item['timestamp'] = $metadata['timestamp'];
  61. $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $metadata['thumbnailUri'] . '" /></a><br><a href="' . $item['uri'] . '">' . $item['title'] . '</a>';
  62. $this->items[] = $item;
  63. $count++;
  64. }
  65. }
  66. }
  67. public function getName(){
  68. switch($this->queriedContext){
  69. case 'By username':
  70. $specific=$this->getInput('u');
  71. break;
  72. case 'By playlist id':
  73. $specific=strtok($this->getInput('p'), '_');
  74. break;
  75. case 'From search results':
  76. $specific=$this->getInput('s');
  77. break;
  78. }
  79. return $specific.' : Dailymotion Bridge';
  80. }
  81. public function getURI(){
  82. $uri=self::URI;
  83. switch($this->queriedContext){
  84. case 'By username':
  85. $uri.='user/'
  86. .urlencode($this->getInput('u')).'/1';
  87. break;
  88. case 'By playlist id':
  89. $uri.='playlist/'
  90. .urlencode(strtok($this->getInput('p'), '_'));
  91. break;
  92. case 'From search results':
  93. $uri.='search/'
  94. .urlencode($this->getInput('s'));
  95. if($this->getInput('pa')){
  96. $uri.='/'.$this->getInput('pa');
  97. }
  98. break;
  99. }
  100. return $uri;
  101. }
  102. }