2011-04-01 06:37:23 +00:00
#!/opt/local/bin/php
< ? php
chdir ( '..' );
require_once 'common.php' ;
2011-04-02 14:57:17 +00:00
define ( 'VKTIMEOUT' , 1 );
2011-04-01 06:37:23 +00:00
$db = Db :: getInstance ();
$vk = new Vkontakte ();
$continue = true ;
while ( $continue ) {
2011-04-02 14:57:17 +00:00
$queue = $db -> getRows ( $db -> q ( " SELECT * FROM beathaven.queue WHERE status=0 OR status=2 ORDER BY priority DESC, status ASC, times_failed ASC LIMIT 100 " ));
2011-04-01 06:37:23 +00:00
if ( ! $queue || count ( $queue ) == 0 ) {
$continue = false ;
} else {
foreach ( $queue as $t ) {
echo " # { $t [ 'track_id' ] } { $t [ 'track_title' ] } \n " ;
echo " Loading file list: " ;
2011-04-01 09:29:04 +00:00
$t1 = microtime ( true );
2011-04-01 06:37:23 +00:00
$vk -> parse ( $t [ 'track_title' ]);
2011-04-02 14:57:17 +00:00
$vk -> parseHtml ();
2011-04-01 06:37:23 +00:00
$files = $vk -> getFiles ();
if ( $files && count ( $files ) > 0 ) {
echo " OK ( " . count ( $files ) . " ) \n " ;
$tmp = explode ( ' - ' , $t [ 'track_title' ]); $artist_name = $tmp [ 0 ]; unset ( $tmp [ 0 ]); $track_name = implode ( ' - ' , $tmp );
$files = VkontakteMP3 :: check ( $files , $artist_name , $track_name , $t [ 'track_length' ]);
BeatDB :: set ( $t [ 'track_id' ], $files );
echo " Good files: " . count ( $files ) . " \n \n " ;
$db -> q ( " UPDATE beathaven.queue SET status=1 WHERE track_id= " . $t [ 'track_id' ]);
2011-04-02 14:57:17 +00:00
@ unlink ( '/www/parser_data/html/' . $t [ 'track_id' ] . '.html' );
2011-04-01 06:37:23 +00:00
} else {
2011-04-02 14:57:17 +00:00
file_put_contents ( '/www/parser_data/html/' . $t [ 'track_id' ] . '.html' , $vk -> getHtml ());
2011-04-01 06:37:23 +00:00
echo " FAILED \n \n " ;
2011-04-01 12:07:09 +00:00
$db -> q ( " UPDATE beathaven.queue SET status = 2, times_failed = times_failed + 1 WHERE track_id= " . $t [ 'track_id' ]);
2011-04-01 06:37:23 +00:00
}
2011-04-01 09:29:04 +00:00
$t2 = microtime ( true );
2011-04-02 14:57:17 +00:00
if ( $t2 - $t1 < VKTIMEOUT ) {
sleep ( ceil ( VKTIMEOUT - ( $t2 - $t1 )));
2011-04-01 09:29:04 +00:00
}
2011-04-01 06:37:23 +00:00
}
2011-04-02 14:57:17 +00:00
sleep ( 5 );
2011-04-01 06:37:23 +00:00
}
2011-04-01 09:29:04 +00:00
}