HDWallpapersBridge.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. class HDWallpapersBridge extends BridgeAbstract {
  3. private $category;
  4. private $resolution;
  5. public function loadMetadatas() {
  6. $this->maintainer = "nel50n";
  7. $this->name = "HD Wallpapers Bridge";
  8. $this->uri = "http://www.hdwallpapers.in/";
  9. $this->description = "Returns the latests wallpapers from HDWallpapers";
  10. $this->update = "2015-04-08";
  11. $this->parameters[] =
  12. '[
  13. {
  14. "name" : "category",
  15. "identifier" : "c"
  16. },
  17. {
  18. "name" : "max number of wallpapers",
  19. "identifier" : "m"
  20. },
  21. {
  22. "name" : "resolution",
  23. "identifier" : "r",
  24. "exampleValue" : "1920x1200, 1680x1050, ..."
  25. }
  26. ]';
  27. }
  28. public function collectData(array $param){
  29. $html = '';
  30. $baseUri = 'http://www.hdwallpapers.in';
  31. $this->category = $param['c'] ?: 'latest_wallpapers'; // Latest default
  32. $this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
  33. $category = $this->category;
  34. if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) {
  35. $category .= '-desktop-wallpapers';
  36. }
  37. $num = 0;
  38. $max = $param['m'] ?: 14;
  39. $lastpage = 1;
  40. for ($page = 1; $page <= $lastpage; $page++) {
  41. $link = $baseUri.'/'.$category.'/page/'.$page;
  42. $html = $this->file_get_html($link) or $this->returnError('No results for this query.', 404);
  43. if ($page === 1) {
  44. preg_match('/page\/(\d+)$/', $html->find('.pagination a', -2)->href, $matches);
  45. $lastpage = min($matches[1], ceil($max/14));
  46. }
  47. foreach($html->find('.wallpapers .wall a') as $element) {
  48. $thumbnail = $element->find('img', 0);
  49. $item = new \Item();
  50. // http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg
  51. $item->uri = $baseUri.'/download'.str_replace('wallpapers.html', $this->resolution.'.jpg', $element->href);
  52. $item->timestamp = time();
  53. $item->title = $element->find('p', 0)->text();
  54. $item->thumbnailUri = $baseUri.$thumbnail->src;
  55. $item->content = $item->title.'<br><a href="'.$item->uri.'"><img src="'.$item->thumbnailUri.'" /></a>';
  56. $this->items[] = $item;
  57. $num++;
  58. if ($num >= $max)
  59. break 2;
  60. }
  61. }
  62. }
  63. public function getName(){
  64. return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->category).' ['.$this->resolution.']';
  65. }
  66. public function getURI(){
  67. return 'http://www.hdwallpapers.in';
  68. }
  69. public function getCacheDuration(){
  70. return 43200; // 12 hours
  71. }
  72. }