-
Notifications
You must be signed in to change notification settings - Fork 1
/
Artist.php
92 lines (83 loc) · 2.26 KB
/
Artist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
class PhEchonest_Artist extends PhEchonest_Abstract
{
protected static $_resource = 'artist';
protected $_id;
protected $_name;
/**
* constructor
*/
public function __construct($id, $name = null)
{
$this->_id = $id;
if (!$name) {
$profile = $this->getProfile();
$name = $profile['name'];
}
$this->_name = $name;
}
/**
* magic getter
*/
public function __get($accessor)
{
$accessor = "_".$accessor;
return $this->$accessor;
}
/**
* get tracks for this artist
*
* @param $limit int number of results to return
* @param $offset int number of results to skip
* @return array array of track info arrays
*/
public function getTracks($limit = 20, $offset = 0)
{
$method = 'audio';
$query = array(
'id' => $this->_id,
'results' => $limit,
'start' => $offset
);
$result = self::makeRequest($method, $query);
return $result['audio'];
}
/**
* get profile of artist
*
* @return artist profile as array
*/
protected function getProfile()
{
$method = 'profile';
$query = array(
'id' => $this->_id
);
$result = self::makeRequest($method, $query);
return $result['artist'];
}
/**
* search for an artist by name
*
* @param $name string name of artist to search for
* @param $results int number of results to return
* @param $fuzzy bool match similar artist names
* @return array array of artist objects
*/
public static function searchByName($name, $results = 20, $fuzzy = true)
{
$method = 'search';
$query = array(
'name' => $name,
'fuzzy_match' => ($fuzzy ? 'true' : 'false'),
'results' => $results
);
$result = self::makeRequest($method, $query);
$artists = array();
foreach ($result['artists'] as $artist)
{
$artists[] = new PhEchonest_Artist($artist['id'], $artist['name']);
}
return $artists;
}
}