mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-16 20:00:55 +00:00
fix: php notice in eztvbridge (#2998)
* fix: php notice in eztvbridge Fixes Undefined property: stdClass::$torrents * lint
This commit is contained in:
parent
b8f73618c1
commit
57d5aa45f7
@ -1,20 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
class EZTVBridge extends BridgeAbstract
|
class EZTVBridge extends BridgeAbstract
|
||||||
{
|
{
|
||||||
const MAINTAINER = 'alexAubin';
|
const MAINTAINER = 'alexAubin';
|
||||||
const NAME = 'EZTV';
|
const NAME = 'EZTV';
|
||||||
const URI = 'https://eztv.re/';
|
const URI = 'https://eztv.re/';
|
||||||
const DESCRIPTION = 'Returns list of torrents for specific show(s)
|
const DESCRIPTION = 'Search for torrents by IMDB id. You can find IMDB id in the url of a tv show.';
|
||||||
on EZTV. Get IMDB IDs from IMDB.';
|
|
||||||
|
|
||||||
const PARAMETERS = [
|
const PARAMETERS = [
|
||||||
[
|
[
|
||||||
'ids' => [
|
'ids' => [
|
||||||
'name' => 'Show IMDB IDs',
|
'name' => 'IMDB ids',
|
||||||
'exampleValue' => '8740790,1733785',
|
'exampleValue' => '8740790,1733785',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'title' => 'One or more IMDB show IDs (can be found in the IMDB show URL)'
|
'title' => 'One or more IMDB ids'
|
||||||
],
|
],
|
||||||
'no480' => [
|
'no480' => [
|
||||||
'name' => 'No 480p',
|
'name' => 'No 480p',
|
||||||
@ -44,53 +45,16 @@ on EZTV. Get IMDB IDs from IMDB.';
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
// Shamelessly lifted from https://stackoverflow.com/a/2510459
|
|
||||||
protected function formatBytes($bytes, $precision = 2)
|
|
||||||
{
|
|
||||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
||||||
|
|
||||||
$bytes = max($bytes, 0);
|
|
||||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
|
||||||
$pow = min($pow, count($units) - 1);
|
|
||||||
$bytes /= pow(1024, $pow);
|
|
||||||
|
|
||||||
return round($bytes, $precision) . ' ' . $units[$pow];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getItemFromTorrent($torrent)
|
|
||||||
{
|
|
||||||
$item = [];
|
|
||||||
$item['uri'] = $torrent->episode_url;
|
|
||||||
$item['author'] = $torrent->imdb_id;
|
|
||||||
$item['timestamp'] = date('d F Y H:i:s', $torrent->date_released_unix);
|
|
||||||
$item['title'] = $torrent->title;
|
|
||||||
$item['enclosures'][] = $torrent->torrent_url;
|
|
||||||
|
|
||||||
$thumbnailUri = 'https:' . $torrent->small_screenshot;
|
|
||||||
$torrentSize = $this->formatBytes($torrent->size_bytes);
|
|
||||||
|
|
||||||
$item['content'] = $torrent->filename . '<br>File size: '
|
|
||||||
. $torrentSize . '<br><a href="' . $torrent->magnet_url
|
|
||||||
. '">magnet link</a><br><a href="' . $torrent->torrent_url
|
|
||||||
. '">torrent link</a><br><img src="' . $thumbnailUri . '" />';
|
|
||||||
|
|
||||||
return $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function compareDate($torrent1, $torrent2)
|
|
||||||
{
|
|
||||||
return (strtotime($torrent1['timestamp']) < strtotime($torrent2['timestamp']) ? 1 : -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectData()
|
public function collectData()
|
||||||
{
|
{
|
||||||
$showIds = explode(',', $this->getInput('ids'));
|
$ids = explode(',', trim($this->getInput('ids')));
|
||||||
|
foreach ($ids as $id) {
|
||||||
foreach ($showIds as $showId) {
|
$data = json_decode(getContents(sprintf('https://eztv.re/api/get-torrents?imdb_id=%s', $id)));
|
||||||
$eztvUri = $this->getURI() . 'api/get-torrents?imdb_id=' . $showId;
|
if (!isset($data->torrents)) {
|
||||||
$content = getContents($eztvUri);
|
// No results
|
||||||
$torrents = json_decode($content)->torrents;
|
continue;
|
||||||
foreach ($torrents as $torrent) {
|
}
|
||||||
|
foreach ($data->torrents as $torrent) {
|
||||||
$title = $torrent->title;
|
$title = $torrent->title;
|
||||||
$regex480 = '/480p/';
|
$regex480 = '/480p/';
|
||||||
$regex720 = '/720p/';
|
$regex720 = '/720p/';
|
||||||
@ -107,12 +71,31 @@ on EZTV. Get IMDB IDs from IMDB.';
|
|||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items[] = $this->getItemFromTorrent($torrent);
|
$this->items[] = $this->getItemFromTorrent($torrent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
usort($this->items, function ($torrent1, $torrent2) {
|
||||||
|
return $torrent2['timestamp'] <=> $torrent1['timestamp'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Sort all torrents in array by date
|
protected function getItemFromTorrent($torrent)
|
||||||
usort($this->items, ['EZTVBridge', 'compareDate']);
|
{
|
||||||
|
$item = [];
|
||||||
|
$item['uri'] = $torrent->episode_url;
|
||||||
|
$item['author'] = $torrent->imdb_id;
|
||||||
|
$item['timestamp'] = $torrent->date_released_unix;
|
||||||
|
$item['title'] = $torrent->title;
|
||||||
|
$item['enclosures'][] = $torrent->torrent_url;
|
||||||
|
|
||||||
|
$thumbnailUri = 'https:' . $torrent->small_screenshot;
|
||||||
|
$torrentSize = format_bytes((int) $torrent->size_bytes);
|
||||||
|
|
||||||
|
$item['content'] = $torrent->filename . '<br>File size: '
|
||||||
|
. $torrentSize . '<br><a href="' . $torrent->magnet_url
|
||||||
|
. '">magnet link</a><br><a href="' . $torrent->torrent_url
|
||||||
|
. '">torrent link</a><br><img src="' . $thumbnailUri . '" />';
|
||||||
|
|
||||||
|
return $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,3 +136,18 @@ function parse_mime_type($url)
|
|||||||
|
|
||||||
return 'application/octet-stream';
|
return 'application/octet-stream';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://stackoverflow.com/a/2510459
|
||||||
|
*/
|
||||||
|
function format_bytes(int $bytes, $precision = 2)
|
||||||
|
{
|
||||||
|
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||||
|
|
||||||
|
$bytes = max($bytes, 0);
|
||||||
|
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||||
|
$pow = min($pow, count($units) - 1);
|
||||||
|
$bytes /= pow(1024, $pow);
|
||||||
|
|
||||||
|
return round($bytes, $precision) . ' ' . $units[$pow];
|
||||||
|
}
|
||||||
|
@ -17,6 +17,15 @@ final class UtilsTest extends TestCase
|
|||||||
$this->assertSame('fo[...]', truncate('foo', 2, '[...]'));
|
$this->assertSame('fo[...]', truncate('foo', 2, '[...]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormatBytes()
|
||||||
|
{
|
||||||
|
$this->assertSame('1 B', format_bytes(1));
|
||||||
|
$this->assertSame('1 KB', format_bytes(1024));
|
||||||
|
$this->assertSame('1 MB', format_bytes(1024 ** 2));
|
||||||
|
$this->assertSame('1 GB', format_bytes(1024 ** 3));
|
||||||
|
$this->assertSame('1 TB', format_bytes(1024 ** 4));
|
||||||
|
}
|
||||||
|
|
||||||
public function testFileCache()
|
public function testFileCache()
|
||||||
{
|
{
|
||||||
$sut = new \FileCache();
|
$sut = new \FileCache();
|
||||||
|
Loading…
Reference in New Issue
Block a user