Animarr/src/Animarr/Release/MultiRelease.php

90 lines
2.5 KiB
PHP
Executable file

<?php
namespace Animarr\Release;
use Animarr\Extractor\SceneExtractor;
use Animarr\Torrent\Torrent;
use Animarr\Database;
class MultiRelease extends Release{
public function __construct($originalTitle, $title, $group, $type, array $tags, $number = -1){
parent::__construct($originalTitle, $title, $group, $type, $tags, $number);
}
/**
* @return Release[]
*/
public function getContents(SceneExtractor $extractor = null){
if($this->content !== null){
return $this->content;
}
$this->content = [];
$extractor = $extractor === null ? new SceneExtractor() : $extractor;
$torrent = Torrent::fromURL($this->getDownloadLink(), Database::getConfigKey("torrent.cache.folder", null));
if($torrent === null and strpos($this->getDownloadLink(), "urn:btih:") !== false){
//Support magnets?
return $this->content;
}
foreach ($torrent->getFiles() as $file){
if(count($file["path"]) > 2){ //In subfolder, let's ignore for now
continue;
}
$baseName = $file["path"][count($file["path"]) - 1];
$release = $extractor->extractInformation($baseName);
if($release === null or $release->getType() !== Release::TYPE_SINGLE){
continue;
}
$release->setInfoLink($this->getInfoLink());
$release->setDownloadLink($this->getDownloadLink());
$release->setUploadDate($this->getUploadDate());
$release->setTrusted($this->isTrusted());
$release->setBest($this->isBest());
$release->setSeeds($this->getSeeds());
$release->setSize($this->getSize());
$release->setParent($this);
if($release->getSource() === Release::SOURCE_UNKNOWN){
$release->setSource($this->getSource());
}
if($release->getQuality() === Release::QUALITY_UNKNOWN){
$release->setQuality($this->getQuality());
}
if($release->getVideoCodec() === Release::VIDEO_CODEC_UNKNOWN){
$release->setVideoCodec($this->getVideoCodec());
}
if($release->getAudioCodec() === Release::AUDIO_CODEC_UNKNOWN){
$release->setAudioCodec($this->getAudioCodec());
}
$release->setProperties($this->getProperties());
if($this->filter !== null){
$release = $this->filter->applyFilterSingle($release);
}
if($release === null){
continue;
}
$this->content[] = $release;
}
ksort($this->content);
return $this->content;
}
}