First commit
This commit is contained in:
commit
d299e73fa4
39
dl.sh
Executable file
39
dl.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
pwd=`echo "$0" | sed -e "s/[^\/]*$//"`
|
||||||
|
|
||||||
|
if [ `cat $pwd/urls | wc -l` -gt 0 ] && [ ! -e /tmp/dlEnCours ]; then
|
||||||
|
transmission-remote -asu 10 -as
|
||||||
|
|
||||||
|
touch /tmp/dlEnCours
|
||||||
|
|
||||||
|
lign=`sed '2,$d' $pwd/urls | tr -d '\n'`
|
||||||
|
|
||||||
|
if [ -z "$lign" ]; then
|
||||||
|
sed -i '1d' $pwd/urls
|
||||||
|
lign=`sed '2,$d' $pwd/urls | tr -d '\n'`
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
sed -i '1d' $pwd/urls
|
||||||
|
|
||||||
|
$pwd/youtube-dl --no-progress -c -k -o "$pwd/content/%(title)s.%(ext)s" --extract-audio --audio-format=mp3 "$lign"
|
||||||
|
|
||||||
|
echo "" > $pwd/dlEc
|
||||||
|
fi
|
||||||
|
|
||||||
|
lign=`sed '2,$d' $pwd/urls | tr -d '\n'`
|
||||||
|
done
|
||||||
|
|
||||||
|
rm /tmp/dlEnCours
|
||||||
|
fi
|
20
htdocs/dl.php
Normal file
20
htdocs/dl.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
define("MAIN_DIR", __dir__."/..");
|
||||||
|
|
||||||
|
if (!empty($_GET["f"]) && is_file(MAIN_DIR."/content/".$_GET["f"]))
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
die ("Fichier introuvable");
|
||||||
|
?>
|
127
htdocs/index.php
Normal file
127
htdocs/index.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
define("MAIN_DIR", __dir__."/..");
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Ajouter une chanson à la liste</h2>
|
||||||
|
<?php
|
||||||
|
if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !empty($_SERVER["HTTP_REFERER"]))) || !empty($_GET["url"]))
|
||||||
|
{
|
||||||
|
if (!empty($_GET["url"]))
|
||||||
|
$url = $_GET["url"];
|
||||||
|
elseif (!empty($_POST["url"]))
|
||||||
|
$url = $_POST["url"];
|
||||||
|
else
|
||||||
|
$url = $_SERVER["HTTP_REFERER"];
|
||||||
|
|
||||||
|
if ($url == "clear")
|
||||||
|
{
|
||||||
|
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>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
$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>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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>
|
||||||
|
|
||||||
|
<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")
|
||||||
|
{
|
||||||
|
foreach($_POST as $id => $value)
|
||||||
|
{
|
||||||
|
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>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$musiks = file(MAIN_DIR."/urls",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||||
|
if (empty($musiks))
|
||||||
|
{
|
||||||
|
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>";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user