first commit

This commit is contained in:
Lionel 2020-11-08 15:14:32 +01:00
commit d2de9134c7
10 changed files with 11830 additions and 0 deletions

116
index.php Normal file
View File

@ -0,0 +1,116 @@
<?php
include "php/function.php";
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
if (isset($_GET['saga'])) {
$sagaID = $_GET['saga'];
$result = movie_list($sagaID);
$movies_list = json_encode($result);
$saga_name = saga_name($sagaID);
}
elseif (isset($_GET['movie'])) {
$id = $_GET['movie'];
$result = movie_detail($id);
$result['release_date'] = ucwords(strftime("%d %B %Y", strtotime($result['release_date'])));
$movie_detail = json_encode($result);
$file = $result['file_path'];
//$file = '/var/www/html/video/test5.mkv';
if (is_file($file)) {
$info = MediaInfo($file);
$file_info = json_encode($info);
}
}
$saga_list = json_encode(saga_list());
$movies_full_list = json_encode(movies_full_list());
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Netflix 2.0</title>
<link href="style/style.css" rel="stylesheet">
<link href="/fontawesome/css/all.css" rel="stylesheet" />
</head>
<body>
<div class="navbar">
<a href=".">Films</a>
<a href="#anime">Animés</a>
<input id="search" type="text" name="search" placeholder="Recherche">
<i class="fa fa-list fa-2x" aria-hidden="true" title="Vue en liste"></i>
<i class="fa fa-th fa-2x" aria-hidden="true" title="Vue en miniature"></i>
</div>
<h2 class="main">Netflix 2.0</h2>
<div id="heure" style="margin: 0 10px; padding: 0;"></div>
<div id="sagas" class="main" ></div>
<div id="movies" class="main" ></div>
<div id="research" class="main" ></div>
<?php
if (isset($movie_detail)):
?>
<section id="movieContent" class="main">
<h2 id="movieTitle" style="margin: 0;"></h2>
<h3 id="showDetail" class="toggle"><i class="fa fa-chevron-down" aria-hidden="true"></i> Afficher détail</h3>
<div id="movieDetails">
<div id="cover" >
<img width="300" src="">
</div>
<div id="spec">
<p></p>
</div>
</div>
<div id="selection">
<div id="AV"></div>
<div id="subtitle_list"></div>
</div>
<div class="hidden" id="video">
<!--<video width="600" controls>
<source src="" type="video/mp4">
</video>-->
</div>
</section>
<?php
endif;
?>
<br>
<button id="back" onclick="goBack()">Go Back</button>
<script>
<?php
echo "var saga_list = " . $saga_list. ";\n";
echo "var movies_full_list = " . $movies_full_list. ";\n";
if (isset($movies_list)) echo "var movies_list = " . $movies_list. ";\nvar saga_name = '" . $saga_name. "';";
if (isset($file_info)) echo "var file_info = " . $file_info. ';';
if (isset($movie_detail)) echo "var movie_detail = " . $movie_detail. ';';
?>
</script>
<script src="js/jquery-3.4.1.js"></script>
<script src="js/function.js"></script>
<script src="js/script.js"></script>
</body>
</html>

284
js/function.js Normal file
View File

