|
@@ -4,6 +4,9 @@ namespace Muzich\CoreBundle\Factory\Elements;
|
4
|
4
|
|
5
|
5
|
use Muzich\CoreBundle\Factory\ElementFactory;
|
6
|
6
|
use Muzich\CoreBundle\Entity\Element;
|
|
7
|
+use Muzich\CoreBundle\Factory\UrlMatchs;
|
|
8
|
+use Symfony\Component\DependencyInjection\Container;
|
|
9
|
+use Doctrine\ORM\EntityManager;
|
7
|
10
|
|
8
|
11
|
/**
|
9
|
12
|
*
|
|
@@ -13,6 +16,18 @@ use Muzich\CoreBundle\Entity\Element;
|
13
|
16
|
class Spotifycom extends ElementFactory
|
14
|
17
|
{
|
15
|
18
|
|
|
19
|
+ public function __construct(Element $element, Container $container, EntityManager $entity_manager)
|
|
20
|
+ {
|
|
21
|
+ $this->url_matchs = UrlMatchs::$spotify;
|
|
22
|
+ parent::__construct($element, $container, $entity_manager);
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ public function proceedDatas()
|
|
26
|
+ {
|
|
27
|
+ $this->setElementDatasWithApi();
|
|
28
|
+ $this->proceedEmbedCode();
|
|
29
|
+ }
|
|
30
|
+
|
16
|
31
|
/**
|
17
|
32
|
*
|
18
|
33
|
track http url: http://open.spotify.com/track/7ylMdCOkqumPAwIMb6j2D5
|
|
@@ -59,67 +74,105 @@ class Spotifycom extends ElementFactory
|
59
|
74
|
}
|
60
|
75
|
}
|
61
|
76
|
|
62
|
|
- protected function getDataFromApi($ref_id)
|
|
77
|
+ protected function setElementDatasWithApi()
|
63
|
78
|
{
|
64
|
|
- if ($this->element->getData(Element::DATA_TYPE) == 'track')
|
|
79
|
+ if ($this->url_analyzer->getType() == Element::TYPE_TRACK)
|
65
|
80
|
{
|
66
|
|
- $data = $this->getJsonDataFromApiWithUrl('http://ws.spotify.com/lookup/1/.json?uri=spotify:track:'.$ref_id);
|
|
81
|
+ $response = $this->getApiConnector()->getResponseForUrl('http://ws.spotify.com/lookup/1/.json?uri=spotify:track:'
|
|
82
|
+ .$this->url_analyzer->getRefId()
|
|
83
|
+ );
|
|
84
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
85
|
+ Element::DATA_ARTIST => array('track' => 'artist'),
|
|
86
|
+ Element::DATA_TITLE => array('track' => 'name')
|
|
87
|
+ ));
|
67
|
88
|
|
68
|
|
- if (array_key_exists('track', $data))
|
|
89
|
+ if (!$this->element->getData(Element::DATA_ARTIST))
|
69
|
90
|
{
|
70
|
|
- if (array_key_exists('available', $data['track']))
|
71
|
|
- {
|
72
|
|
- if ($data['track']['available'])
|
73
|
|
- {
|
74
|
|
- if (array_key_exists('artist', $data['track']))
|
75
|
|
- {
|
76
|
|
- $this->element->setData(Element::DATA_ARTIST, $data['track']['artist']);
|
77
|
|
- }
|
78
|
|
- if (array_key_exists('artists', $data['track']))
|
79
|
|
- {
|
80
|
|
- if (count($data['track']['artists']))
|
81
|
|
- {
|
82
|
|
- if (array_key_exists('name', $data['track']['artists'][0]))
|
83
|
|
- {
|
84
|
|
- $this->element->setData(Element::DATA_ARTIST, $data['track']['artists'][0]['name']);
|
85
|
|
- }
|
86
|
|
- }
|
87
|
|
- }
|
88
|
|
- if (array_key_exists('name', $data['track']))
|
89
|
|
- {
|
90
|
|
- $this->element->setData(Element::DATA_TITLE, $data['track']['name']);
|
91
|
|
- }
|
92
|
|
- }
|
93
|
|
- }
|
|
91
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
92
|
+ Element::DATA_ARTIST => array('track' => array('artists' => array(0 => 'name'))),
|
|
93
|
+ ));
|
94
|
94
|
}
|
95
|
95
|
}
|
96
|
|
- if ($this->element->getData(Element::DATA_TYPE) == 'album')
|
|
96
|
+ if ($this->url_analyzer->getType() == Element::TYPE_ALBUM)
|
97
|
97
|
{
|
98
|
|
- $data = $this->getJsonDataFromApiWithUrl('http://ws.spotify.com/lookup/1/.json?uri=spotify:album:'.$ref_id);
|
|
98
|
+ $response = $this->getApiConnector()->getResponseForUrl('http://ws.spotify.com/lookup/1/.json?uri=spotify:album:'
|
|
99
|
+ .$this->url_analyzer->getRefId()
|
|
100
|
+ );
|
|
101
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
102
|
+ Element::DATA_ARTIST => array('album' => 'artist'),
|
|
103
|
+ Element::DATA_TITLE => array('album' => 'name')
|
|
104
|
+ ));
|
99
|
105
|
|
100
|
|
- if (array_key_exists('album', $data))
|
|
106
|
+ if (!$this->element->getData(Element::DATA_ARTIST))
|
101
|
107
|
{
|
102
|
|
- if (array_key_exists('artist', $data['album']))
|
103
|
|
- {
|
104
|
|
- $this->element->setData(Element::DATA_ARTIST, $data['album']['artist']);
|
105
|
|
- }
|
106
|
|
- if (array_key_exists('artists', $data['album']))
|
107
|
|
- {
|
108
|
|
- if (count($data['album']['artists']))
|
109
|
|
- {
|
110
|
|
- if (array_key_exists('name', $data['album']['artists'][0]))
|
111
|
|
- {
|
112
|
|
- $this->element->setData(Element::DATA_ARTIST, $data['album']['artists'][0]['name']);
|
113
|
|
- }
|
114
|
|
- }
|
115
|
|
- }
|
116
|
|
- if (array_key_exists('name', $data['album']))
|
117
|
|
- {
|
118
|
|
- $this->element->setData(Element::DATA_TITLE, $data['album']['name']);
|
119
|
|
- }
|
|
108
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
109
|
+ Element::DATA_ARTIST => array('album' => array('artists' => array(0 => 'name'))),
|
|
110
|
+ ));
|
120
|
111
|
}
|
121
|
112
|
}
|
122
|
113
|
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+ //if ($this->element->getData(Element::DATA_TYPE) == 'track')
|
|
118
|
+ //{
|
|
119
|
+ // $data = $this->getJsonDataFromApiWithUrl('http://ws.spotify.com/lookup/1/.json?uri=spotify:track:'.$ref_id);
|
|
120
|
+ //
|
|
121
|
+ // if (array_key_exists('track', $data))
|
|
122
|
+ // {
|
|
123
|
+ // if (array_key_exists('available', $data['track']))
|
|
124
|
+ // {
|
|
125
|
+ // if ($data['track']['available'])
|
|
126
|
+ // {
|
|
127
|
+ // if (array_key_exists('artist', $data['track']))
|
|
128
|
+ // {
|
|
129
|
+ // $this->element->setData(Element::DATA_ARTIST, $data['track']['artist']);
|
|
130
|
+ // }
|
|
131
|
+ // if (array_key_exists('artists', $data['track']))
|
|
132
|
+ // {
|
|
133
|
+ // if (count($data['track']['artists']))
|
|
134
|
+ // {
|
|
135
|
+ // if (array_key_exists('name', $data['track']['artists'][0]))
|
|
136
|
+ // {
|
|
137
|
+ // $this->element->setData(Element::DATA_ARTIST, $data['track']['artists'][0]['name']);
|
|
138
|
+ // }
|
|
139
|
+ // }
|
|
140
|
+ // }
|
|
141
|
+ // if (array_key_exists('name', $data['track']))
|
|
142
|
+ // {
|
|
143
|
+ // $this->element->setData(Element::DATA_TITLE, $data['track']['name']);
|
|
144
|
+ // }
|
|
145
|
+ // }
|
|
146
|
+ // }
|
|
147
|
+ // }
|
|
148
|
+ //}
|
|
149
|
+ //if ($this->element->getData(Element::DATA_TYPE) == 'album')
|
|
150
|
+ //{
|
|
151
|
+ // $data = $this->getJsonDataFromApiWithUrl('http://ws.spotify.com/lookup/1/.json?uri=spotify:album:'.$ref_id);
|
|
152
|
+ //
|
|
153
|
+ // if (array_key_exists('album', $data))
|
|
154
|
+ // {
|
|
155
|
+ // if (array_key_exists('artist', $data['album']))
|
|
156
|
+ // {
|
|
157
|
+ // $this->element->setData(Element::DATA_ARTIST, $data['album']['artist']);
|
|
158
|
+ // }
|
|
159
|
+ // if (array_key_exists('artists', $data['album']))
|
|
160
|
+ // {
|
|
161
|
+ // if (count($data['album']['artists']))
|
|
162
|
+ // {
|
|
163
|
+ // if (array_key_exists('name', $data['album']['artists'][0]))
|
|
164
|
+ // {
|
|
165
|
+ // $this->element->setData(Element::DATA_ARTIST, $data['album']['artists'][0]['name']);
|
|
166
|
+ // }
|
|
167
|
+ // }
|
|
168
|
+ // }
|
|
169
|
+ // if (array_key_exists('name', $data['album']))
|
|
170
|
+ // {
|
|
171
|
+ // $this->element->setData(Element::DATA_TITLE, $data['album']['name']);
|
|
172
|
+ // }
|
|
173
|
+ // }
|
|
174
|
+ //}
|
|
175
|
+
|
123
|
176
|
}
|
124
|
177
|
|
125
|
178
|
public function proceedEmbedCode()
|