=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) { exec("/bin/bash -c './get_ipfs_node_id.sh'", $output); // echo '
'; var_dump($output); echo '
'; $ipfsNodeId = $output[0]; $indexHTML = file_get_contents('http://' . HOST . '/ipns/' . $ipnsHash . '/index.html'); // $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 (isset($indexHTML)) { return json_decode($indexHTML); } }