@ -0,0 +1,284 @@
var duree_movie;
function ShowSagas(data) {
var nosaga = $('<a />', {
id: 0,
class: 'saga button nosaga',
href: '.?saga=0',
});
nosaga.append('No Saga');
nosaga.appendTo('#sagas');
$.each(data, function(key, value) {
var saga = $('<a />', {
id: value['id'],
class: 'saga button container',
href: '.?saga='+value['id'],
});
//saga.append('<br>' + value['name']);
saga.appendTo('#sagas');
var text = $('<div />', {
html: value['name'],
class: 'centered title',
});
text.prependTo(saga);
var image = $('<img />', {
src: value['poster_path'],
class: 'thumbnail',
});
image.prependTo(saga);
});
};
function ShowMovies(data) {
$('#movies').append('<h3 style="margin: 10px 10px; padding: 0;">' + saga_name + '</h3>');
$.each(data, function(key, value) {
var movie = $('<a />', {
id: value['id'],
class: 'movie button container',
href: '.?movie='+value['id'],
});
//movie.append('<br>' + value['title']);
movie.appendTo('#movies');
var title = $('<div />', {
html: value['title'],
class: 'centered title',
});
title.appendTo(movie);
var original_title = $('<div />', {
html: value['original_title'],
class: 'original_title',
});
original_title.appendTo(movie);
original_title.hide();
var image = $('<img />', {
src: value['poster_path'],
class: 'thumbnail',
});
image.prependTo(movie);
});
};
function MovieDetails(data) {
$('#movieTitle').html(data.title);
var description = $('#movieDetails #spec p');
description.empty();
description.append('<span id="release_date">Date de sortie : ' + data.release_date + '<br></span>');
description.append('<span id="viewOverview" class="toggle"><i class="fa fa-chevron-right" aria-hidden="true"></i> Résumé</span><br><span class="overview" style="display: none">' + data.overview + '<br></span>');
description.append('<span id="original_language">Langue original : ' + data.original_language + '<br></span>');
description.append('<span id="original_title">Titre original : ' + data.original_title + '<br></span>');
description.append('<span id="file_name">Nom du fichier : ' + data.file_name + '<br></span>');
description.append('<span id="tmdbMovie">More details here : <a target="_blank" href="https://www.themoviedb.org/movie/' + data.id + '?language=fr-FR">TMDB</a><br></span>');
if (data.sagaID != 0)
description.append('<span id="tmdbSaga">Saga details : <a target="_blank" href="https://www.themoviedb.org/collection/' + data.sagaID + '?language=fr-FR">TMDB</a><br></span>');
description.append('<span id="dl">Download : <a target="_blank" href="php/download.php?file=' + data.id + '">File</a>\
<i class="fas fa-clipboard-list" aria-hidden="true" title="Copy to clipboard"></i></span><br>');
$('#cover img').attr('src', data.poster_path);
$('#viewOverview').click(function() {
$('.overview').slideToggle(200);
$(this).find(".fa").toggleClass('active');
});
$('#showDetail').click(function() {
$('#movieDetails').slideToggle(200);
$(this).find(".fa").toggleClass('active');
});
};
function ShowSearch(sc_saga, sc_movie) {
$('#sagas').hide();
$('#movies').hide();
$('#movieContent').hide();
$('#research').empty();
$.each(sc_saga, function(key, value) {
var saga = $('<a />', {
id: value['id'],
class: 'saga line',
href: '.?saga='+value['id'],
});
saga.appendTo('#research');
var title = $('<div />', {
html: value['name'],
class: 'title',
});
title.appendTo(saga);
var image = $('<img />', {
src: value['poster_path'],
class: 'thumbnail',
});
image.prependTo(saga);
});
$.each(sc_movie, function(key, value) {
var movie = $('<a />', {
id: value['id'],
class: 'movie line',
href: '.?movie='+value['id'],
});
movie.appendTo('#research');
var title = $('<div />', {
html: value['title'],
class: 'title',
});
title.appendTo(movie);
var original_title = $('<div />', {
html: value['original_title'],
class: 'original_title',
});
original_title.appendTo(movie);
var image = $('<img />', {
src: value['poster_path'],
class: 'thumbnail',
});
image.prependTo(movie);
});
//$('#research').html(data.toString());
}
function FileInfo(data) {
duree_movie = parseInt(data.format.duration)*1000;
$('#movieDetails #spec p > span#release_date').after('<span id="duration">Durée : ' + data.format.duration.toHHMMSS() + '</span><br>');
$('#movieDetails #spec p > span#original_title').after('<span id="title">Titre du media : ' + data.format.title + '</span><br>');
var selection = $('#selection');
var AV = $('#AV');
var subtitle_list = $('#subtitle_list');
AV.append('Choose Video(s) :<br>');
$.each(data.video, function(key, video) {
var title, language, label;
if('title' in video)
title = video.title;
else
title = 'No title';
if('language' in video)
language = video.language;
else
language = 'und';
label = title + ' [' + language + '] ' + video.codec_name + ' ' + video.display_aspect_ratio + ' ' + video.width + 'x' + video.height;
if(video.forced == 1)
label = label + ' [forced]';
if(video.default == 1)
label = label + ' [def]';
AV.append('<input id="' + key + '" type="checkbox"><label for="' + key + '">' + label + '</label><br>');
});
AV.append('<br>Choose Audio(s) :<br>');
$.each(data.audio, function(key, audio) {
var title, language, label;
if('title' in audio)
title = audio.title;
else
title = 'No title';
if('language' in audio)
language = audio.language;
else
language = 'und';
label = title + ' [' + language + '] ' + audio.codec_name + ' ' + audio.channel_layout;
if(audio.forced == 1)
label = label + ' [forced]';
if(audio.default == 1)
label = label + ' [def]';
AV.append('<input id="' + key + '" type="checkbox"><label for="' + key + '">' + label + '</label><br>');
});
AV.append('<br><input id="convert" type="submit" name="convert">');
if (data.hasOwnProperty("subtitle")) {
subtitle_list.append('Liste Subtitle :<br>');
$.each(data.subtitle, function(key, subtitle) {
var title, language, label;
if('title' in subtitle)
title = subtitle.title;
else
title = 'No title';
if('language' in subtitle)
language = subtitle.language;
else
language = 'und';
label = title + ' [' + language + '] ' + subtitle.codec_name;
if(subtitle.forced == 1)
label = label + ' [forced]';
if(subtitle.default == 1)
label = label + ' [def]';
subtitle_list.append(label + '<br>');
});
}
};
function Horloge() {
var laDate = new Date();
if (typeof duree_movie !== 'undefined') {
var seg = laDate.getTime();
var heure_fin = seg + duree_movie;
heure_fin = new Date(heure_fin);
heure_fin = heure_fin.getHours() + ":" + ("0" + heure_fin.getMinutes()).slice(-2);
}
//var h = laDate.getHours() + ":" + ("0" + laDate.getMinutes()).slice(-2) + ":" + ("0" + laDate.getSeconds()).slice(-2);
var h = laDate.getHours() + ":" + ("0" + laDate.getMinutes()).slice(-2);
var temps = 'Heure : ' + h + ' Heure de Fin : ' + heure_fin;
$('#heure').text(temps);
};
function goBack() {
if (document.referrer.split('/')[2] == location.host)
window.history.back();
};
String.prototype.toHHMMSS = function () {
var sec_num = parseInt(this, 10); // don't forget the second param
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
var total = '';
if (hours > 0) {
total = hours + " Heure"
if (hours > 1)
total = total + 's'
}
if (minutes > 0) {
total = total + ' ' + minutes + " Minute"
if (minutes > 1)
total = total + 's'
}
if (seconds > 0) {
total = total + ' ' + seconds + " Seconde"
if (seconds > 1)
total = total + 's'
}
return total;
}

