forked from axiom-team/astrXbian
243 lines
4.1 KiB
PHP
243 lines
4.1 KiB
PHP
<?php
|
|
|
|
function getCollectionType ($filename) {
|
|
|
|
switch (substr($filename, 0, 1)) {
|
|
|
|
case 'F': return 'Films';
|
|
|
|
case 'Y': return 'Youtube';
|
|
}
|
|
}
|
|
|
|
function pingFile ($url) {
|
|
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
|
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$data = curl_exec($ch);
|
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
return ($httpcode>=200 && $httpcode<300);
|
|
}
|
|
|
|
function guessTypeFromFilename ($filename) {
|
|
|
|
$ext = substr($filename, (strrpos($filename, '.') + 1));
|
|
|
|
switch ($ext) {
|
|
|
|
case 'mkv':
|
|
$type = 'video/mkv';
|
|
break;
|
|
|
|
case 'flv':
|
|
$type = 'video/flv';
|
|
break;
|
|
|
|
case 'avi':
|
|
$type = 'video/x-msvideo';
|
|
break;
|
|
|
|
case 'webm':
|
|
$type = 'video/webm';
|
|
break;
|
|
|
|
case 'mkv':
|
|
$type = 'video/x-matroska';
|
|
break;
|
|
|
|
case '3gp':
|
|
$type = 'video/3gp';
|
|
break;
|
|
|
|
case 'ogv':
|
|
$type = 'video/ogv';
|
|
break;
|
|
|
|
default:
|
|
$type = 'video/mp4';
|
|
break;
|
|
}
|
|
|
|
return $type;
|
|
}
|
|
|
|
function astroport_urlencode ($str) {
|
|
|
|
$str = str_replace('%', '%25', $str);
|
|
$str = str_replace('#', '%23', $str);
|
|
$str = str_replace('\'', '%27', $str);
|
|
$str = str_replace('"', '%22', $str);
|
|
|
|
return $str;
|
|
}
|
|
|
|
function quickfix_getYoutubeIdFromIpfsFileName ($name) {
|
|
|
|
return substr($name, 0, 11);
|
|
|
|
}
|
|
|
|
function quickfix_getVideoNameFromIpfsFileName ($name) {
|
|
|
|
//$name = substr($name, 12);
|
|
$name = substr($name, 0, strrpos($name, '.'));
|
|
|
|
return $name;
|
|
}
|
|
|
|
function formatDuration ($seconds) {
|
|
|
|
$h = floor($seconds / 3600);
|
|
$h_r = $seconds % 3600;
|
|
$m = floor($h_r / 60);
|
|
$s = $h_r % 60;
|
|
|
|
if ($h != 0) {
|
|
|
|
return sprintf("%s:%s:%s", $h, str_pad($m, 2, '0', STR_PAD_LEFT), str_pad($s, 2, '0', STR_PAD_LEFT));
|
|
|
|
} else {
|
|
|
|
return sprintf("%s:%s", $m, str_pad($s, 2, '0', STR_PAD_LEFT));
|
|
|
|
}
|
|
}
|
|
|
|
function getVideoJson ($ipnsHash) {
|
|
|
|
$indexHTML = @file_get_contents('http://' . HOST . '/ipns/' . $ipnsHash . '/index.html');
|
|
|
|
if (empty($indexHTML)) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
// $indexHTML = @file_get_contents('http://' . HOST . '/ipns/' . $ipfsNodeId . '/.' . $ipfsNodeId . '/KEY/');
|
|
|
|
$re = '!/ipns/[^/]+/([^/]+)/!isU';
|
|
|
|
preg_match($re, $indexHTML, $matches);
|
|
|
|
$ipnsHiddenHash = $matches[1];
|
|
|
|
$indexHTML = @file_get_contents('http://' . HOST . '/ipns/' . $ipnsHash . '/' . $ipnsHiddenHash . '/video.json');
|
|
|
|
if (empty($indexHTML)) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
return json_decode($indexHTML);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function getTagsListFromTagStr ($str) {
|
|
|
|
if (substr($str, 0, 1) == "[") {
|
|
|
|
$str = substr($str, 1);
|
|
$str = substr($str, 0, -1);
|
|
|
|
preg_match_all('/"([^"]+)"/isU', $str, $matches, PREG_PATTERN_ORDER);
|
|
$tags = $matches[1];
|
|
|
|
} else {
|
|
|
|
$tags = explode('|', $str);
|
|
}
|
|
|
|
if ((count($tags) == 1) and empty($tags[0])) {
|
|
|
|
return array();
|
|
|
|
} else {
|
|
|
|
return $tags;
|
|
}
|
|
}
|
|
|
|
function separateTags ($tags, $stations) {
|
|
|
|
return [
|
|
array_diff($tags, $stations),
|
|
array_intersect($tags, $stations)
|
|
];
|
|
|
|
}
|
|
|
|
function isStation ($tag) {
|
|
|
|
global $stations;
|
|
|
|
return in_array($tag, $stations);
|
|
}
|
|
|
|
function buildRequestedURI ($uri, $params, $escapeHTML = false) {
|
|
|
|
$URL = $uri;
|
|
$first = true;
|
|
|
|
foreach ($params as $k => $v) {
|
|
|
|
if ($first) {
|
|
|
|
$URL .= '?';
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
if ($escapeHTML) {
|
|
|
|
$URL .= '&';
|
|
|
|
} else {
|
|
|
|
$URL .= '&';
|
|
}
|
|
}
|
|
|
|
$URL .= $k . '=' . htmlspecialchars($v);
|
|
}
|
|
|
|
return $URL;
|
|
}
|
|
|
|
function handleVideoID ($videoID) {
|
|
|
|
preg_match('/^((?P<ndd>([a-zA-Z0-9-]+\.)?[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+)_)?(?P<id>.+)$/is', $videoID, $matches);
|
|
|
|
$ndd = empty($matches['ndd']) ? 'www.youtube.com' : strrev($matches['ndd']);
|
|
$id = $matches['id'];
|
|
|
|
return [
|
|
$ndd,
|
|
$id
|
|
];
|
|
}
|
|
|
|
function canReadVideoFormat ($mimeType) {
|
|
|
|
return ($mimeType == 'video/mp4');
|
|
}
|
|
|
|
function in_array_column($text, $column, $array)
|
|
{
|
|
if (!empty($array) && is_array($array))
|
|
{
|
|
for ($i=0; $i < count($array); $i++)
|
|
{
|
|
if ($array[$i][$column]==$text || strcmp($array[$i][$column],$text)==0) return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|