Skip to content

Commit

Permalink
[bridges] Shimmie v2 based imageboards derive from DanbooruBridge
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Mazière <[email protected]>
  • Loading branch information
Pierre Mazière committed Sep 3, 2016
1 parent fd6bcbb commit e7f2bf1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 95 deletions.
36 changes: 3 additions & 33 deletions bridges/DollbooruBridge.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
<?php
class DollbooruBridge extends BridgeAbstract{
require_once('Shimmie2Bridge.php');

class DollbooruBridge extends Shimmie2Bridge{

const MAINTAINER = "mitsukarenai";
const NAME = "Dollbooru";
const URI = "http://dollbooru.org/";
const DESCRIPTION = "Returns images from given page";


const PARAMETERS = array( array(
'p'=>array(
'name'=>'page',
'type'=>'number'
),
't'=>array('name'=>'tags')
));

public function collectData(){
$page=$this->getInput('p');
$tags = urlencode($this->getInput('t'));
$html = $this->getSimpleHTMLDOM(self::URI."post/list/$tags/$page")
or $this->returnServerError('Could not request Dollbooru.');


foreach($html->find('div[class=shm-image-list] a') as $element) {
$item = array();
$item['uri'] = self::URI.$element->href;
$item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('data-post-id'));
$item['timestamp'] = time();
$thumbnailUri = self::URI.$element->find('img', 0)->src;
$item['tags'] = $element->getAttribute('data-tags');
$item['title'] = 'Dollbooru | '.$item['postid'];
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
$this->items[] = $item;
}
}

public function getCacheDuration(){
return 1800; // 30 minutes
}
}
32 changes: 2 additions & 30 deletions bridges/MilbooruBridge.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
<?php
class MilbooruBridge extends BridgeAbstract{
require_once('Shimmie2Bridge.php');

class MilbooruBridge extends Shimmie2Bridge{

const MAINTAINER = "mitsukarenai";
const NAME = "Milbooru";
const URI = "http://sheslostcontrol.net/moe/shimmie/";
const DESCRIPTION = "Returns images from given page";

const PARAMETERS = array( array(
'p'=>array(
'name'=>'page',
'type'=>'number'
),
't'=>array('name'=>'tags')
));

public function collectData(){
$html = $this->getSimpleHTMLDOM(
self::URI.'?q=/post/list/'.urlencode($this->getInput('t')).'/'.$this->getInput('p')
)or $this->returnServerError('Could not request Milbooru.');

foreach($html->find('div[class=shm-image-list] span[class=thumb]') as $element) {
$item = array();
$item['uri'] = self::URI.$element->find('a', 0)->href;
$item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->find('a', 0)->getAttribute('data-post-id'));
$item['timestamp'] = time();
$thumbnailUri = self::URI.$element->find('img', 0)->src;
$item['tags'] = $element->find('a', 0)->getAttribute('data-tags');
$item['title'] = 'Milbooru | '.$item['postid'];
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
$this->items[] = $item;
}
}

public function getCacheDuration(){
return 1800; // 30 minutes
}
}
35 changes: 3 additions & 32 deletions bridges/Rule34pahealBridge.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
<?php
class Rule34pahealBridge extends BridgeAbstract{
require_once('Shimmie2Bridge.php');

class Rule34pahealBridge extends Shimmie2Bridge{

const MAINTAINER = "mitsukarenai";
const NAME = "Rule34paheal";
const URI = "http://rule34.paheal.net/";
const DESCRIPTION = "Returns images from given page";

const PARAMETERS = array( array(
'p'=>array(
'name'=>'page',
'type'=>'number'
),
't'=>array('name'=>'tags')
));


public function collectData(){
$html = $this->getSimpleHTMLDOM(self::URI.'post/list/'.$tags.'/'.$page)
or $this->returnServerError('Could not request Rule34paheal.');


foreach($html->find('div[class=shm-image-list] div[class=shm-thumb]') as $element) {
$item = array();
$item['uri'] = self::URI.$element->find('a', 0)->href;
$item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->find('img', 0)->getAttribute('id'));
$item['timestamp'] = time();
$thumbnailUri = $element->find('img', 0)->src;
$item['tags'] = $element->getAttribute('data-tags');
$item['title'] = 'Rule34paheal | '.$item['postid'];
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
$this->items[] = $item;
}
}

public function getCacheDuration(){
return 1800; // 30 minutes
}
}
31 changes: 31 additions & 0 deletions bridges/Shimmie2Bridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
require_once('DanbooruBridge.php');

class Shimmie2Bridge extends DanbooruBridge{

const NAME = "Shimmie v2";
const URI = "http://shimmie.shishnet.org/v2/";
const DESCRIPTION = "Returns images from given page";

const PATHTODATA='.shm-thumb-link';
const IDATTRIBUTE='data-post-id';

protected function getFullURI(){
return $this->getURI().'post/list/'
.$this->getInput('t').'/'
.$this->getInput('p');
}

protected function getItemFromElement($element){
$item = array();
$item['uri'] = $this->getURI().$element->href;
$item['id'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute(static::IDATTRIBUTE));
$item['timestamp'] = time();
$thumbnailUri = $this->getURI().$element->find('img', 0)->src;
$item['tags'] = $element->getAttribute('data-tags');
$item['title'] = $this->getName().' | '.$item['id'];
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a><br>Tags: '.$item['tags'];
return $item;
}

}

0 comments on commit e7f2bf1

Please sign in to comment.