10598
js/jquery-3.4.1.js vendored Normal file

File diff suppressed because it is too large Load Diff

95
js/script.js Normal file
View File

@ -0,0 +1,95 @@
$(document).ready(function() {
if (typeof movies_list !== 'undefined') {
ShowMovies(movies_list);
}
else if (typeof movie_detail !== 'undefined') {
MovieDetails(movie_detail);
}
else if (typeof saga_list !== 'undefined') {
$('#back').hide();
ShowSagas(saga_list);
}
if (typeof file_info !== 'undefined') {
FileInfo(file_info);
Horloge();
setInterval(Horloge, 1000);
}
if (document.referrer.split('/')[2] !== location.host)
$('#back').hide();
$("#search").on('keyup', function (e) {
if (e.keyCode === 13) {
var sc_saga = [];
var sc_movie = [];
var search = $("#search").val();
console.log(search);
$.each(saga_list, function(index, value) {
if (value.name.toLowerCase().includes(search.toLowerCase())) {
if(! sc_saga.includes(value)){ sc_saga.push(value);}
}
});
$.each(movies_full_list, function(index, value) {
if (value.title.toLowerCase().includes(search.toLowerCase())) {
if(! sc_movie.includes(value)){ sc_movie.push(value);}
}
if (value.original_title.toLowerCase().includes(search.toLowerCase())) {
if(! sc_movie.includes(value)){ sc_movie.push(value);}
}
});
ShowSearch(sc_saga, sc_movie);
}
});
$('.fa-list').click(function() {
var lien = $('.saga, .movie');
var title = $('.saga > .title, .movie > .title');
var original_title = $('.movie > .original_title');
lien.removeClass('button container');
lien.addClass('line');
title.removeClass('centered');
original_title.show();
});
$('.fa-th').click(function() {
var lien = $('.saga, .movie');
var title = $('.saga > .title, .movie > .title');
var original_title = $('.movie > .original_title');
lien.removeClass('line');
lien.addClass('button container');
title.addClass('centered');
original_title.hide();
});
$('.fa-clipboard-list').click(function() {
//var copyText = $('#dl > a').attr('href');
var copyText = $(this).prev().attr('href');
var temp = $("<input>");
$("body").append(temp);
temp.val(location.origin + location.pathname + copyText).select();
//temp.setSelectionRange(0, 99999);
document.execCommand("copy");
temp.remove();
});
$('#convert').click(function() {
var stream = [];
$('#AV > input[type=checkbox]').each(function() {
var id = $(this).attr('id');
var state = $(this).prop('checked');
if (state)
stream.push(id);
});
if (stream.length > 0)
alert(stream);
});
});

