<?php

date_default_timezone_set('Europe/Moscow');

chdir('..');
require_once 'common.php';
Config::loadFile('app', 'config/app.ini');

$artist_name = 'Foo Fighters';
if (isset($_GET['q']) && $_GET['q'] != '') {
	$artist_name = $q = $_GET['q'];
} else {
	$q = $artist_name;
}

$a_model = Model::factory('musicbrainz', 'Artist');
$rg_model = Model::factory('musicbrainz', 'ReleaseGroup');
$r_model = Model::factory('musicbrainz', 'Release');
$t_model = Model::factory('musicbrainz', 'Track');

$artist_id = $a_model->getId($artist_name);

if (!$artist_id) {
	echo "Bad artist name!\n\n\n"; die;
}

$albums = $rg_model->getArtistAlbums($artist_id);
$release_groups = $r_model->getReleases(array_keys($albums), true);

$g_tracks = array();
foreach ($release_groups as $release_group => $releases) {
	$g_tracks[$release_group] = $t_model->getUniqueReleaseTracks(array_keys($releases));
}

include 'tpl/index.php';
