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

61
dl.sh
View File

@ -2,38 +2,47 @@
pwd=`echo "$0" | sed -e "s/[^\/]*$//"`
if [ `cat $pwd/urls | wc -l` -gt 0 ] && [ ! -e /tmp/dlEnCours ]; then
transmission-remote -asu 10 -as
# 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
touch /tmp/dlEnCours
touch /tmp/dlEnCours
lign=`sed '2,$d' $f | tr -d '\n'`
lign=`sed '2,$d' $pwd/urls | tr -d '\n'`
while [ -n "$lign" ] && [ `cat $f | wc -l` -gt 0 ]
do
if [ -z "$lign" ]; then
sed -i '1d' $f
lign=`sed '2,$d' $f | tr -d '\n'`
fi
if [ -z "$lign" ]; then
sed -i '1d' $pwd/urls
lign=`sed '2,$d' $pwd/urls | tr -d '\n'`
fi
echo "Action: $lign"
if [ "$lign" = "clear" ]; then
echo "-- " >> $f.done
transmission-remote -AS
else
echo "$lign" >> $pwd/database
$pwd/youtube-dl --get-title --get-thumbnail --get-filename "$lign" >> $pwd/database
echo "-- " >> $pwd/database
while [ -n "$lign" ] && [ `cat $pwd/urls | wc -l` -gt 0 ]
do
echo "Action: $lign"
if [ "$lign" = "clear" ]; then
sed -i '1d' $pwd/urls
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
else
$pwd/youtube-dl -e $lign > $pwd/dlEc
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
sed -i '1d' $pwd/urls
echo "$lign" >> $f.done
fi
$pwd/youtube-dl --no-progress -c -k -o "$pwd/content/%(title)s.%(ext)s" --extract-audio --audio-format=mp3 "$lign"
#Remove the action from the file
sed -i '1d' $f
echo "" > $pwd/dlEc
fi
lign=`sed '2,$d' $pwd/urls | tr -d '\n'`
#What's next?
lign=`sed '2,$d' $f | tr -d '\n'`
done
fi
done
rm /tmp/dlEnCours
rm /tmp/dlEnCours 2> /dev/null
fi

View File

@ -1,20 +1,73 @@
<?php
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"];
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"".$_GET["f"]."\"");
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($filename));
readfile($filename);
exit;
$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;
}
else
die ("Fichier introuvable");
$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-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"".$musik[1].".mp3\"");
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($filename));
readfile($filename);
exit;
}
}
}
}
}
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,46 +2,84 @@
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");
?>
<DOCTYPE html>
<html>
<head>
<title>En avant la musique !</title>
<meta http-equiv="refresh" content="42">
</head>
<body>
<form method="post" action="?a=add">
<input type="hidden" name="url" value="clear">
<h2>Chansons prêtes à être téléchargées <input type="submit" value="Vider cette liste"></h2>
</form>
<ul>
<?php
$dir = MAIN_DIR."/content/";
$musiks = opendir($dir) or die('Erreur');
$ec = file_get_contents(MAIN_DIR."/dlEc");
$ecD = "téléchargement";
while($entry = @readdir($musiks))
$user = "generic";
foreach ($_GET as $k => $t)
{
if (empty($t))
{
if(is_file($dir.'/'.$entry) && preg_match("#^(.*).mp3$#ui", $entry, $out))
{
if (substr($ec,0,strlen($out[1])) == $out[1])
$ecD = "convertion";
else
echo '<li><a href="dl.php?f='.rawurlencode($entry).'">'.$out[1].'</a></li>';
}
}
closedir($musiks);
$user = $k;
break;
}
}
if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
die ("Le nom d'utilisateur contient des caractères interdits.");
?>
</ul>
<!doctype html>
<html>
<head>
<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">
</head>
<body>
<div class="blk">
<h2>Chansons prêtes à être téléchargées</h2>
<ul><?php
$dir = MAIN_DIR."/content/";
<h2>Ajouter une chanson à la liste</h2>
$someone = false;
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)
{
$musik = get_info($lign);
if(isset($musik) && is_file($dir.'/'.$musik[4]))
{
$someone = true;
echo '<li><a href="dl.php?'.$user.'&amp;f='.$k.'">'.$musik[1].'</a></li>';
}
}
}
if (empty($someone))
echo "<h3>Aucun élément dans cette liste</h3>";
?> </ul>
</div>
<div class="blk">
<h2>Ajouter une chanson</h2>
<?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"]))
{
if (!empty($_GET["url"]))
$url = $_GET["url"];
@ -51,77 +89,88 @@ if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !emp
$url = $_SERVER["HTTP_REFERER"];
if ($url == "clear")
{
if ($fp = fopen(MAIN_DIR."/users/".$user.".dlist", "a+"))
{
if ($fp = fopen(MAIN_DIR."/urls", "a+"))
{
fputs($fp, "clear\n");
print "<h3 style=\"color: #00FF00;\">La demande de vidage de la liste a été ajouté à la file d'attente</h3>";
}
fputs($fp, "clear\n");
print "<h3 style=\"color: #00FF00;\">La demande de vidage de la liste a été ajouté à la file d'attente</h3>";
}
}
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
if (is_file(MAIN_DIR."/users/".$user.".dlist"))
$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+"))
{
//Check if the URL isn't already in the file
$content = file(MAIN_DIR."/urls",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
if (!in_array($matched[0], $content) && $fp = fopen(MAIN_DIR."/urls", "a+"))
{
fputs($fp, $matched[0]."\n");
print "<h3 style=\"color: #00FF00;\">L'adresse a bien été ajoutée avec succès.</h3>";
}
fputs($fp, $matched[0]."\n");
print "<h3 style=\"color: #00FF00;\">L'adresse a bien été ajoutée avec succès.</h3>";
}
}
else
print "<h3>L'adresse fournie n'est pas valide !</h3>";
}
?>
<form method="post" action="?a=add">
<label for="url">Adresse de la chanson à télécharger :</label> <input type="text" name="url" id="url" />
<input type="submit" value="Ajouter" />
</form>
<form method="post" action="?a=add&amp;<?php echo $user; ?>">
<label for="url">Adresse :</label> <input type="text" name="url" size="50">
<input type="submit" value="Ajouter">
</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>
<?php
if (strlen($ec) > 1)
echo "<strong>Actuellement en cours de ".$ecD." :</strong> <em>".$ec."</em><br />";
if (!empty($_GET["a"]) && $_GET["a"] == "del")
if (!empty($ec[0]))
{
foreach($_POST as $id => $value)
$musik = get_info($ec[0]);
if(isset($musik))
{
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>";
}
echo '<div style="text-align: center;"><img src="'.$musik[2].'" alt="Miniature"></div>';
if (count ($ec) == 1)
echo "<label>En cours de téléchargement :</label>";
else if (count ($ec) == 2)
echo "<label>En cours de conversion :</label>";
echo $musik[1];
$encours = $ec[0];
$someone = true;
}
}
}
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);
if (empty($musiks))
foreach ($ec as $k => $lign)
{
if (strlen($ec) < 2)
echo "La liste de téléchargement est vide.";
}
else
{
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 (isset($encours) && $lign == $encours)
continue;
?>
</body>
$someone = true;
$musik = get_info($lign);
if(isset($musik) && is_file($dir.'/'.$musik[4]))
echo '<li>'.$musik[1].'</li>';
else
echo '<li>'.$lign.' <input type="submit" name="del'.sha1($lign).'" value="Retirer de la liste"></li>';
}
}
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>
</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