fix: php notice in eztvbridge (#2998)

* fix: php notice in eztvbridge

Fixes Undefined property: stdClass::$torrents

* lint
This commit is contained in:
Dag 2022-09-04 04:35:21 +02:00 committed by GitHub
parent b8f73618c1
commit 57d5aa45f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 52 deletions

View file

@ -136,3 +136,18 @@ function parse_mime_type($url)
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];
}