53
php/DaveRandom_Resume.php Normal file
View File

@ -0,0 +1,53 @@
<?php declare(strict_types=1);
namespace DaveRandom\Resume;
require __DIR__ . '/../../vendor/autoload.php';
include "function.php";
if (isset($_GET['file'])) {
$id = $_GET['file'];
$path = file_path($id);
$contentType = mime_content_type($path);
}
else {
exit();
}
// Avoid sending unexpected errors to the client - we should be serving a file,
// we don't want to corrupt the data we send
\ini_set('display_errors', '0');
try {
// Note that this construct will still work if the client did not specify a Range: header
$rangeHeader = get_request_header('Range');
$rangeSet = RangeSet::createFromHeader($rangeHeader);
/** @var Resource $resource */
$resource = new FileResource($path, $contentType);
$servlet = new ResourceServlet($resource);
$servlet->sendResource($rangeSet);
} catch (InvalidRangeHeaderException $e) {
\header("HTTP/1.1 400 Bad Request");
} catch (UnsatisfiableRangeException $e) {
\header("HTTP/1.1 416 Range Not Satisfiable");
} catch (NonExistentFileException $e) {
\header("HTTP/1.1 404 Not Found");
} catch (UnreadableFileException $e) {
\header("HTTP/1.1 500 Internal Server Error");
} catch (SendFileFailureException $e) {
if (!\headers_sent()) {
\header("HTTP/1.1 500 Internal Server Error");
}
echo "An error occurred while attempting to send the requested resource: {$e->getMessage()}";
}
// It's usually a good idea to explicitly exit after sending a file to avoid sending any
// extra data on the end that might corrupt the file
exit;

9
php/download.php Normal file
View File

@ -0,0 +1,9 @@
<?php
$query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
$url = "Location: DaveRandom_Resume.php?".$query;
header($url);
?>

294
php/function.php Normal file
View File

