Check size before download
Add common.php with common functions
This commit is contained in:
parent
30cd0ba548
commit
f8d59cca32
8 changed files with 455 additions and 308 deletions
|
|
@ -2,48 +2,9 @@
|
|||
|
||||
define("MAIN_DIR", __dir__."/..");
|
||||
|
||||
function get_info($url)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/database",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
$nbLign = count($ec);
|
||||
require(MAIN_DIR."/common.php");
|
||||
|
||||
for ($i = 0; $i < $nbLign; $i++)
|
||||
{
|
||||
if ($ec[$i] == $url)
|
||||
break;
|
||||
else
|
||||
{
|
||||
while ($i < $nbLign && trim($ec[$i]) != "--")
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i+2 < $nbLign)
|
||||
{
|
||||
if ($ec[$i+3] == "-- ")
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+2]);
|
||||
else
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
@$filenameogg = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.ogg', $filename);
|
||||
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename), trim($filenameogg));
|
||||
}
|
||||
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.");
|
||||
|
||||
header("Content-type: application/atom+xml;charset=utf-8");
|
||||
//header("Content-type: application/atom+xml;charset=utf-8");
|
||||
|
||||
$xml = new DOMDocument('1.0', 'UTF-8');
|
||||
$xml->formatOutput = true;
|
||||
|
|
@ -70,33 +31,32 @@ $xml_feed->appendChild($xml_feed_rights);
|
|||
$xml_feed->appendChild($xml_feed_author);
|
||||
|
||||
$files = array();
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
||||
|
||||
$ec = get_dlmusiks($user);
|
||||
$cnt = 0;
|
||||
for ($i = count ($ec) - 1; $i >= 0 && $cnt < 10; $i--, $cnt++)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist.done",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
$cnt = 0;
|
||||
for ($i = count ($ec) - 1; $i >= 0 && $cnt < 10; $i--, $cnt++)
|
||||
{
|
||||
$musik = get_info($ec[$i]);
|
||||
if (isset($musik) && (is_file (MAIN_DIR."/content/".$musik[4]) || is_file (MAIN_DIR."/content/".$musik[5])))
|
||||
$musik = $ec[$i];
|
||||
if (isset($musik) && (is_file (MAIN_DIR."/content/".$musik["mp3"]) || is_file (MAIN_DIR."/content/".$musik["ogg"])))
|
||||
{
|
||||
$xml_entry = $xml->createElement("entry");
|
||||
$xml_entry->appendChild($xml->createElement("id", "http://musik.p0m.fr/".$musik[0]));
|
||||
@$xml_entry->appendChild($xml->createElement("title", strip_tags($musik[1])));
|
||||
if (is_file (MAIN_DIR."/content/".$musik[5]))
|
||||
$xml_entry->appendChild($xml->createElement("updated", date('c', filectime(MAIN_DIR."/content/".$musik[5]))));
|
||||
$xml_entry->appendChild($xml->createElement("id", "http://musik.p0m.fr/".$musik["filename"]));
|
||||
@$xml_entry->appendChild($xml->createElement("title", strip_tags($musik["title"])));
|
||||
if (is_file (MAIN_DIR."/content/".$musik["ogg"]))
|
||||
$xml_entry->appendChild($xml->createElement("updated", date('c', filectime(MAIN_DIR."/content/".$musik["ogg"]))));
|
||||
else
|
||||
$xml_entry->appendChild($xml->createElement("updated", date('c', filectime(MAIN_DIR."/content/".$musik[4]))));
|
||||
$xml_entry->appendChild($xml->createElement("updated", date('c', filectime(MAIN_DIR."/content/".$musik["mp3"]))));
|
||||
|
||||
$xml_entry_summary = $xml->createElement("summary", htmlentities(utf8_decode($musik[2])));
|
||||
$xml_entry_summary = $xml->createElement("summary", htmlentities(utf8_decode($musik["title"])));
|
||||
$xml_entry_summary->setAttribute("type", "html");
|
||||
|
||||
$xml_entry_enclosure = $xml_entry->appendChild($xml->createElement("link"));
|
||||
$xml_entry_enclosure->setAttribute("href", "http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"]).urlencode("dl.php?".$user."&f=".$i));
|
||||
$xml_entry_enclosure->setAttribute("href", "http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"]).urlencode("dl.php?".$user."&s&f=".$i));
|
||||
$xml_entry_enclosure->setAttribute("rel", "enclosure");
|
||||
$xml_entry->appendChild($xml_entry_enclosure);
|
||||
|
||||
$xml_entry_enclosure = $xml_entry->appendChild($xml->createElement("link"));
|
||||
$xml_entry_enclosure->setAttribute("href", $musik[0]);
|
||||
$xml_entry_enclosure->setAttribute("href", $musik["url"]);
|
||||
$xml_entry_enclosure->setAttribute("rel", "via");
|
||||
$xml_entry->appendChild($xml_entry_enclosure);
|
||||
|
||||
|
|
@ -109,7 +69,7 @@ if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
|||
$xml_feed->appendChild($xml_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$xml->appendChild($xml_feed);
|
||||
|
||||
|
|
|
|||
BIN
htdocs/default.jpg
Normal file
BIN
htdocs/default.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
104
htdocs/dl.php
104
htdocs/dl.php
|
|
@ -1,80 +1,54 @@
|
|||
<?php
|
||||
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)
|
||||
{
|
||||
if ($ec[$i+3] == "-- ")
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+2]);
|
||||
else
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
@$filenameogg = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.ogg', $filename);
|
||||
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename), trim($filenameogg));
|
||||
}
|
||||
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.");
|
||||
require(MAIN_DIR."/common.php");
|
||||
|
||||
if (isset($_GET["s"]))
|
||||
$stream = "inline";
|
||||
else
|
||||
$stream = "attachment";
|
||||
|
||||
if (isset($_GET["f"]))
|
||||
{
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
||||
$musiks = get_dlmusiks($user);
|
||||
|
||||
foreach ($musiks as $k => $lign)
|
||||
{
|
||||
$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"])
|
||||
{
|
||||
if ($k == $_GET["f"])
|
||||
$musik = get_info($lign["url"]);
|
||||
if (isset($musik) && (is_file(MAIN_DIR."/content/".$musik["mp3"])
|
||||
|| is_file(MAIN_DIR."/content/".$musik["ogg"])))
|
||||
{
|
||||
$musik = get_info($lign);
|
||||
if (isset($musik) && (is_file(MAIN_DIR."/content/".$musik[4]) || is_file(MAIN_DIR."/content/".$musik[5])))
|
||||
if (is_file(MAIN_DIR."/content/".$musik["ogg"]))
|
||||
{
|
||||
if (is_file(MAIN_DIR."/content/".$musik[5]))
|
||||
$filename = MAIN_DIR."/content/".$musik[5];
|
||||
else
|
||||
$filename = MAIN_DIR."/content/".$musik[4];
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
if (is_file(MAIN_DIR."/content/".$musik[5]))
|
||||
header("Content-Disposition: attachment; filename=\"".$musik[1].".ogg\"");
|
||||
else
|
||||
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;
|
||||
$filename = MAIN_DIR."/content/".$musik["ogg"];
|
||||
$ext = ".ogg";
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = MAIN_DIR."/content/".$musik["mp3"];
|
||||
$ext = ".mp3";
|
||||
}
|
||||
|
||||
//Mark file as dled
|
||||
mark_as_dled($user, $k);
|
||||
|
||||
if (is_file(MAIN_DIR."/content/".$musik["ogg"]))
|
||||
$fname = MAIN_DIR."/content/".$musik["ogg"];
|
||||
else
|
||||
$fname = MAIN_DIR."/content/".$musik["mp3"];
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: '.mime_content_type($filename));
|
||||
header("Content-Disposition: ".$stream."; filename=\"".addslashes($musik["title"]).$ext."\"");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
173
htdocs/index.php
173
htdocs/index.php
|
|
@ -2,48 +2,9 @@
|
|||
|
||||
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)
|
||||
{
|
||||
if ($ec[$i+3] == "-- ")
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+2]);
|
||||
else
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
@$filenameogg = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.ogg', $filename);
|
||||
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename), trim($filenameogg));
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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.");
|
||||
require(MAIN_DIR."/common.php");
|
||||
?>
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
|
@ -57,33 +18,23 @@ if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
|
|||
<body>
|
||||
<div class="blk">
|
||||
<h2>Chansons prêtes à être téléchargées</h2>
|
||||
<ul><?php
|
||||
$dir = MAIN_DIR."/content/";
|
||||
|
||||
$someone = false;
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
||||
<div class="dled"><?php
|
||||
$list_ready = get_user_ready($user);
|
||||
if (count($list_ready))
|
||||
{
|
||||
$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]) || is_file($dir.'/'.$musik[5])))
|
||||
{
|
||||
$someone = true;
|
||||
echo '<li><a href="dl.php?'.$user.'&f='.$k.'">'.$musik[1].'</a></li>';
|
||||
}
|
||||
}
|
||||
foreach ($list_ready as $m)
|
||||
format_clip($user, $m);
|
||||
}
|
||||
|
||||
if (empty($someone))
|
||||
echo "<h3>Aucun élément dans cette liste</h3>";
|
||||
?> </ul>
|
||||
else
|
||||
echo "<h3>Pas de nouvelle chanson à télécharger</h3>";
|
||||
?> </div>
|
||||
</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"];
|
||||
|
|
@ -91,35 +42,7 @@ if (empty($someone))
|
|||
$url = $_POST["url"];
|
||||
else
|
||||
$url = $_SERVER["HTTP_REFERER"];
|
||||
|
||||
if ($url == "clear")
|
||||
{
|
||||
if ($fp = fopen(MAIN_DIR."/users/".$user.".dlist", "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)
|
||||
|| preg_match("#^http://youtu.be/([a-zA-Z0-9_-]+)#", $url, $matched)
|
||||
|| preg_match("#^http://(www.)?dailymotion.com/video/([a-zA-Z0-9_-]+)#", $url, $matched)
|
||||
|| preg_match("#^http://(www.)?vimeo.com/([0-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+"))
|
||||
{
|
||||
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>";
|
||||
add_url($user, $url);
|
||||
}
|
||||
?>
|
||||
<form method="post" action="?a=add&<?php echo $user; ?>">
|
||||
|
|
@ -131,55 +54,33 @@ if (empty($someone))
|
|||
<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"))
|
||||
$ecdl = get_ecdl($user);
|
||||
foreach($ecdl as $lign)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist.ec",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
if (!empty($ec[0]))
|
||||
{
|
||||
$musik = get_info($ec[0]);
|
||||
if(isset($musik))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
echo '<li>'.$lign.' <input type="submit" name="del'.
|
||||
sha1($lign).'" value="Retirer de la liste"></li>';
|
||||
}
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist"))
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($ec as $k => $lign)
|
||||
{
|
||||
if (isset($encours) && $lign == $encours)
|
||||
continue;
|
||||
|
||||
$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))
|
||||
if (empty($ecdl))
|
||||
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>
|
||||
</div><?php
|
||||
$list_archives = get_user_archives($user);
|
||||
if (count($list_archives))
|
||||
{
|
||||
print '<div class="blk"><h2>Chansons déjà téléchargées</h2><div class="dled">';
|
||||
$last = 0;
|
||||
foreach ($list_archives as $m)
|
||||
{
|
||||
$ths = intval($m["dled"] / 21600);
|
||||
if ($last < $ths)
|
||||
{
|
||||
$last = $ths;
|
||||
echo "<h4>".strftime("%a. %d %b %G - %H:%M", $m["dled"])."</h4>";
|
||||
}
|
||||
format_clip($user, $m);
|
||||
}
|
||||
print '</div></div>';
|
||||
}
|
||||
?></body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ label:hover {
|
|||
input[type=text], input[type=password], select, textarea {
|
||||
transition: background 0.75s;
|
||||
-moz-transition: background 0.75s;
|
||||
-webkit-transition: background 0.75s;
|
||||
-webkit-transition: background 0.75s;
|
||||
-o-transition: background 0.75s;
|
||||
}
|
||||
input, select, textarea {
|
||||
|
|
@ -107,6 +107,10 @@ div.blk {
|
|||
margin-bottom: 15px;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
div.blk .dled {
|
||||
margin-top: -15px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.blk h2 {
|
||||
background: #88DE66;
|
||||
|
|
@ -117,7 +121,7 @@ div.blk {
|
|||
text-align: center;
|
||||
transition: color 1s;
|
||||
-moz-transition: color 1s;
|
||||
-webkit-transition: color 1s;
|
||||
-webkit-transition: color 1s;
|
||||
-o-transition: color 1s;
|
||||
}
|
||||
.blk:hover h2 {
|
||||
|
|
@ -163,4 +167,30 @@ ins
|
|||
del
|
||||
{
|
||||
color: #DF2200;
|
||||
}
|
||||
}
|
||||
|
||||
div.clip
|
||||
{
|
||||
display: inline-block;
|
||||
margin: 9px 1.5px;
|
||||
text-align: center;
|
||||
width: 19%;
|
||||
}
|
||||
div.clip a.bot
|
||||
{
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
div.clip a.tp
|
||||
{
|
||||
color: white;
|
||||
display: none;
|
||||
margin-left: 12px;
|
||||
position: absolute;
|
||||
font-weight: bold;
|
||||
}
|
||||
div.clip:hover a.tp
|
||||
{
|
||||
display: block;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue