når den skal parse en playlist fil, skriver den VED ALLE POSTER at det allerede eksitster!
Nu har jeg følgende kode:
<?php
set_time_limit ( 999 );
/* Can be located anyway (also as an URL) */
$playlist_file = "upload/$_GET[file]";
/* DON'T CHANGE ANYTHING BELOW */
if (!is_file($playlist_file))
die("An internal error occured. <b>File not found!</b>");
function parse_entry($values) {
for ($i=0; $i < count($values); $i++)
$tracks[$values[$i]["tag"]] = $values[$i]["value"];
return $tracks;
}
function parse_playlist($playlist) {
global $dropoff;
$data = implode('',file($playlist));
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($xml_parser,$data,$vals,$index);
xml_parser_free($xml_parser);
foreach ($index as $key=>$val) {
if ($key == "entry") {
$ranges = $val;
for ($i=0; $i < count($ranges); $i+=2) {
$offset = $ranges[$i] + 1;
$len = $ranges[$i + 1] - $offset;
$list[] = parse_entry(array_slice($vals, $offset, $len));
}
} else continue;
}
return $list;
}
$playlist = parse_playlist($playlist_file);
$unknown = 0;
function get_total_secs() {
global $playlist, $unknown;
$secs = 0;
foreach($playlist as $id => $track)
if (isset($track['Length']))
$secs += $track['Length']/1000;
else
$unknown++;
return $secs;
}
function get_secs($secs) {
$secs -= get_hours($secs)*3600;
while ($secs >= 60) $secs -= 60;
return floor($secs);
}
function get_min($secs) {
$secs -= get_hours($secs)*3600;
$min = 0;
while ($secs >= 60) {
$secs -= 60;
$min++;
}
return floor($min);
}
function get_hours($secs) {
$hours = 0;
while ($secs >= 3600) {
$secs -= 3600;
$hours++;
}
return floor($hours);
}
function get_length($secs) {
return sprintf("%s%s%s"
,(get_hours($secs) != 0) ? get_hours($secs) .":" : ""
,(get_min($secs) != 0) ? get_min($secs) .":" : ""
,get_secs($secs)
);
}
// TILFOEJ TIL DATABASE-FUNKTIONER
// TAK TIL WEBCAFE.DK OG #PHP PAA QUAKENET!
function aabn_forbindelse_og_vaelgdb() {
$server = "localhost";
$bruger = "root";
$kodeord = "root";
$database = "pilip";
if (!mysql_connect("$server","$bruger","$kodeord")) {
udskriv_fejl("Could not make connection to MySQL database!");
}
if(!mysql_select_db("$database")) {
udskriv_fejl("Cound not select database: $database");
}
}
function sql_spoerg_og_faa_svar($query) {
$resultat = mysql_query($query);
if(!$resultat) {
udskriv_fejl("Could not execute: <em>$query</em>");
}
while($raekke = mysql_fetch_array($resultat)) {
$resultat_array[] = $raekke;
}
return $resultat_array;
}
function sql_spoerg($query) {
$resultat = mysql_query($query);
if(!$resultat) {
udskriv_fejl("Could not execute: <em>$query</em>");
}
}
function luk_forbindelse() {
if(!mysql_close()) {
udskriv_fejl("Could not close MySQL database connection!");
}
}
function udskriv_fejl($fejl) {
echo "<p>$fejl";
if ($mysql_fejl = mysql_error()) {
echo "<br>The error is: <em>$mysql_fejl</em>";
}
exit;
}
function addentry($artist, $track, $ip) {
$ip = $_SERVER[REMOTE_ADDR];
$sql = "insert into numre(artist,track,ip)
values('$artist','$track','$ip')";
aabn_forbindelse_og_vaelgdb();
sql_spoerg($sql);
luk_forbindelse();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.0 Transitional//EN">
<html>
<head>
<title>Pilip.dk Playlist Parser</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<blockquote>
<ol>
<font color="#000000" size="2" face="verdana"><small>
<?
$added = "0";
$failed = "0";
foreach($playlist as $id => $track) {
echo "<li>";
// echo $track['Name'];
echo "<b>";
$arr = explode(" - ", $track['Name']);
echo $arr[count($arr) - 2];
$toeren =$arr[count($arr) - 2];
echo " - ";
echo $arr[count($arr) - 1];
$etteren = $arr[count($arr) - 1];
echo "</b>";
// if (eksisterer($arr[count($arr) - 2]) && $arr[count($arr) - 1])) == "true") {
$tjek = mysql_query("SELECT * FROM tabel WHERE artist = '$artist' and track = '$track'");
if($tjek) { addentry(addslashes($arr[count($arr) - 2]),addslashes($arr[count($arr) - 1]),$_SERVER["REMOTE_ADDR"]);
echo "<br><font color=#008000><b>Success: added!</b></font><br>";
$added++;
} else {
echo "<br><font color=#990000>Error: Track already added by another user!</font><br>";
$failed++;
}
// if(!mysql_num_rows($tjek)) { addentry(addslashes($arr[count($arr) - 2]),addslashes($arr[count($arr) - 1]),$_SERVER["REMOTE_ADDR"]);}
// else{}
// echo "<font color=#008000><b>Success: added!</b>";
// } else {
// echo "<font color=#990000><b>Error: Track already added by another user!</b>";
// }
if (isset($_GET['duration']) && $_GET['duration'] == 'show') {
echo " <strong>[ ";
if (isset($track['Length'])) echo get_length($track['Length']/1000);
else echo "<font color=\"#000000\">N/A</font>";
echo " ]</strong>";
}
echo "</li>\n";
}
// $tjek = "select * from numre where artist = 'Baha Men' and track = 'Who Let The Dogs Out'";
// aabn_forbindelse_og_vaelgdb();
// $resultat = sql_spoerg($tjek);
// echo count($resultat);
if (file_exists($playlist_file)) {
unlink("$playlist_file");
}
echo "<br><br><font size=3>Your playlist was successfully removed from the tempoary directory!";
?>
</small></font>
</ol>
</blockquote><font face="verdana" color="#000000" size="3"><b><?
echo "$added tracks added! - $failed tracks was NOT added (already added by another user!)";
?></b></font><br><br><br><font face="verdana" color="#808080" size="1">
Playlist-parser powered by Tom Sommer Networks,
www.tsn.dk - THANKS!
</body>
</html>