@ -0,0 +1,294 @@
<?php
setlocale (LC_TIME, 'fr_FR.utf8');
$images_folder = '/img';
$bdd = '/var/www/html/bdd.db';
$output_video_folder = 'vid/';
function convert($id, $video, $audio) {
global $output_video_folder;
$result = sql(NULL, $id);
if(! $result)
return false;
$file = $result[0]['file_path'];
$info = MediaInfo($file);
if(! $info)
return false;
$allow_codec = array('h264', 'aac');
$out=$output_video_folder.$result[0]['id'];
if (in_array($info['video'][$video]['codec_name'], $allow_codec))
$video_codec = 'copy';
else
$video_codec = 'h264';
if (in_array($info['audio'][$audio]['codec_name'], $allow_codec))
$audio_codec = 'copy';
else
$audio_codec = 'aac';
$commande = 'ffmpeg -hide_banner -i "'.$file.'" -y -map 0:'.$video.' -map 0:'.$audio.' -c:v '.$video_codec.' -c:a '.$audio_codec.' '.$out.'.mp4 2>&1';
//echo "Commande : ".$commande."<br>";
exec($commande, $output);
if(array_key_exists("subtitle", $info)) {
foreach ($info['subtitle'] as $key => $value) {
$commande = 'ffmpeg -hide_banner -i "'.$file.'" -y -map 0:'.$key.' '.$out.'_'.$key.'.vtt 2>&1';
if (! file_exists($out.'_'.$key.'.vtt'))
exec($commande, $output);
}
}
}
function MediaInfo($file) {
require '/var/www/html/vendor/autoload.php';
$ffprobe = FFMpeg\FFProbe::create();
if (file_exists($file)) {
$info = array();
$format=$ffprobe->format($file);
$format_tags=$format->get('tags');
$info['format']['duration'] = $duree=$format->get('duration');
if (isset($format_tags['title']))
$info['format']['title'] = $format_tags['title'];
else
$info['format']['title'] = "No Title";
$streams=$ffprobe->streams($file);
$all=$streams->all();
$nb=$streams->count();
for ($i=0; $i<$nb; $i++) {
$type = $all[$i]->get('codec_type');
$info[$type][$i]['codec_name'] = $all[$i]->get('codec_name');
if($type == "video"){
$info[$type][$i]['width'] = $all[$i]->get('width');
$info[$type][$i]['height'] = $all[$i]->get('height');
$info[$type][$i]['display_aspect_ratio'] = $all[$i]->get('display_aspect_ratio');
}
if($type == "audio")
$info[$type][$i]['channel_layout'] = $all[$i]->get('channel_layout');
$tags=$all[$i]->get('tags');
$disposition=$all[$i]->get('disposition');
if($tags!=NULL){
if (array_key_exists("title", $tags)) {
$info[$type][$i]['title'] = $tags['title'];
}
if (array_key_exists("language", $tags)) {
$info[$type][$i]['language'] = $tags['language'];
}
}
if($disposition!=NULL){
if (array_key_exists("default", $disposition)) {
$info[$type][$i]['default'] = $disposition['default'];
}
if (array_key_exists("forced", $disposition)) {
$info[$type][$i]['forced'] = $disposition['forced'];
}
}
}
return $info;
}
else {
return false;
}
}
function saga_list()
{
global $bdd, $images_folder;
try {
$conn = new PDO('sqlite:'.$bdd);
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
$req = $conn->query("SELECT * FROM sagas ORDER BY name ASC");
$result = $req->fetchAll();
for($i = 0; $i < count($result); $i++) {
$result[$i]['poster_path'] = $images_folder.$result[$i]['poster_path'];
$result[$i]['poster_path'] = $images_folder.'/cover.jpg';
}
return $result;
}
function saga_name($saga)
{
global $bdd;
try {
$conn = new PDO('sqlite:'.$bdd);
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
$req = $conn->prepare("SELECT name FROM sagas WHERE id=:sagaID");
$req->execute(['sagaID' => $saga]);
$result = $req->fetch()[0];
return $result;
}
function movies_full_list()
{
global $bdd, $images_folder;
try {
$conn = new PDO('sqlite:'.$bdd);
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
$req = $conn->query("SELECT id,title,poster_path,original_title FROM movies ORDER BY title ASC");
$result = $req->fetchAll();
for($i = 0; $i < count($result); $i++) {
$result[$i]['poster_path'] = $images_folder.$result[$i]['poster_path'];
$result[$i]['poster_path'] = $images_folder.'/cover.jpg';
}
return $result;
}
function movie_list($saga)
{
global $bdd, $images_folder;
try {
$conn = new PDO('sqlite:'.$bdd);
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
if ($saga == 0) {
$req = $conn->prepare("SELECT id,title,poster_path,original_title FROM movies WHERE sagaID=:sagaID ORDER BY title ASC");
}
else {
$req = $conn->prepare("SELECT id,title,poster_path,original_title FROM movies WHERE sagaID=:sagaID ORDER BY release_date ASC");
}
$req->execute(['sagaID' => $saga]);
$result = $req->fetchAll();
for($i = 0; $i < count($result); $i++) {
$result[$i]['poster_path'] = $images_folder.$result[$i]['poster_path'];
$result[$i]['poster_path'] = $images_folder.'/cover.jpg';
}
return $result;
}
function movie_detail($movie)
{
global $bdd, $images_folder;
try {
$conn = new PDO('sqlite:'.$bdd);
#$bdd = new PDO('sqlite:/home/user/video/bdd.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
die('Erreur : '.$e->getMessage());
}
$req = $conn->prepare("SELECT * FROM movies WHERE id=:id");
$req->execute(['id' => $movie]);
$result = $req->fetchAll()[0];
$result['poster_path'] = $images_folder.$result['poster_path'];
$result['poster_path'] = $images_folder.'/cover.jpg';
return $result;
}
function human_filesize($bytes, $dec = 2)
{
$size = array('B', 'kiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
}
function time_to_str($time,$precision=2){
if($time=abs(intval($time))){
$s=['an'=>31556926,'mois'=>2629743,'semaine'=>604800,'jour'=>86400,'heure'=>3600,'minute'=>60,'seconde'=>1];
foreach($s as $a=>$b){if($time>=$b && $c=$time/$b){$c=intval($c);$time-=$b*$c;
$r[]="$c $a".($c>1?($a=='mois'?'':'s'):'');if(++$d==$precision)break;}}
return count($r)==1?$r[0]:(implode(' ',array_slice($r,0,-1)).' et '.array_shift(array_slice($r,-1,1)));}
return 'un instant';
}
?>

148
php/resumable-download.php Normal file
View File

@ -0,0 +1,148 @@
<?php
class ResumeDownload {
private $file;
private $name;
private $boundary;
private $delay = 0;
private $size = 0;
function __construct($file, $delay = 0) {
if (! is_file($file)) {
header("HTTP/1.1 400 Invalid Request");
die("<h3>File Not Found</h3>");
}
$this->size = filesize($file);
$this->file = fopen($file, "r");
$this->type = mime_content_type($file);
$this->boundary = md5($file);
$this->delay = $delay;
$this->name = basename($file);
}
public function process() {
$ranges = NULL;
$t = 0;
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_SERVER['HTTP_RANGE']) && $range = stristr(trim($_SERVER['HTTP_RANGE']), 'bytes=')) {
$range = substr($range, 6);
$ranges = explode(',', $range);
$t = count($ranges);
}
header("Accept-Ranges: bytes");
//header("Content-Type: application/octet-stream");
header(sprintf('Content-Type: %s', $this->type));
header("Content-Transfer-Encoding: binary");
header(sprintf('Content-Disposition: attachment; filename="%s"', $this->name));
if ($t > 0) {
header("HTTP/1.1 206 Partial content");
$t === 1 ? $this->pushSingle($range) : $this->pushMulti($ranges);
} else {
header("Content-Length: " . $this->size);
$this->readFile();
}
flush();
}
private function pushSingle($range) {
$start = $end = 0;
$this->getRange($range, $start, $end);
header("Content-Length: " . ($end - $start + 1));
header(sprintf("Content-Range: bytes %d-%d/%d", $start, $end, $this->size));
fseek($this->file, $start);
$this->readBuffer($end - $start + 1);
$this->readFile();
}
private function pushMulti($ranges) {
$length = $start = $end = 0;
$output = "";
$tl = "Content-type: application/octet-stream\r\n";
$formatRange = "Content-range: bytes %d-%d/%d\r\n\r\n";
foreach ( $ranges as $range ) {
$this->getRange($range, $start, $end);
$length += strlen("\r\n--$this->boundary\r\n");
$length += strlen($tl);
$length += strlen(sprintf($formatRange, $start, $end, $this->size));
$length += $end - $start + 1;
}
$length += strlen("\r\n--$this->boundary--\r\n");
header("Content-Length: $length");
header("Content-Type: multipart/x-byteranges; boundary=$this->boundary");
foreach ( $ranges as $range ) {
$this->getRange($range, $start, $end);
echo "\r\n--$this->boundary\r\n";
echo $tl;
echo sprintf($formatRange, $start, $end, $this->size);
fseek($this->file, $start);
$this->readBuffer($end - $start + 1);
}
echo "\r\n--$this->boundary--\r\n";
}
private function getRange($range, &$start, &$end) {
list($start, $end) = explode('-', $range);
$fileSize = $this->size;
if ($start == '') {
$tmp = $end;
$end = $fileSize - 1;
$start = $fileSize - $tmp;
if ($start < 0)
$start = 0;
} else {
if ($end == '' || $end > $fileSize - 1)
$end = $fileSize - 1;
}
if ($start > $end) {
header("Status: 416 Requested range not satisfiable");
header("Content-Range: */" . $fileSize);
exit();
}
return array(
$start,
$end
);
}
private function readFile() {
while ( ! feof($this->file) ) {
echo fgets($this->file);
flush();
usleep($this->delay);
}
}
private function readBuffer($bytes, $size = 1024) {
$bytesLeft = $bytes;
while ( $bytesLeft > 0 && ! feof($this->file) ) {
$bytesLeft > $size ? $bytesRead = $size : $bytesRead = $bytesLeft;
$bytesLeft -= $bytesRead;
echo fread($this->file, $bytesRead);
flush();
usleep($this->delay);
}
}
}
include "function.php";
if (isset($_GET['file'])) {
$id = $_GET['file'];
$file = file_path($id);
set_time_limit(0);
$download = new ResumeDownload($file); //delay about in microsecs
$download->process();
}
?>

32
php/simple_download.php Normal file
View File

@ -0,0 +1,32 @@
<?php
include "function.php";
if (isset($_GET['file'])) {
$id = $_GET['file'];
$file = file_path($id);
if(is_file($file)) {
$type = mime_content_type($file);
header('Content-Description: File Transfer');
//header('Content-Type: application/octet-stream');
header('Content-Type: ' . $type);
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\"");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
}
?>

201
style/style.css Normal file
View File

@ -0,0 +1,201 @@
.hidden {
display: none;
}
.container {
position: relative;
text-align: center;
color: white;
}
.centered {
display: none;
position: absolute;
bottom: 20px;
left: 50%;
transform: translate(-50%, -50%);
}
.container:hover > .centered {
display: block;
background-color:rgba(37, 34, 34, 0.6);
}
.thumbnail {
width: 150px;
}
.nosaga.button {
width: 150px;
}
#movieDetails {
display: flex;
}
#cover {
margin-left: 20px;
//background-color: green;
}
#spec {
margin-left: 30px;
width: 60%;
//background-color: red;
}
#selection {
display: flex;
}
#AV {
margin-left: 20px;
//background-color: green;
}
#subtitle_list {
margin-left: 30px;
width: 60%;
//background-color: red;
}
a.button {
background-color: #EEEEEE;
cursor: pointer;
display: inline-block;
text-align: center;
//border: 2px solid;
border-radius: 5px;
font-weight: bold;
margin: 5px;
color: #10a2ff;
padding: 1em 1.5em;
text-decoration: none;
}
a.line {
background-color: #EEEEEE;
cursor: pointer;
display: block;
//border: 2px solid;
border-radius: 5px;
font-weight: bold;
margin: 5px;
color: #10a2ff;
padding: 5px;
text-decoration: none;
display: flex;
align-items: center;
justify-content: flex-start;
}
a.line > .title {
margin-left: 200px;
width: 600px;
font-size: 20px;
}
a.line > .original_title {
margin-left: 100px;
font-size: 20px;
}
a.line > img {
margin-left: 50px;
width: 50px;
}
.toggle {
cursor: pointer;
font-size: 16px;
font-weight: 700;
display: inline-block;
border-bottom: 2px solid;
}
.fa {
transition: transform .2s;
}
.fa-chevron-right.active {
transform: rotateZ(90deg);
}
.fa-chevron-down.active {
transform: rotateZ(-90deg);
}
.fa-clipboard-list {
cursor: pointer;
}
.overview {
border: 1px solid;
display: inline-block;
margin: 5px 0;
margin-left: 5px;
padding: 3px;
}
input:checked + label {
font-weight: bold;
}
input[type="checkbox"] {
position: absolute;
left: -9999px;
}
label:hover, input:focus + label {
cursor: pointer;
box-shadow: 0 0 20px rgba(0, 0, 0, .6);
}
body {
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
position: sticky;
top: 0;
left: 0;
z-index: 999;
padding: 5px 60px;
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar > * {
font-size: 17px;
}
.navbar > a,
.navbar > i {
margin: 0 6px;
padding: 8px 8px;
text-decoration: none;
color: #f2f2f2;
cursor: pointer;
}
.navbar > input[type=text] {
margin-left: auto;
margin-right: 20px;
}
.navbar > a:hover,
.navbar > i:hover {
background: #ddd;
color: black;
}
.main {
padding: 0;
margin: 16px;
}