|
@@ -6,11 +6,6 @@ use Muzich\CoreBundle\Factory\ElementFactory;
|
6
|
6
|
use Muzich\CoreBundle\Entity\Element;
|
7
|
7
|
use Muzich\CoreBundle\Factory\UrlMatchs;
|
8
|
8
|
|
9
|
|
-/**
|
10
|
|
- *
|
11
|
|
- *
|
12
|
|
- * @author bux
|
13
|
|
- */
|
14
|
9
|
class Jamendocom extends ElementFactory
|
15
|
10
|
{
|
16
|
11
|
|
|
@@ -22,36 +17,13 @@ class Jamendocom extends ElementFactory
|
22
|
17
|
|
23
|
18
|
public function getStreamData()
|
24
|
19
|
{
|
25
|
|
- // On determine le type et l'url
|
26
|
|
- $this->proceedTypeAndId();
|
27
|
|
-
|
28
|
|
- $type = $this->element->getData(Element::DATA_TYPE);
|
29
|
20
|
$ref_id = $this->element->getData(Element::DATA_REF_ID);
|
|
21
|
+ $api_url = "http://api.jamendo.com/get2/name+stream/track/json/?". $this->element->getData(Element::DATA_TYPE)."_id=".$ref_id;
|
30
|
22
|
|
31
|
|
- // Récupération de données avec l'API
|
32
|
|
- $api_url = null;
|
33
|
|
- switch ($type)
|
34
|
|
- {
|
35
|
|
- case 'track':
|
36
|
|
- $api_url = "http://api.jamendo.com/get2/name+stream/track/json/?track_id=".$ref_id;
|
37
|
|
- break;
|
38
|
|
-
|
39
|
|
- case 'album':
|
40
|
|
- $api_url = "http://api.jamendo.com/get2/name+stream/track/json/?album_id=".$ref_id;
|
41
|
|
- break;
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- if ($api_url)
|
|
23
|
+ if ($ref_id)
|
45
|
24
|
{
|
46
|
|
- $ch = curl_init($api_url);
|
47
|
|
- $options = array(
|
48
|
|
- CURLOPT_RETURNTRANSFER => true,
|
49
|
|
- CURLOPT_HTTPHEADER => array('Content-type: text/plain')
|
50
|
|
- );
|
51
|
|
- curl_setopt_array( $ch, $options );
|
52
|
|
- $result = json_decode(curl_exec($ch), true);
|
53
|
|
-
|
54
|
|
- if (count($result))
|
|
25
|
+ $response = $this->getApiConnector()->getResponseForUrl($api_url);
|
|
26
|
+ if (count($response->getContent()))
|
55
|
27
|
{
|
56
|
28
|
$data_return = array();
|
57
|
29
|
foreach ($result as $song)
|
|
@@ -66,12 +38,6 @@ class Jamendocom extends ElementFactory
|
66
|
38
|
}
|
67
|
39
|
}
|
68
|
40
|
|
69
|
|
- /**
|
70
|
|
- * ALBUM = http://www.jamendo.com/fr/album/30661
|
71
|
|
- * TRACK = http://www.jamendo.com/fr/track/207079
|
72
|
|
- *
|
73
|
|
- * API: http://developer.jamendo.com/fr/wiki/Musiclist2ApiFields
|
74
|
|
- */
|
75
|
41
|
public function retrieveDatas()
|
76
|
42
|
{
|
77
|
43
|
$type = $this->element->getData(Element::DATA_TYPE);
|
|
@@ -81,13 +47,13 @@ class Jamendocom extends ElementFactory
|
81
|
47
|
$api_url = null;
|
82
|
48
|
switch ($type)
|
83
|
49
|
{
|
84
|
|
- case 'album':
|
|
50
|
+ case Element::TYPE_ALBUM:
|
85
|
51
|
$api_url = "http://api.jamendo.com/get2/"
|
86
|
52
|
."id+name+url+image+artist_name+artist_url/album/json/?album_id=".$ref_id;
|
87
|
53
|
$api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/album_tag/?album_id=".$ref_id;
|
88
|
54
|
break;
|
89
|
55
|
|
90
|
|
- case 'track':
|
|
56
|
+ case Element::TYPE_TRACK:
|
91
|
57
|
$api_url = "http://api.jamendo.com/get2/"
|
92
|
58
|
."id+name+url+image+artist_name+artist_url+track_name/album/json/?track_id=".$ref_id;
|
93
|
59
|
$api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/track_tag/?track_id=".$ref_id;
|
|
@@ -96,53 +62,28 @@ class Jamendocom extends ElementFactory
|
96
|
62
|
|
97
|
63
|
if ($api_url)
|
98
|
64
|
{
|
99
|
|
- $ch = curl_init($api_url);
|
100
|
|
- $options = array(
|
101
|
|
- CURLOPT_RETURNTRANSFER => true,
|
102
|
|
- CURLOPT_HTTPHEADER => array('Content-type: text/plain')
|
103
|
|
- );
|
104
|
|
- curl_setopt_array( $ch, $options );
|
105
|
|
- $result = json_decode(curl_exec($ch), true);
|
106
|
|
-
|
107
|
|
- if (count($result))
|
|
65
|
+ if (($response = $this->getApiConnector()->getResponseForUrl($api_url)))
|
108
|
66
|
{
|
109
|
|
- // Thumb
|
110
|
|
- if (array_key_exists('image', $result[0]))
|
111
|
|
- {
|
112
|
|
- $this->element->setData(Element::DATA_THUMB_URL, $result[0]['image']);
|
113
|
|
- }
|
|
67
|
+ // Check si tout se passe bien si pas de retour de l'api
|
|
68
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
69
|
+ Element::DATA_THUMB_URL => array(0 => 'image'),
|
|
70
|
+ Element::DATA_ARTIST => array(0 => 'artist_name'),
|
|
71
|
+ ));
|
114
|
72
|
|
115
|
|
- // Album name
|
116
|
|
- if (array_key_exists('name', $result[0]) && $type == 'album')
|
|
73
|
+ if ($this->url_analyzer->getType() == Element::TYPE_ALBUM)
|
117
|
74
|
{
|
118
|
|
- $this->element->setData(Element::DATA_TITLE, $result[0]['name']);
|
|
75
|
+ $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'name')));
|
119
|
76
|
}
|
120
|
|
-
|
121
|
|
- // Artist name
|
122
|
|
- if (array_key_exists('artist_name', $result[0]))
|
123
|
|
- {
|
124
|
|
- $this->element->setData(Element::DATA_ARTIST, $result[0]['artist_name']);
|
125
|
|
- }
|
126
|
|
-
|
127
|
|
- // track name
|
128
|
|
- if (array_key_exists('track_name', $result[0]) && $type == 'track')
|
|
77
|
+ if ($this->url_analyzer->getType() == Element::TYPE_TRACK)
|
129
|
78
|
{
|
130
|
|
- $this->element->setData(Element::DATA_TITLE, $result[0]['track_name']);
|
|
79
|
+ $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'track_name')));
|
131
|
80
|
}
|
132
|
81
|
|
133
|
|
- // Maintenant au tour des tags (deuxième requete a l'api)
|
134
|
|
- $ch = curl_init($api_tag_url);
|
135
|
|
- $options = array(
|
136
|
|
- CURLOPT_RETURNTRANSFER => true,
|
137
|
|
- CURLOPT_HTTPHEADER => array('Content-type: text/plain')
|
138
|
|
- );
|
139
|
|
- curl_setopt_array( $ch, $options );
|
140
|
|
- $result = json_decode(curl_exec($ch), true);
|
141
|
|
-
|
142
|
|
- if (count($result))
|
|
82
|
+ if (($response = $this->getApiConnector()->getResponseForUrl($api_url)))
|
143
|
83
|
{
|
|
84
|
+ // TODO: Check si tout ce passe bien avec pas de tags en retour de l'api
|
144
|
85
|
$tags = array();
|
145
|
|
- foreach ($result as $tag)
|
|
86
|
+ foreach ($result->getContent() as $tag)
|
146
|
87
|
{
|
147
|
88
|
$tags[] = $tag['name'];
|
148
|
89
|
}
|