1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-13 03:54:04 +02:00

Merge pull request #115 from nel50n/media-rss

Media RSS
This commit is contained in:
Mitsu
2015-04-24 17:32:02 +02:00
6 changed files with 443 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
/**
* HDWallpapersBridge
* Returns the latests wallpapers from http://www.hdwallpapers.in
*
* @name HD Wallpapers Bridge
* @homepage http://www.hdwallpapers.in/
* @description Returns the latests wallpapers from HDWallpapers
* @maintainer nel50n
* @update 2015-04-08
* @use1(c="category",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
*/
class HDWallpapersBridge extends BridgeAbstract {
private $category;
private $resolution;
public function collectData(array $param){
$html = '';
$baseUri = 'http://www.hdwallpapers.in';
$this->category = $param['c'] ?: 'latest_wallpapers'; // Latest default
$this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
$category = $this->category;
if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) {
$category .= '-desktop-wallpapers';
}
$num = 0;
$max = $param['m'] ?: 14;
$lastpage = 1;
for ($page = 1; $page <= $lastpage; $page++) {
$link = $baseUri.'/'.$category.'/page/'.$page;
$html = file_get_html($link) or $this->returnError('No results for this query.', 404);
if ($page === 1) {
preg_match('/page\/(\d+)$/', $html->find('.pagination a', -2)->href, $matches);
$lastpage = min($matches[1], ceil($max/14));
}
foreach($html->find('.wallpapers .wall a') as $element) {
$thumbnail = $element->find('img', 0);
$item = new \Item();
// http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg
$item->uri = $baseUri.'/download'.str_replace('wallpapers.html', $this->resolution.'.jpg', $element->href);
$item->timestamp = time();
$item->title = $element->find('p', 0)->text();
$item->thumbnailUri = $baseUri.$thumbnail->src;
$item->content = $item->title.'<br><a href="'.$item->uri.'"><img src="'.$item->thumbnailUri.'" /></a>';
$this->items[] = $item;
$num++;
if ($num >= $max)
break 2;
}
}
}
public function getName(){
return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->category).' ['.$this->resolution.']';
}
public function getURI(){
return 'http://www.hdwallpapers.in';
}
public function getCacheDuration(){
return 43200; // 12 hours
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* PickyWallpapersBridge
* Returns the latests wallpapers from http://www.pickywallpapers.com
*
* @name PickyWallpapers Bridge
* @homepage http://www.pickywallpapers.com/
* @description Returns the latests wallpapers from PickyWallpapers
* @maintainer nel50n
* @update 2014-03-31
* @use1(c="category",s="subcategory",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
*/
class PickyWallpapersBridge extends BridgeAbstract {
private $category;
private $subcategory;
private $resolution;
public function collectData(array $param){
$html = '';
if (!isset($param['c'])) {
$this->returnError('You must specify at least a category (?c=...).', 400);
} else {
$baseUri = 'http://www.pickywallpapers.com';
$this->category = $param['c'];
$this->subcategory = $param['s'] ?: '';
$this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
$num = 0;
$max = $param['m'] ?: 12;
$lastpage = 1;
for ($page = 1; $page <= $lastpage; $page++) {
$link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/';
$html = file_get_html($link) or $this->returnError('No results for this query.', 404);
if ($page === 1) {
preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
$lastpage = min($matches[1], ceil($max/12));
}
foreach($html->find('.items li img') as $element) {
$item = new \Item();
$item->uri = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src);
$item->timestamp = time();
$item->title = $element->alt;
$item->thumbnailUri = $element->src;
$item->content = $item->title.'<br><a href="'.$item->uri.'">'.$element.'</a>';
$this->items[] = $item;
$num++;
if ($num >= $max)
break 2;
}
}
}
}
public function getName(){
return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
}
public function getURI(){
return 'http://www.pickywallpapers.com';
}
public function getCacheDuration(){
return 43200; // 12 hours
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* SuperbWallpapersBridge
* Returns the latests wallpapers from http://www.superbwallpapers.com
*
* @name Superb Wallpapers Bridge
* @homepage http://www.superbwallpapers.com/
* @description Returns the latests wallpapers from SuperbWallpapers
* @maintainer nel50n
* @update 2015-04-08
* @use1(c="category",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
*/
class SuperbWallpapersBridge extends BridgeAbstract {
private $category;
private $resolution;
public function collectData(array $param){
$html = '';
$baseUri = 'http://www.superbwallpapers.com';
$this->category = $param['c'] ?: ''; // All default
$this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
$num = 0;
$max = $param['m'] ?: 36;
$lastpage = 1;
// Get last page number
$link = $baseUri.'/'.$this->category.'/9999.html';
$html = file_get_html($link);
$lastpage = min($html->find('.paging .cpage', 0)->innertext(), ceil($max/36));
for ($page = 1; $page <= $lastpage; $page++) {
$link = $baseUri.'/'.$this->category.'/'.$page.'.html';
$html = file_get_html($link) or $this->returnError('No results for this query.', 404);
foreach($html->find('.wpl .i a') as $element) {
$thumbnail = $element->find('img', 0);
$item = new \Item();
$item->uri = str_replace('200x125', $this->resolution, $thumbnail->src);
$item->timestamp = time();
$item->title = $element->title;
$item->thumbnailUri = $thumbnail->src;
$item->content = $item->title.'<br><a href="'.$item->uri.'">'.$thumbnail.'</a>';
$this->items[] = $item;
$num++;
if ($num >= $max)
break 2;
}
}
}
public function getName(){
return 'HDWallpapers - '.$this->category.' ['.$this->resolution.']';
}
public function getURI(){
return 'http://www.superbwallpapers.com';
}
public function getCacheDuration(){
return 43200; // 12 hours
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* UnsplashBridge
* Returns the latests photos from http://unsplash.com
*
* @name Unsplash Bridge
* @homepage http://unsplash.com/
* @description Returns the latests photos from Unsplash
* @maintainer nel50n
* @update 2015-03-02
* @use1(m="max number of photos",w="width (1920, 1680, ...)",q="jpeg quality (0..100)")
*/
class UnsplashBridge extends BridgeAbstract {
public function collectData(array $param){
$html = '';
$baseUri = 'http://unsplash.com';
$width = $param['w'] ?: '1920'; // Default width
$num = 0;
$max = $param['m'] ?: 20;
$quality = $param['q'] ?: 75;
$lastpage = 1;
for ($page = 1; $page <= $lastpage; $page++) {
$link = $baseUri.'/grid?page='.$page;
$html = file_get_html($link) or $this->returnError('No results for this query.', 404);
if ($page === 1) {
preg_match('/=(\d+)$/', $html->find('.pagination > a[!class]', -1)->href, $matches);
$lastpage = min($matches[1], ceil($max/40));
}
foreach($html->find('.photo') as $element) {
$thumbnail = $element->find('img', 0);
$thumbnail->src = str_replace('https://', 'http://', $thumbnail->src);
$item = new \Item();
$item->uri = str_replace(array('q=75', 'w=400'),
array("q=$quality", "w=$width"),
$thumbnail->src).'.jpg'; // '.jpg' only for format hint
$item->timestamp = time();
$item->title = $thumbnail->alt;
$item->thumbnailUri = $thumbnail->src;
$item->content = $item->title.'<br><a href="'.$item->uri.'"><img src="'.$item->thumbnailUri.'" /></a>';
$this->items[] = $item;
$num++;
if ($num >= $max)
break 2;
}
}
}
public function getName(){
return 'Unsplash';
}
public function getURI(){
return 'http://unsplash.com';
}
public function getCacheDuration(){
return 43200; // 12 hours
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* WallpaperStopBridge
* Returns the latests wallpapers from http://www.wallpaperstop.com
*
* @name WallpaperStop Bridge
* @homepage http://www.wallpaperstop.com/
* @description Returns the latests wallpapers from WallpaperStop
* @maintainer nel50n
* @update 2014-11-05
* @use1(c="category",s="subcategory",m="max number of wallpapers",r="resolution (1920x1200, 1680x1050, ...)")
*/
class WallpaperStopBridge extends BridgeAbstract {
private $category;
private $subcategory;
private $resolution;
public function collectData(array $param){
$html = '';
if (!isset($param['c'])) {
$this->returnError('You must specify at least a category (?c=...).', 400);
} else {
$baseUri = 'http://www.wallpaperstop.com';
$this->category = $param['c'];
$this->subcategory = $param['s'] ?: '';
$this->resolution = $param['r'] ?: '1920x1200'; // Wide wallpaper default
$num = 0;
$max = $param['m'] ?: 20;
$lastpage = 1;
for ($page = 1; $page <= $lastpage; $page++) {
$link = $baseUri.'/'.$this->category.'-wallpaper/'.(!empty($this->subcategory)?$this->subcategory.'-wallpaper/':'').'desktop-wallpaper-'.$page.'.html';
$html = file_get_html($link) or $this->returnError('No results for this query.', 404);
if ($page === 1) {
preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches);
$lastpage = min($matches[1], ceil($max/20));
}
foreach($html->find('article.item') as $element) {
$wplink = $element->getAttribute('data-permalink');
if (preg_match('%^http://www\.wallpaperstop\.com/(.+)/([^/]+)-(\d+)\.html$%', $wplink, $matches)) {
$thumbnail = $element->find('img', 0);
$item = new \Item();
$item->uri = $baseUri.'/wallpapers/'.str_replace('wallpaper', 'wallpapers', $matches[1]).'/'.$matches[2].'-'.$this->resolution.'-'.$matches[3].'.jpg';
$item->id = $matches[3];
$item->timestamp = time();
$item->title = $thumbnail->title;
$item->thumbnailUri = $baseUri.$thumbnail->src;
$item->content = $item->title.'<br><a href="'.$wplink.'"><img src="'.$item->thumbnailUri.'" /></a>';
$this->items[] = $item;
$num++;
if ($num >= $max)
break 2;
}
}
}
}
}
public function getName(){
return 'WallpaperStop - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
}
public function getURI(){
return 'http://www.wallpaperstop.com';
}
public function getCacheDuration(){
return 43200; // 12 hours
}
}