DailymotionBridge.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. class DailymotionBridge extends BridgeAbstract{
  3. private $request;
  4. public function loadMetadatas() {
  5. $this->maintainer = "mitsukarenai";
  6. $this->name = "Dailymotion Bridge";
  7. $this->uri = "https://www.dailymotion.com/";
  8. $this->description = "Returns the 5 newest videos by username/playlist or search";
  9. $this->update = "2016-08-02";
  10. $this->parameters["By username"] =
  11. '[
  12. {
  13. "name" : "username",
  14. "identifier" : "u"
  15. }
  16. ]';
  17. $this->parameters["By playlist id"] =
  18. '[
  19. {
  20. "name" : "playlist id",
  21. "identifier" : "p",
  22. "type" : "text"
  23. }
  24. ]';
  25. $this->parameters["From search results"] =
  26. '[
  27. {
  28. "name" : "Search keyword",
  29. "identifier" : "s"
  30. },
  31. {
  32. "name" : "Page",
  33. "identifier" : "pa",
  34. "type" : "number"
  35. }
  36. ]';
  37. }
  38. public function collectData(array $param){
  39. function getMetadata($id) {
  40. $metadata=array();
  41. $html2 = file_get_html('http://www.dailymotion.com/video/'.$id) or $this->returnError('Could not request Dailymotion.', 404);
  42. $metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
  43. $metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') );
  44. $metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
  45. $metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
  46. return $metadata;
  47. }
  48. $html = '';
  49. $limit = 5;
  50. $count = 0;
  51. if (isset($param['u'])) { // user timeline mode
  52. $this->request = $param['u'];
  53. $html = $this->file_get_html('http://www.dailymotion.com/user/'.urlencode($this->request).'/1') or $this->returnError('Could not request Dailymotion.', 404);
  54. }
  55. else if (isset($param['p'])) { // playlist mode
  56. $this->request = strtok($param['p'], '_');
  57. $html = $this->file_get_html('http://www.dailymotion.com/playlist/'.urlencode($this->request).'') or $this->returnError('Could not request Dailymotion.', 404);
  58. }
  59. else if (isset($param['s'])) { // search mode
  60. $this->request = $param['s']; $page = 1; if (isset($param['pa'])) $page = (int)preg_replace("/[^0-9]/",'', $param['pa']);
  61. $html = $this->file_get_html('http://www.dailymotion.com/search/'.urlencode($this->request).'/'.$page.'') or $this->returnError('Could not request Dailymotion.', 404);
  62. }
  63. else {
  64. $this->returnError('You must either specify a Dailymotion username (?u=...) or a playlist id (?p=...) or search (?s=...)', 400);
  65. }
  66. foreach($html->find('div.media a.preview_link') as $element) {
  67. if($count < $limit) {
  68. $item = new \Item();
  69. $item->id = str_replace('/video/', '', strtok($element->href, '_'));
  70. $metadata = getMetadata($item->id);
  71. $item->uri = $metadata['uri'];
  72. $item->thumbnailUri = $metadata['thumbnailUri'];
  73. $item->title = $metadata['title'];
  74. $item->timestamp = $metadata['timestamp'];
  75. $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br><a href="' . $item->uri . '">' . $item->title . '</a>';
  76. $this->items[] = $item;
  77. $count++;
  78. }
  79. }
  80. }
  81. public function getName(){
  82. return (!empty($this->request) ? $this->request .' - ' : '') .'Dailymotion Bridge';
  83. }
  84. public function getURI(){
  85. return 'https://www.dailymotion.com/';
  86. }
  87. public function getCacheDuration(){
  88. return 3600*3; // 3 hours
  89. }
  90. }