New version

This commit is contained in:
Némunaire 2012-03-05 22:46:25 +01:00
parent d299e73fa4
commit cf8262d3cb
8 changed files with 5056 additions and 131 deletions

45
dl.sh
View File

@ -2,38 +2,47 @@
pwd=`echo "$0" | sed -e "s/[^\/]*$//"` pwd=`echo "$0" | sed -e "s/[^\/]*$//"`
if [ `cat $pwd/urls | wc -l` -gt 0 ] && [ ! -e /tmp/dlEnCours ]; then # Don't do anything if this script is already launched
if [ ! -e /tmp/dlEnCours ]; then
for f in "$pwd"/users/*.dlist; do
if [ `cat $f | wc -l` -gt 0 ]; then
transmission-remote -asu 10 -as transmission-remote -asu 10 -as
touch /tmp/dlEnCours touch /tmp/dlEnCours
lign=`sed '2,$d' $pwd/urls | tr -d '\n'` lign=`sed '2,$d' $f | tr -d '\n'`
while [ -n "$lign" ] && [ `cat $f | wc -l` -gt 0 ]
do
if [ -z "$lign" ]; then if [ -z "$lign" ]; then
sed -i '1d' $pwd/urls sed -i '1d' $f
lign=`sed '2,$d' $pwd/urls | tr -d '\n'` lign=`sed '2,$d' $f | tr -d '\n'`
fi fi
while [ -n "$lign" ] && [ `cat $pwd/urls | wc -l` -gt 0 ]
do
echo "Action: $lign" echo "Action: $lign"
if [ "$lign" = "clear" ]; then if [ "$lign" = "clear" ]; then
sed -i '1d' $pwd/urls echo "-- " >> $f.done
mkdir $pwd/content/`date +%Y%m%d%H%M%S`
mv $pwd/content/*.mp3 $pwd/content/`date +%Y%m%d%H%M%S`
transmission-remote -AS transmission-remote -AS
else else
$pwd/youtube-dl -e $lign > $pwd/dlEc echo "$lign" >> $pwd/database
$pwd/youtube-dl --get-title --get-thumbnail --get-filename "$lign" >> $pwd/database
echo "-- " >> $pwd/database
sed -i '1d' $pwd/urls echo "$lign" > $f.ec
$pwd/youtube-dl --no-progress -c -o "$pwd/content/%(id)s.%(ext)s" "$lign"
echo "$lign" >> $f.ec
$pwd/youtube-dl --no-progress -c -k -o "$pwd/content/%(id)s.%(ext)s" --extract-audio --audio-format=mp3 "$lign"
echo "" > $f.ec
$pwd/youtube-dl --no-progress -c -k -o "$pwd/content/%(title)s.%(ext)s" --extract-audio --audio-format=mp3 "$lign" echo "$lign" >> $f.done
echo "" > $pwd/dlEc
fi fi
lign=`sed '2,$d' $pwd/urls | tr -d '\n'` #Remove the action from the file
sed -i '1d' $f
#What's next?
lign=`sed '2,$d' $f | tr -d '\n'`
done done
fi
rm /tmp/dlEnCours done
rm /tmp/dlEnCours 2> /dev/null
fi fi

View File

@ -1,12 +1,62 @@
<?php <?php
define("MAIN_DIR", __dir__."/.."); define("MAIN_DIR", __dir__."/..");
if (!empty($_GET["f"]) && is_file(MAIN_DIR."/content/".$_GET["f"])) function get_info($url)
{ {
$filename = MAIN_DIR."/content/".$_GET["f"]; $ec = file(MAIN_DIR."/database",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$nbLign = count($ec);
for ($i = 0; $i < $nbLign; $i++)
{
if ($ec[$i] == $url)
break;
else
{
while ($i < $nbLign && trim($ec[$i]) != "--")
$i++;
}
}
if ($i < $nbLign)
{
$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
return array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename));
}
else
return NULL;
}
$user = "generic";
foreach ($_GET as $k => $t)
{
if (empty($t))
{
$user = $k;
break;
}
}
if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
die ("Le nom d'utilisateur contient des caractères interdits.");
if (isset($_GET["f"]))
{
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
{
$ec = file(MAIN_DIR."/users/".$user.".dlist.done",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
foreach ($ec as $k => $lign)
{
if ($k == $_GET["f"])
{
$musik = get_info($lign);
if (isset($musik) && is_file(MAIN_DIR."/content/".$musik[4]))
{
$filename = MAIN_DIR."/content/".$musik[4];
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"".$_GET["f"]."\""); header("Content-Disposition: attachment; filename=\"".$musik[1].".mp3\"");
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
header('Expires: 0'); header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@ -15,6 +65,9 @@ if (!empty($_GET["f"]) && is_file(MAIN_DIR."/content/".$_GET["f"]))
readfile($filename); readfile($filename);
exit; exit;
} }
else }
}
}
}
die ("Fichier introuvable"); die ("Fichier introuvable");
?> ?>

BIN
htdocs/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -2,44 +2,82 @@
define("MAIN_DIR", __dir__."/.."); define("MAIN_DIR", __dir__."/..");
function get_info($url)
{
$ec = file(MAIN_DIR."/database",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$nbLign = count($ec);
for ($i = 0; $i < $nbLign; $i++)
{
if ($ec[$i] == $url)
break;
else
{
while ($i < $nbLign && trim($ec[$i]) != "--")
$i++;
}
}
if ($i+2 < $nbLign)
{
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename));
}
else
return NULL;
}
header("Content-type: text/html;charset=utf-8"); header("Content-type: text/html;charset=utf-8");
$user = "generic";
foreach ($_GET as $k => $t)
{
if (empty($t))
{
$user = $k;
break;
}
}
if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
die ("Le nom d'utilisateur contient des caractères interdits.");
?> ?>
<DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<title>En avant la musique !</title> <meta charset="UTF-8">
<title>.: Pommultimédia - Online Converter :.</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon">
<meta http-equiv="refresh" content="42"> <meta http-equiv="refresh" content="42">
</head> </head>
<body> <body>
<form method="post" action="?a=add"> <div class="blk">
<input type="hidden" name="url" value="clear"> <h2>Chansons prêtes à être téléchargées</h2>
<h2>Chansons prêtes à être téléchargées <input type="submit" value="Vider cette liste"></h2> <ul><?php
</form>
<ul>
<?php
$dir = MAIN_DIR."/content/"; $dir = MAIN_DIR."/content/";
$musiks = opendir($dir) or die('Erreur');
$ec = file_get_contents(MAIN_DIR."/dlEc"); $someone = false;
$ecD = "téléchargement"; if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
{
$ec = file(MAIN_DIR."/users/".$user.".dlist.done",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
while($entry = @readdir($musiks)) foreach ($ec as $k => $lign)
{ {
if(is_file($dir.'/'.$entry) && preg_match("#^(.*).mp3$#ui", $entry, $out)) $musik = get_info($lign);
if(isset($musik) && is_file($dir.'/'.$musik[4]))
{ {
if (substr($ec,0,strlen($out[1])) == $out[1]) $someone = true;
$ecD = "convertion"; echo '<li><a href="dl.php?'.$user.'&amp;f='.$k.'">'.$musik[1].'</a></li>';
else }
echo '<li><a href="dl.php?f='.rawurlencode($entry).'">'.$out[1].'</a></li>';
} }
} }
closedir($musiks);
?>
</ul>
<h2>Ajouter une chanson à la liste</h2> if (empty($someone))
echo "<h3>Aucun élément dans cette liste</h3>";
?> </ul>
</div>
<div class="blk">
<h2>Ajouter une chanson</h2>
<?php <?php
if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !empty($_SERVER["HTTP_REFERER"]))) || !empty($_GET["url"])) if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !empty($_SERVER["HTTP_REFERER"]))) || !empty($_GET["url"]))
{ {
@ -52,7 +90,7 @@ if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !emp
if ($url == "clear") if ($url == "clear")
{ {
if ($fp = fopen(MAIN_DIR."/urls", "a+")) if ($fp = fopen(MAIN_DIR."/users/".$user.".dlist", "a+"))
{ {
fputs($fp, "clear\n"); fputs($fp, "clear\n");
print "<h3 style=\"color: #00FF00;\">La demande de vidage de la liste a été ajouté à la file d'attente</h3>"; print "<h3 style=\"color: #00FF00;\">La demande de vidage de la liste a été ajouté à la file d'attente</h3>";
@ -61,8 +99,11 @@ if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !emp
elseif (preg_match("#^http://(www.)?youtube.com/watch\?v=([a-zA-Z0-9_-]+)#", $url, $matched)) elseif (preg_match("#^http://(www.)?youtube.com/watch\?v=([a-zA-Z0-9_-]+)#", $url, $matched))
{ {
//Check if the URL isn't already in the file //Check if the URL isn't already in the file
$content = file(MAIN_DIR."/urls",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); if (is_file(MAIN_DIR."/users/".$user.".dlist"))
if (!in_array($matched[0], $content) && $fp = fopen(MAIN_DIR."/urls", "a+")) $content = file(MAIN_DIR."/users/".$user.".dlist",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
else
$content = array();
if (!in_array($matched[0], $content) && $fp = fopen(MAIN_DIR."/users/".$user.".dlist", "a+"))
{ {
fputs($fp, $matched[0]."\n"); fputs($fp, $matched[0]."\n");
print "<h3 style=\"color: #00FF00;\">L'adresse a bien été ajoutée avec succès.</h3>"; print "<h3 style=\"color: #00FF00;\">L'adresse a bien été ajoutée avec succès.</h3>";
@ -72,56 +113,64 @@ if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !emp
print "<h3>L'adresse fournie n'est pas valide !</h3>"; print "<h3>L'adresse fournie n'est pas valide !</h3>";
} }
?> ?>
<form method="post" action="?a=add"> <form method="post" action="?a=add&amp;<?php echo $user; ?>">
<label for="url">Adresse de la chanson à télécharger :</label> <input type="text" name="url" id="url" /> <label for="url">Adresse :</label> <input type="text" name="url" size="50">
<input type="submit" value="Ajouter" /> <input type="submit" value="Ajouter">
</form> </form>
</div>
<div class="blk">
<h2>Chansons en file d'attente</h2>
<form method="post" action="?a=del">
<ul><?php
$someone = false;
if (is_file(MAIN_DIR."/users/".$user.".dlist.ec"))
{
$ec = file(MAIN_DIR."/users/".$user.".dlist.ec",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
<h2>Chansons en cours de téléchargement</h2> if (!empty($ec[0]))
<?php {
$musik = get_info($ec[0]);
if(isset($musik))
{
echo '<div style="text-align: center;"><img src="'.$musik[2].'" alt="Miniature"></div>';
if (strlen($ec) > 1) if (count ($ec) == 1)
echo "<strong>Actuellement en cours de ".$ecD." :</strong> <em>".$ec."</em><br />"; echo "<label>En cours de téléchargement :</label>";
else if (count ($ec) == 2)
echo "<label>En cours de conversion :</label>";
if (!empty($_GET["a"]) && $_GET["a"] == "del") echo $musik[1];
{ $encours = $ec[0];
foreach($_POST as $id => $value) $someone = true;
{
if (preg_match("#^del([a-z0-9]+)$#", $id, $out))
{
$content = file(MAIN_DIR."/urls",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$newlist = array();
for ($i = 0; $i < count($content); $i++)
{
if (sha1($content[$i]) != $out[1])
$newlist[] = $content[$i];
}
file_put_contents(MAIN_DIR."/urls", implode("\n", $newlist)."\n");
print "<h3>La chanson a été retirée de la liste.</h3>";
} }
} }
} }
if (is_file(MAIN_DIR."/users/".$user.".dlist"))
{
$ec = file(MAIN_DIR."/users/".$user.".dlist",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$musiks = file(MAIN_DIR."/urls",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); foreach ($ec as $k => $lign)
if (empty($musiks))
{ {
if (strlen($ec) < 2) if (isset($encours) && $lign == $encours)
echo "La liste de téléchargement est vide."; continue;
}
$someone = true;
$musik = get_info($lign);
if(isset($musik) && is_file($dir.'/'.$musik[4]))
echo '<li>'.$musik[1].'</li>';
else else
{ echo '<li>'.$lign.' <input type="submit" name="del'.sha1($lign).'" value="Retirer de la liste"></li>';
echo '<form method="post" action="?a=del"><ul>';
foreach($musiks as $musik)
{
if ($musik == "clear")
echo '<li>Supprimer les fichiers télécharger';
else
echo '<li><a href="'.$musik.'">'.$musik.'</a>';
echo ' <input type="submit" name="del'.sha1($musik).'" value="Retirer de la liste"></li>';
} }
echo "</ul></form>";
} }
?> if (empty($someone))
echo "<h3>Aucun élément dans cette liste</h3>";
?></ul>
</form>
</div>
<div class="blk">
<h2>Chansons déjà téléchargées</h2>
<h3>Prochainement ...</h3>
</div>
</body> </body>
</html> </html>

166
htdocs/style.css Normal file
View File

@ -0,0 +1,166 @@
body
{
background: url('images/background.jpg');
margin-bottom: 234px;
}
header
{
margin: auto;
width: 999px;
}
header span
{
display: none;
}
header h1
{
background: url('images/logo.png');
height: 312px;
width: 100%;
}
header h2
{
background: url('images/partage.png');
float: right;
height: 92px;
margin: -93px 125px 0 0;
width: 171px;
}
p,ul
{
margin: auto;
text-align: left;
}
#res {
font-size: 80%;
text-align: right;
}
#res ul, #res ul li {
display: inline;
padding-right: 10px;
}
label {
color: #80a92c;
font-weight: bold;
margin-right: 5px;
}
label:hover {
text-decoration: underline;
}
input[type=text], input[type=password], select, textarea {
transition: background 0.75s;
-moz-transition: background 0.75s;
-webkit-transition: background 0.75s;
-o-transition: background 0.75s;
}
input, select, textarea {
background: #558dd4;
border: #2f588b solid 1px;
border-radius: 5px;
margin-top: 5px;
}
input:hover, input:focus, select:hover, select:focus, textarea:hover, textarea:focus {
background: #95cdff;
}
input.erreur, select.erreur {
background: #df0009;
border: #f7000b solid 1px;
}
input.erreur:hover, select.erreur:hover {
background: #ff2029;
}
h1 {
color: #75903b;
text-align: center;
}
h2 {
color: #7f9a48;
}
h3 {
color: #89a355;
}
h4, h5, h6 {
color: #95ae64;
}
form {
text-align: center;
}
fieldset, div#content, ul#list, .blk {
background: #e3e3e3;
border: none;
border-radius: 10px;
box-shadow: 0px 0px 11px #555;
min-height: 50px;
margin: auto;
width: 750px;
}
div.blk {
margin-bottom: 15px;
padding-bottom: 15px;
}
.blk h2 {
background: #88DE66;
border-bottom: solid 2px #208748;
border-radius: inherit;
border-radius: 10px 10px 0 0;
color: #309F60;
text-align: center;
transition: color 1s;
-moz-transition: color 1s;
-webkit-transition: color 1s;
-o-transition: color 1s;
}
.blk:hover h2 {
background: #88DE66;
color: #30609F;
}
.blk h3 {
color: #444;
text-align: center;
font-style: italic;
}
ul#list
{
padding: 10px 10px 10px 20px;
}
div#content {
padding: 5px;
text-align: left;
min-width: 80%;
}
div#content pre {
overflow-x: auto;
}
textarea#content {
height: 200px;
width: 90%;
}
div.answer {
float: right;
font-size: 65%;
font-style: italic;
}
ins
{
color: #00DF22;
}
del
{
color: #DF2200;
}

0
users/users Normal file
View File

4648
youtube-dl Executable file

File diff suppressed because it is too large Load Diff