DailymotionBridge.php 3.7 KB

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