Parser fix & stats page
This commit is contained in:
parent
3bca154729
commit
f5dba21b56
|
@ -10,13 +10,14 @@ $vk = new Vkontakte();
|
|||
|
||||
$continue = true;
|
||||
while ($continue) {
|
||||
$queue = $db->getRows($db->q("SELECT * FROM beathaven.queue WHERE status=0 LIMIT 100"));
|
||||
$queue = $db->getRows($db->q("SELECT * FROM beathaven.queue WHERE status=2 LIMIT 100"));
|
||||
if (!$queue || count($queue) == 0) {
|
||||
$continue = false;
|
||||
} else {
|
||||
foreach ($queue as $t) {
|
||||
echo "#{$t['track_id']} {$t['track_title']}\n";
|
||||
echo "Loading file list: ";
|
||||
$t1 = microtime(true);
|
||||
$vk->parse($t['track_title']);
|
||||
$files = $vk->getFiles();
|
||||
if ($files && count($files) > 0) {
|
||||
|
@ -30,6 +31,10 @@ while ($continue) {
|
|||
echo "FAILED\n\n";
|
||||
$db->q("UPDATE beathaven.queue SET status=2 WHERE track_id=". $t['track_id']);
|
||||
}
|
||||
$t2 = microtime(true);
|
||||
if ($t2 - $t1 < 5) {
|
||||
sleep(ceil(5 - ($t2 - $t1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,73 +1,15 @@
|
|||
<?php
|
||||
|
||||
date_default_timezone_set('Europe/Moscow');
|
||||
require_once 'common.php';
|
||||
|
||||
$artist = 'Foo Fighters';
|
||||
if (isset($_GET['q']) && $_GET['q'] != '') {
|
||||
$q = $_GET['q'];
|
||||
} else {
|
||||
$q = $artist;
|
||||
$db = Db::getInstance();
|
||||
|
||||
$rows = $db->getRows($db->q("SELECT status, count(*) as cnt FROM beathaven.queue GROUP BY status"));
|
||||
|
||||
$info = array_fill(0, 3, array());
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$info[$row['status']] = $row['cnt'];
|
||||
}
|
||||
|
||||
$c = pg_connect('host=localhost port=5432 dbname=beatheaven user=postgres password=password');
|
||||
|
||||
$t = pg_query($c, "SELECT * FROM beatheaven.bh_artist WHERE name = '{$q}'");
|
||||
$artist = pg_fetch_assoc($t);
|
||||
|
||||
$t = pg_query($c, "SELECT * FROM beatheaven.bh_release_group WHERE artist_id = {$artist['id']} AND type = 1");
|
||||
$release_groups = array();
|
||||
$release_group_ids = array();
|
||||
while ($row = pg_fetch_assoc($t)) {
|
||||
$row['releases'] = array();
|
||||
$release_groups[$row['id']] = $row;
|
||||
$release_group_ids[] = $row['id'];
|
||||
}
|
||||
|
||||
$t = pg_query($c, "SELECT * FROM beatheaven.bh_release WHERE release_group IN (". implode(',', $release_group_ids) .") AND type=1 ORDER BY date");
|
||||
while ($row = pg_fetch_assoc($t)) {
|
||||
$row['tracks'] = array();
|
||||
$release_groups[$row['release_group']]['releases'][$row['id']] = $row;
|
||||
$t1 = pg_query($c, "SELECT * FROM beatheaven.bh_track WHERE release_id = '{$row['id']}' ORDER BY position");
|
||||
while ($row1 = pg_fetch_assoc($t1)) {
|
||||
$release_groups[$row['release_group']]['releases'][$row['id']]['tracks'][$row1['position']] = $row1;
|
||||
}
|
||||
}
|
||||
|
||||
usort($release_groups, function($a, $b){
|
||||
return strtotime($a['year']) > strtotime($b['year']);
|
||||
});
|
||||
|
||||
$artist['albums'] = array();
|
||||
while(list( $i, $rg ) = each($release_groups)) {
|
||||
$t_list = array();
|
||||
$b_list = array();
|
||||
$tracks = array();
|
||||
$bonus = array();
|
||||
|
||||
$r = current($rg['releases']);
|
||||
if (count($r['tracks']) > 0) {
|
||||
while(list( $j, $t ) = each($r['tracks'])) if ($t['name'] != '[silence]') {
|
||||
$t_list[] = strtolower($t['name']);
|
||||
$tracks[] = array('id' => $t['id'], 'name' => $t['name'], 'duration' => round($t['length'] / 1000));
|
||||
}
|
||||
|
||||
while(list( $j, $r ) = each($rg['releases'])) {
|
||||
while(list( $k, $t ) = each($r['tracks'])) if ($t['name'] != '[silence]') {
|
||||
if (!in_array(strtolower($t['name']), $t_list) && !in_array(strtolower($t['name']), $b_list)) {
|
||||
$bonus[] = array('id' => $t['id'], 'name' => $t['name'], 'duration' => round($t['length'] / 1000));
|
||||
$b_list[] = strtolower($t['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$artist['albums'][] = array(
|
||||
'name' => $rg['name'],
|
||||
'year' => $rg['year'],
|
||||
'tracks' => $tracks,
|
||||
'bonus' => $bonus
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
include 'tpl/index.php';
|
||||
print_r($info);
|
||||
|
|
Loading…
Reference in New Issue