mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
progress-bar
This commit is contained in:
@@ -187,4 +187,24 @@ class DB
|
||||
return mysql_fetch_assoc($res);
|
||||
}
|
||||
|
||||
public static function getAll($table, $whereStr, $fields = '*')
|
||||
{
|
||||
if ($fields != '*') {
|
||||
if (is_array($fields)) {
|
||||
$fields = implode(', ', $fields);
|
||||
}
|
||||
}
|
||||
if (empty($fields)) {
|
||||
do_log("args: " . json_encode(func_get_args()));
|
||||
throw new DatabaseException("empty fields.");
|
||||
}
|
||||
$sql = "select $fields from $table where $whereStr";
|
||||
$res = sql_query($sql);
|
||||
$result = [];
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Nexus\Torrent;
|
||||
|
||||
class TechnicalInformation
|
||||
{
|
||||
private $mediaInfo;
|
||||
|
||||
private $mediaInfoArr;
|
||||
|
||||
public function __construct($mediaInfo)
|
||||
{
|
||||
$this->mediaInfo = (string)$mediaInfo;
|
||||
$this->mediaInfoArr = $this->getMediaInfoArr((string)$mediaInfo);
|
||||
}
|
||||
|
||||
public function getMediaInfoArr(string $mediaInfo)
|
||||
{
|
||||
$arr = preg_split('/[\r\n]+/', $mediaInfo);
|
||||
$result = [];
|
||||
$parentKey = "";
|
||||
foreach ($arr as $key => $value) {
|
||||
$value = trim($value);
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
$rowKeyValue = explode(':', $value);
|
||||
$rowKeyValue = array_filter(array_map('trim', $rowKeyValue));
|
||||
if (count($rowKeyValue) == 1) {
|
||||
$parentKey = $rowKeyValue[0];
|
||||
} elseif (count($rowKeyValue) == 2) {
|
||||
if (empty($parentKey)) {
|
||||
continue;
|
||||
}
|
||||
$result[$parentKey][$rowKeyValue[0]] = $rowKeyValue[1];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function getRuntime()
|
||||
{
|
||||
return $this->mediaInfoArr['General']['Duration'] ?? '';
|
||||
}
|
||||
|
||||
public function getResolution()
|
||||
{
|
||||
$width = $this->mediaInfoArr['Video']['Width'] ?? '';
|
||||
$height = $this->mediaInfoArr['Video']['Height'] ?? '';
|
||||
$ratio = $this->mediaInfoArr['Video']['Display aspect ratio'] ?? '';
|
||||
$result = $width . 'x' . $height;
|
||||
if ($ratio) {
|
||||
$result .= "($ratio)";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getBitrate()
|
||||
{
|
||||
$result = $this->mediaInfoArr['Video']['Bit rate'] ?? '';
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getFramerate()
|
||||
{
|
||||
$result = $this->mediaInfoArr['Video']['Frame rate'] ?? '';
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getProfile()
|
||||
{
|
||||
$result = $this->mediaInfoArr['Video']['Format profile'] ?? '';
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getRefFrame()
|
||||
{
|
||||
foreach ($this->mediaInfoArr['Video'] as $key => $value) {
|
||||
if (strpos($key, 'Reference frames') !== false) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getAudios()
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->mediaInfoArr as $parentKey => $values) {
|
||||
if (strpos($parentKey, 'Audio') == false) {
|
||||
continue;
|
||||
}
|
||||
$audioInfoArr = [];
|
||||
if (!empty($values['Language'])) {
|
||||
$audioInfoArr[] = $values['Language'];
|
||||
}
|
||||
if (!empty($values['Format'])) {
|
||||
$audioInfoArr[] = $values['Format'];
|
||||
}
|
||||
if (!empty($values['Channel(s)'])) {
|
||||
$audioInfoArr[] = $values['Channel(s)'];
|
||||
}
|
||||
if (!empty($values['Bit rate'])) {
|
||||
$audioInfoArr[]= "@" . $values['Bit rate'];
|
||||
}
|
||||
if (!empty($audioInfoArr)) {
|
||||
$result[$parentKey] = implode(" ", $audioInfoArr);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSubtitles()
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->mediaInfoArr as $parentKey => $values) {
|
||||
if (strpos($parentKey, 'Text') == false) {
|
||||
continue;
|
||||
}
|
||||
$audioInfoArr = [];
|
||||
if (!empty($values['Language'])) {
|
||||
$audioInfoArr[] = $values['Language'];
|
||||
}
|
||||
if (!empty($values['Format'])) {
|
||||
$audioInfoArr[] = $values['Format'];
|
||||
}
|
||||
if (!empty($audioInfoArr)) {
|
||||
$result[$parentKey] = implode(" ", $audioInfoArr);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function renderOnDetailsPage()
|
||||
{
|
||||
global $lang_functions;
|
||||
$runtime = $this->getRuntime();
|
||||
$resolution = $this->getResolution();
|
||||
$bitrate = $this->getBitrate();
|
||||
$profile = $this->getProfile();
|
||||
$framerate = $this->getFramerate();
|
||||
$refFrame = $this->getRefFrame();
|
||||
$audios = $this->getAudios();
|
||||
$subtitles = $this->getSubtitles();
|
||||
$html = '<table>';
|
||||
if (!empty($runtime)) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Nexus\Torrent;
|
||||
|
||||
use Nexus\Database\DB;
|
||||
|
||||
class Torrent
|
||||
{
|
||||
/**
|
||||
* get torrent seeching or downloading status, download progress for someone
|
||||
*
|
||||
* @param int $uid
|
||||
* @param array $torrentIdArr
|
||||
* @return array
|
||||
* @throws \Nexus\Database\DatabaseException
|
||||
*/
|
||||
public function listLeechingSeedingStatus(int $uid, array $torrentIdArr)
|
||||
{
|
||||
$torrentIdStr = implode(',', $torrentIdArr);
|
||||
//seeding or leeching, from peers
|
||||
$whereStr = sprintf("userid = %s and torrent in (%s)", sqlesc($uid), $torrentIdStr);
|
||||
$peerList = DB::getAll('peers', $whereStr, 'torrent, to_go');
|
||||
$peerList = array_column($peerList,'to_go', 'torrent');
|
||||
//download progress, from snatched
|
||||
$sql = sprintf(
|
||||
"select snatched.finished, snatched.to_go, snatched.torrentid, torrents.size from snatched inner join torrents on snatched.torrentid = torrents.id where snatched.userid = %s and snatched.torrentid in (%s)",
|
||||
sqlesc($uid), $torrentIdStr
|
||||
);
|
||||
$snatchedList = [];
|
||||
$res = sql_query($sql);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$id = $row['torrentid'];
|
||||
$activeStatus = 'none';
|
||||
if (isset($peerList[$id])) {
|
||||
if ($peerList[$id]['to_go'] == 0) {
|
||||
$activeStatus = 'seeding';
|
||||
} else {
|
||||
$activeStatus = 'leeching';
|
||||
}
|
||||
}
|
||||
$realDownloaded = $row['size'] - $row['to_go'];
|
||||
$progress = sprintf('%.4f', $realDownloaded / $row['size']);
|
||||
$snatchedList[$id] = [
|
||||
'finished' => $row['to_go'] == 0 ? 'yes' : 'no',
|
||||
'progress' => $progress,
|
||||
'active_status' => $activeStatus,
|
||||
];
|
||||
}
|
||||
return $snatchedList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user