[add] rename dir

This commit is contained in:
Knah Tsaeb 2013-07-26 10:06:54 +02:00
parent 20c0dbbcce
commit e2302f1163
5 changed files with 104 additions and 38 deletions

View File

@ -18,7 +18,7 @@ do
then
while read urlHash url destination
do
youtube-dl -R 0 -q -c --write-thumbnail --write-info-json --recode-video webm --no-check-certificate -f 46/37/45/22/44/35/34/5 -o "$urlHash.%(ext)s" "$url"
youtube-dl -R 0 -c --write-thumbnail --write-info-json --recode-video webm --no-check-certificate -f 45/46/37/45/22/44/35/34/5 -o "$urlHash.%(ext)s" "$url"
sleep 5
if [ ! -f $urlHash.*.part ]
then
@ -29,3 +29,5 @@ do
done < $file
fi
done
# -rc_lookahead 16 -g 360 -threads 3

View File

@ -1,7 +1,4 @@
<?php
#todo n_print(chunk_split($text,8,'/'));
require 'inc/topMenu.php';
if (!empty($ci['ac']) && $ci['ac'] === 'login') {
echo '<form action="?" method="post">
@ -14,43 +11,47 @@ if (!empty($ci['ac']) && $ci['ac'] === 'login') {
<input type="hidden" name="op" value="2"/>
<input type="hidden" name="ac" value="login"/>
<input type="hidden" name="bc" value="'.$ci['bc'].'" />
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="submit" />
</fieldset>
</form>';
}
if (!empty($ci['ac']) && $ci['ac'] === 'newDir') {
if (!empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addDir = addDir($ci['newDir'], $ci['bc'], $fullListDir);
} else {
echo '<form action="?" method="post">
<fieldset>
<legend>
New directory
</legend>
<legend>New directory</legend>
<label>Name</label>
<input type="text" name="newDir"/>
<input type="hidden" name="op" value="1"/>
<input type="hidden" name="ac" value="newDir" />
<input type="hidden" name="bc" value="'.$ci['bc'].'" />
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="submit"/>
</fieldset>
</form>';
}
if (!empty($ci['ac']) && $ci['ac'] === 'renDir') {
if (empty($ci['op'])){
$currentDir = getCurrentDir($ci['bc']);
echo '<form action="?" method="post">
<fieldset>
<legend>', $fullListDir[$currentDir], '</legend>
<label>New name</label>
<input type="text" name="renDir" value="', $fullListDir[$currentDir], '"/>
<input type="hidden" name="op" value="1"/>
<input type="hidden" name="ac" value="renDir" />
<input type="hidden" name="bc" value="'.$ci['bc'].'" />
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="submit"/>
</fieldset>
</form>';
}
}
if (!empty($ci['ac']) && $ci['ac'] === 'addVideo') {
if (!empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addVideo = addVideo($ci, $fullListFile);
} else {
echo '<form action="?" method="post">
<fieldset>
<legend>
New video
</legend>
<legend>New video</legend>
<label>Url</label>
<input type="url" name="url" />
<label>Name</label>
@ -66,12 +67,13 @@ if (!empty($ci['ac']) && $ci['ac'] === 'addVideo') {
<input type="hidden" name="op" value="1"/>
<input type="hidden" name="ac" value="addVideo" />
<input type="hidden" name="bc" value="'.$ci['bc'].'" />
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="hidden" name="token" value="', genToken(), '"/>
<input type="submit"/>
</fieldset>
</form>';
}
}
//n_print($fullListDir);
if (!empty($ci['ac']) && $ci['ac'] === 'view') {
if (!empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
@ -125,8 +127,9 @@ if ($ci['ac'] === 'view' && !empty($listCurrentFile)) {
if (!empty($videoInfo)) {
echo '<div id="viewFile">';
echo '<h2>', $videoInfo['title'], ' (', $videoInfo['originalTitle'], ')</h2>';
echo '<video width="400" controls="controls" poster="', $path.$videoInfo['hash'], '.jpg">';
echo '<video width="640" controls="controls" poster="', $path.$videoInfo['hash'], '.jpg">';
echo '<source src="', $path.$videoInfo['hash'], '.webm" type="video/webm" />';
echo '<source src="', $path.$videoInfo['hash'], '.mp4" type="video/mp4" />';
echo '
<object type="application/x-shockwave-flash" data="lib/flowplayer-3.2.1.swf" width="640" height="360">
<param name="movie" value="lib/flowplayer-3.2.1.swf" />
@ -146,28 +149,31 @@ if ($ci['ac'] === 'view' && !empty($listCurrentFile)) {
</tr>
<tr>
<th>Description</th>
<td>', $videoInfo['desc'], '</td
<td>', $videoInfo['desc'], '</td>
</tr>
<tr>
<th>Original description</th>
<td>', $videoInfo['originalDesc'], '</td
<td>', $videoInfo['originalDesc'], '</td>
</tr>
<tr>
<tr>
<th>Url</th>
<td>', $videoInfo['url'], '</td
<td>', $videoInfo['url'], '</td>
</tr>
<tr>
<th>Date</th>
<td>', $videoInfo['uploadDate'], '</td
<th>Duration</th>
<td>', $videoInfo['duration'], '</td>
<tr>
<th>Publish date</th>
<td>', $videoInfo['uploadDate'], '</td>
</tr>
<tr>
<th>Via</th>
<td>', $videoInfo['via'], '</td
<td>', $videoInfo['via'], '</td>
</tr>
<tr>
<th>Licence</th>
<td>', $videoInfo['licence'], '</td
<td>', $videoInfo['licence'], '</td>
</tr>
</table>
</div>';

View File

@ -4,6 +4,7 @@
if ($_SESSION['log'] === true) {
echo '
<li><a href="?ac=newDir&bc=', $ci['bc'], '">New directory</a></li>
<li><a href="?ac=renDir&bc=', $ci['bc'], '">Rename directory</a></li>
<li><a href="?ac=addVideo&bc=', $ci['bc'], '">Add videos</a></li>';
} else {
echo '<li><a href="?ac=login&bc=', $ci['bc'], '">Login</a></li>';

View File

@ -102,6 +102,11 @@ function checkSecure() {
function logout() {
}
function getCurrentDir($bc) {
$currentDir = end(str_split($bc, 8));
return $currentDir;
}
function genToken() {
$token = sha1(uniqid(rand(), true).'_'.mt_rand());
$_SESSION['token'] = $token;
@ -153,12 +158,12 @@ function n_print($data, $name = '') {
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '
<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
<fieldset style="border: 1px solid orange; padding: 5px;color:#1E1915; background-color: #fff;">';
echo '
<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">
', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '
', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '
</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '<pre style="color:#1E1915;">', htmlentities(print_r($data, 1)), '</pre>';
echo '
</fieldset>
<br />';
@ -168,19 +173,45 @@ function addDir($dir, $breadcrumb, $fullListDir) {
if (empty($dir)) {
return 'error';
}
$dirHash = substr(sha1($dir), 0, 8);
$dirHash = substr(sha1($dir.microtime(true)), 0, 8);
$fullListDir[$dirHash] = $dir;
$path = chunk_split($breadcrumb, 8, '/');
file_put_contents($GLOBALS['config']['LISTDIR'], "<?php\n\$fullListDir=".var_export($fullListDir, true).";\n?>");
if (mkdir('videos/'.$path.'/'.$dirHash)) {
return 'success';
return array(
'result' => 'success',
'fullListDir' => $fullListDir
);
} else {
return 'error';
}
}
function renDir($dir, $breadcrumb, $fullListDir) {
if (empty($dir)) {
return;
}
$currentDir = getCurrentDir($breadcrumb);
$dirHash = substr(sha1($dir.microtime(true)), 0, 8);
$fullListDir[$dirHash] = $dir;
$path = chunk_split($breadcrumb, 8, '/');
if (rename('videos/'.$path, 'videos/'.substr($path, 0, -9).'/'.$dirHash)) {
unset($fullListDir[$currentDir]);
file_put_contents($GLOBALS['config']['LISTDIR'], "<?php\n\$fullListDir=".var_export($fullListDir, true).";\n?>");
$breadcrumb = substr($path, 0, -9).$dirHash;
return array(
'result' => 'success',
'bc' => str_replace('/', '', $breadcrumb),
'fullListDir' => $fullListDir
);
} else {
return 'error';
}
}
function addVideo($ci, $fullListFile) {
$nameHash = substr(sha1($ci['name']), 0, 10);
$nameHash = substr(sha1($ci['name'].$ci['url']), 0, 10);
$url = escapeshellcmd($ci['url']);
$path = chunk_split($ci['bc'], 8, '/');
$data = $nameHash.' '.$url.' '.$path."\n";
@ -228,6 +259,8 @@ function getVideoInfo($file, $dir, $fullListFile) {
$descFile = glob("videos/".$path.$file."*.json");
$jsonInfo = json_decode(file_get_contents($descFile[0]));
$time = gmdate('H\hi\ms\s', $jsonInfo -> duration);
$info = array(
'hash' => $file,
'title' => $postInfo['title'],
@ -238,7 +271,7 @@ function getVideoInfo($file, $dir, $fullListFile) {
'uploadDate' => htmlentities($jsonInfo -> upload_date),
'format' => htmlentities($jsonInfo -> format),
'ext' => htmlentities($jsonInfo -> ext),
'duration' => htmlentities(round(($jsonInfo -> duration / 60), 2)),
'duration' => htmlentities($time),
'via' => $postInfo['via'],
'licence' => $postInfo['licence']
);
@ -270,6 +303,26 @@ if (!empty($ci['ac']) && $ci['ac'] === 'login' && !empty($ci['op']) && (int)$ci[
unset($ci['op'], $ci['ac']);
}
}
if (!empty($ci['ac'])) {
if ($ci['ac'] === 'renDir' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$renDir = renDir($ci['renDir'], $ci['bc'], $fullListDir);
$ci['bc'] = $renDir['bc'];
$fullListDir = $renDir['fullListDir'];
}
if ($ci['ac'] === 'newDir' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addDir = addDir($ci['newDir'], $ci['bc'], $fullListDir);
$fullListDir = $addDir['fullListDir'];
}
if ($ci['ac'] === 'addVideo' && !empty($ci['op']) && (int)$ci['op'] === 1) {
verifToken($ci['token']);
$addVideo = addVideo($ci, $fullListFile);
}
}
?>
<!doctype html>
<html lang="fr">

View File

@ -38,6 +38,10 @@ vertical-align: middle;
margin : 0 auto;
}
input, select, options {
color : #1E1915;
}
input[type="submit"] {
color : #1E1915;
}
}