%PDF- %PDF-
| Direktori : /var/www_old/music/scanned/ |
| Current File : //var/www_old/music/scanned/grab.php |
<?php
function q($query,$assoc=0)
{
// global $queries;
echo $query."<br />\n";
$r = @mysql_query($query);
if( mysql_errno() ) {
$error = 'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$query</VAR>";
echo($error); return FALSE;
}
$queries++;
if( strtolower(substr($query,0,6)) != 'select' ) return array(mysql_affected_rows(),mysql_insert_id());
$count = @mysql_num_rows($r);
if( !$count ) return 0;
if( $count == 1 ) {
if( $assoc ) $f = mysql_fetch_assoc($r);
else $f = mysql_fetch_row($r);
mysql_free_result($r);
if( count($f) == 1 ) {
list($key) = array_keys($f);
return $f[$key];
} else {
$all = array();
$all[] = $f;
return $all;
}
} else {
$all = array();
for( $i = 0; $i < $count; $i++ ) {
if( $assoc ) $f = mysql_fetch_assoc($r);
else $f = mysql_fetch_row($r);
$all[] = $f;
}
mysql_free_result($r);
return $all;
}
}
$text = file_get_contents($_POST['link']);
preg_match_all("#<a name=\"[0-9]+\">([0-9]+\\. )?(.*?)</a></h3>(.*?)(<h3>|<div class=\"thanks\">|<div class=\"note\">)#msi", $text, $matches);
//print_r($matches);
$connection = mysql_connect("localhost", "root", "waritko3");
mysql_select_db("lyrics", $connection);
$max = count($matches[0]);
$ar = q("select id from artist where name like '".str_replace("'", "\\'", trim($_POST['artist']))."'");
if(!$ar)
{
$ar = q("insert into artist(name) values('".str_replace("'", "\\'", trim($_POST['artist']))."')");
$ar = $ar[1];
}
$al = q("insert into album(artist, name) values($ar, '".str_replace("'", "\\'", trim($_POST['album']))."')");
$al = $al[1];
for($i = 0; $i < $max; $i++)
{
$text = str_replace("'", "\\'", trim(str_replace("<br />", "\n", $matches[3][$i])));
$title = str_replace("'", "\\'", $matches[2][$i]);
q("insert into track(album, tracknr, name, text) values($al, $i, '$title', '$text')");
}
mysql_close($connection);
?>