<?php

// Include the API
require '../../lastfmapi/lastfmapi.php';

// Get the session auth data
$file = fopen('../auth.txt', 'r');
// Put the auth data into an array
$authVars = array(
	'apiKey' => trim(fgets($file)),
	'secret' => trim(fgets($file)),
	'username' => trim(fgets($file)),
	'sessionKey' => trim(fgets($file)),
	'subscriber' => trim(fgets($file))
);
$config = array(
	'enabled' => true,
	'path' => '../../lastfmapi/',
	'cache_length' => 1800
);
// Pass the array to the auth class to eturn a valid auth
$auth = new lastfmApiAuth('setsession', $authVars);

// Call for the album package class with auth data
$apiClass = new lastfmApi();
$artistClass = $apiClass->getPackage($auth, 'artist', $config);

// Setup the variables
array_shift($argv);
$methodVars = array(
	'artist' => implode(" ", $argv), #'King Crimson',
	'lang' => 'ru'
);

if ( $artist = $artistClass->getInfo($methodVars)) {
	if( ! empty($artist['bio']['summary'])) {
		$m = new Mongo();
		$db = $m->rock;
		$collection = $db->artists;
		$collection->insert($artist);
		echo $methodVars['artist'].": inserted\n";
	} else {
		echo $methodVars['artist'].": empty info, skipping\n";
	}
}
else {
	echo($methodVars['artist'].': error '.$artistClass->error['code'].' - '.$artistClass->error['desc']."\n");
}

?>
