Animarr/src/Animarr/Extractor/AnimeBytesExtractor.php

76 lines
1.8 KiB
PHP

<?php
namespace Animarr\Extractor;
use Animarr\AniDB;
use Animarr\Database;
use Animarr\Release\MultiRelease;
use Animarr\Release\Release;
class AnimeBytesExtractor implements Extractor{
private $db;
public function __construct(AniDB $aniDB = null){
$this->db = $aniDB;
}
private function tryMatch($title){
if($this->db === null){
return true;
}
return $this->db->matchTitle((string) $title) !== null;
}
//
public function extractInformation($releaseTitle, $forceType = null){
if(!is_array($forceType)){
$forceType = [];
}
parse_str($releaseTitle, $info);
$tags = array_map("trim", explode("|", $info["info"]));
$releaseTitle = $info["title"];
if($info["aid"] != ""){
$releaseTitle = $this->db->getAnime($info["aid"])["title"];
}
$group = "";
$newTags = [];
$allow = false;
foreach($tags as $t){
if(preg_match("#subs[ ]*\\((.+)\\)#u", $t, $matches) > 0){
$group = $matches[1];
}
foreach($forceType as $type){
if(stripos($t, $type) !== false){
$allow = true;
}
}
foreach(explode(" ", str_replace(["(", ")"], " ", $t)) as $t2){
$newTags[] = trim($t2);
}
}
if(!$allow or in_array(strtolower(explode(" ", $tags[1])[0]), Database::getConfigKey("filter.extension.ignore", []))){
return null;
}
if(isset($info["edition"]) and preg_match("/Episode ([0-9]+)$/", $info["edition"], $matches) > 0){
$episode = (int) $matches[1];
return new Release("[$group] $releaseTitle ".str_pad($episode, 2, "0", STR_PAD_LEFT) ." [".implode("][", $tags) . "]", $releaseTitle, $group, Release::TYPE_SINGLE, $newTags, $episode);
}else{
return new MultiRelease("[$group] $releaseTitle [".implode("][", $tags) . "]", $releaseTitle, $group, Release::TYPE_BATCH, $newTags);
}
}
}