[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 then
while read urlHash url destination while read urlHash url destination
do 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 sleep 5
if [ ! -f $urlHash.*.part ] if [ ! -f $urlHash.*.part ]
then then
@ -29,3 +29,5 @@ do
done < $file done < $file
fi fi
done done
# -rc_lookahead 16 -g 360 -threads 3

View file

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

View file

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

View file

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

View file

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