Skip to content

Commit

Permalink
[ShanaprojectBridge] Add filter options
Browse files Browse the repository at this point in the history
- Filter by minimum number of episodes
- Filter by minimum number of total episodes
- Filter by banner image
  • Loading branch information
logmanoriginal committed Jul 3, 2019
1 parent 2ea8d73 commit c0edf6e
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions bridges/ShanaprojectBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ class ShanaprojectBridge extends BridgeAbstract {
const NAME = 'Shanaproject Bridge';
const URI = 'https://www.shanaproject.com';
const DESCRIPTION = 'Returns a list of anime from the current Season Anime List';
const PARAMETERS = array(
array(
'min_episodes' => array(
'name' => 'Minimum Episodes',
'type' => 'number',
'title' => 'Minimum number of episodes before including in feed',
'defaultValue' => 0,
),
'min_total_episodes' => array(
'name' => 'Minimum Total Episodes',
'type' => 'number',
'title' => 'Minimum total number of episodes before including in feed',
'defaultValue' => 0,
),
'require_banner' => array(
'name' => 'Require Banner',
'type' => 'checkbox',
'title' => 'Only include anime with custom banner image',
'defaultValue' => false,
),
),
);

private $uri;

Expand All @@ -17,14 +39,41 @@ public function collectData(){
$animes = $html->find('div.header_display_box_info')
or returnServerError('Could not find anime headers!');

$min_episodes = $this->getInput('min_episodes') ?: 0;
$min_total_episodes = $this->getInput('min_total_episodes') ?: 0;

foreach($animes as $anime) {

list(
$episodes_released,
/* of */,
$episodes_total
) = explode(' ', $this->extractAnimeEpisodeInformation($anime));

// Skip if not enough episodes yet
if ($episodes_released < $min_episodes) {
continue;
}

// Skip if too many episodes in total
if ($episodes_total !== '?' && $episodes_total < $min_total_episodes) {
continue;
}

// Skip if https://static.shanaproject.com/no-art.jpg
if ($this->getInput('require_banner')
&& strpos($this->extractAnimeBackgroundImage($anime), 'no-art') !== false) {
continue;
}

$this->items[] = array(
'title' => $this->extractAnimeTitle($anime),
'author' => $this->extractAnimeTitle($anime),
'author' => $this->extractAnimeAuthor($anime),
'uri' => $this->extractAnimeUri($anime),
'timestamp' => $this->extractAnimeTimestamp($anime),
'content' => $this->buildAnimeContent($anime),
);

}
}

Expand Down Expand Up @@ -94,7 +143,11 @@ private function extractAnimeAuthor($anime){
private function extractAnimeEpisodeInformation($anime){
$episode = $anime->find('div.header_info_episode', 0)
or returnServerError('Could not find anime episode information!');
return preg_replace('/\r|\n/', ' ', $episode->plaintext);

$retVal = preg_replace('/\r|\n/', ' ', $episode->plaintext);
$retVal = preg_replace('/\s+/', ' ', $retVal);

return $retVal;
}

// Extracts the background image
Expand Down

0 comments on commit c0edf6e

Please sign in to comment.