|
@@ -5,6 +5,7 @@ namespace Muzich\CoreBundle\Factory\Elements;
|
5
|
5
|
use Muzich\CoreBundle\Factory\ElementFactory;
|
6
|
6
|
use Muzich\CoreBundle\Entity\Element;
|
7
|
7
|
use Muzich\CoreBundle\Util\TagLike;
|
|
8
|
+use Muzich\CoreBundle\lib\Api\Response as ApiResponse;
|
8
|
9
|
|
9
|
10
|
/**
|
10
|
11
|
*
|
|
@@ -12,8 +13,7 @@ use Muzich\CoreBundle\Util\TagLike;
|
12
|
13
|
* @author bux
|
13
|
14
|
*/
|
14
|
15
|
class Soundcloudcom extends ElementFactory
|
15
|
|
-{
|
16
|
|
-
|
|
16
|
+{
|
17
|
17
|
/**
|
18
|
18
|
* ??SET = http://soundcloud.com/matas/sets/library-project
|
19
|
19
|
* ?? = http://soundcloud.com/matas/anadrakonic-waltz
|
|
@@ -41,214 +41,256 @@ class Soundcloudcom extends ElementFactory
|
41
|
41
|
$match = false;
|
42
|
42
|
}
|
43
|
43
|
|
44
|
|
-
|
45
|
|
- //$this->element->setData(Element::DATA_REF_ID, $this->element->getUrl());
|
46
|
|
-
|
47
|
|
- // récupération de données avec l'API
|
|
44
|
+ /////////////
|
48
|
45
|
if ($match)
|
49
|
46
|
{
|
50
|
|
- // La première étape consiste a résoudre l'url
|
51
|
|
- $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$this->element->getUrl().'&client_id=39946ea18e3d78d64c0ac95a025794e1');
|
52
|
|
-
|
53
|
|
- $options = array(
|
54
|
|
- CURLOPT_RETURNTRANSFER => true,
|
55
|
|
- CURLOPT_HTTPHEADER => array('Content-type: application/json')
|
56
|
|
- );
|
57
|
|
-
|
58
|
|
- curl_setopt_array( $ch, $options );
|
59
|
|
- $result = json_decode(curl_exec($ch));
|
60
|
|
-
|
61
|
|
- if (isset($result->errors))
|
62
|
|
- {
|
63
|
|
- if (count($result->errors))
|
64
|
|
- {
|
65
|
|
- return;
|
66
|
|
- }
|
67
|
|
- }
|
68
|
|
-
|
69
|
|
- if (!isset($result->location))
|
|
47
|
+ $this->setElementDatasWithApi();
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ ////$this->element->setData(Element::DATA_REF_ID, $this->element->getUrl());
|
|
51
|
+ //
|
|
52
|
+ //// récupération de données avec l'API
|
|
53
|
+ //if ($match)
|
|
54
|
+ //{
|
|
55
|
+ //
|
|
56
|
+ //
|
|
57
|
+ //
|
|
58
|
+ //
|
|
59
|
+ //
|
|
60
|
+ // // La première étape consiste a résoudre l'url
|
|
61
|
+ // $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$this->element->getUrl().'&client_id=39946ea18e3d78d64c0ac95a025794e1');
|
|
62
|
+ //
|
|
63
|
+ // $options = array(
|
|
64
|
+ // CURLOPT_RETURNTRANSFER => true,
|
|
65
|
+ // CURLOPT_HTTPHEADER => array('Content-type: application/json')
|
|
66
|
+ // );
|
|
67
|
+ //
|
|
68
|
+ // curl_setopt_array( $ch, $options );
|
|
69
|
+ // $result = json_decode(curl_exec($ch));
|
|
70
|
+ //
|
|
71
|
+ // if (isset($result->errors))
|
|
72
|
+ // {
|
|
73
|
+ // if (count($result->errors))
|
|
74
|
+ // {
|
|
75
|
+ // return;
|
|
76
|
+ // }
|
|
77
|
+ // }
|
|
78
|
+ //
|
|
79
|
+ // if (!isset($result->location))
|
|
80
|
+ // {
|
|
81
|
+ // return;
|
|
82
|
+ // }
|
|
83
|
+ //
|
|
84
|
+ // if (!$result->location)
|
|
85
|
+ // {
|
|
86
|
+ // return;
|
|
87
|
+ // }
|
|
88
|
+ //
|
|
89
|
+ // $getjsonurl = $result->location;
|
|
90
|
+ // // On a maintenant la bonne url pour demander les infos
|
|
91
|
+ // $ch = curl_init($getjsonurl);
|
|
92
|
+ // curl_setopt_array($ch, $options);
|
|
93
|
+ // $result = json_decode(curl_exec($ch), true);
|
|
94
|
+ //
|
|
95
|
+ // // En premier lieux il nous faut être sur d'avoir le droit d'utiliser le lecteur exportable
|
|
96
|
+ // $sharing = false;
|
|
97
|
+ // if (array_key_exists('sharing', $result) && array_key_exists('embeddable_by', $result))
|
|
98
|
+ // {
|
|
99
|
+ // if ($result['sharing'] == 'public' && ($result['embeddable_by'] == 'all' || $result['embeddable_by'] == 'me'))
|
|
100
|
+ // {
|
|
101
|
+ // $sharing = true;
|
|
102
|
+ // }
|
|
103
|
+ // }
|
|
104
|
+ //
|
|
105
|
+ // if ($sharing)
|
|
106
|
+ // {
|
|
107
|
+ // if (array_key_exists('id', $result) )
|
|
108
|
+ // {
|
|
109
|
+ // $this->element->setData(Element::DATA_REF_ID, $result['id']);
|
|
110
|
+ // }
|
|
111
|
+ //
|
|
112
|
+ // if (array_key_exists('uri', $result) )
|
|
113
|
+ // {
|
|
114
|
+ // $this->element->setData(Element::DATA_NORMALIZED_URL, $result['uri']);
|
|
115
|
+ // }
|
|
116
|
+ //
|
|
117
|
+ // if (array_key_exists('artwork_url', $result) )
|
|
118
|
+ // {
|
|
119
|
+ // if ($result['artwork_url'])
|
|
120
|
+ // {
|
|
121
|
+ // $this->element->setData(Element::DATA_THUMB_URL, $result['artwork_url']);
|
|
122
|
+ // }
|
|
123
|
+ // else
|
|
124
|
+ // {
|
|
125
|
+ // if (array_key_exists('user', $result) )
|
|
126
|
+ // {
|
|
127
|
+ // if (array_key_exists('avatar_url', $result['user']) )
|
|
128
|
+ // {
|
|
129
|
+ // if ($result['user']['avatar_url'])
|
|
130
|
+ // {
|
|
131
|
+ // $this->element->setData(Element::DATA_THUMB_URL, $result['user']['avatar_url']);
|
|
132
|
+ // }
|
|
133
|
+ // }
|
|
134
|
+ // }
|
|
135
|
+ // }
|
|
136
|
+ // }
|
|
137
|
+ //
|
|
138
|
+ // if (array_key_exists('kind', $result) )
|
|
139
|
+ // {
|
|
140
|
+ // $this->element->setData(Element::DATA_TYPE, $result['kind']);
|
|
141
|
+ // }
|
|
142
|
+ //
|
|
143
|
+ // if (array_key_exists('downloadable', $result) )
|
|
144
|
+ // {
|
|
145
|
+ // $this->element->setData(Element::DATA_DOWNLOAD, $result['downloadable']);
|
|
146
|
+ // // FIXME
|
|
147
|
+ // $this->element->setData(Element::DATA_DOWNLOAD_URL, $this->element->getUrl().'/download');
|
|
148
|
+ // }
|
|
149
|
+ //
|
|
150
|
+ // if (array_key_exists('title', $result) )
|
|
151
|
+ // {
|
|
152
|
+ // $this->element->setData(Element::DATA_TITLE, $result['title']);
|
|
153
|
+ // }
|
|
154
|
+ //
|
|
155
|
+ // if (array_key_exists('user', $result) )
|
|
156
|
+ // {
|
|
157
|
+ // $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
|
|
158
|
+ // }
|
|
159
|
+ //
|
|
160
|
+ // $genres = '';
|
|
161
|
+ // if (array_key_exists('genre', $result) )
|
|
162
|
+ // {
|
|
163
|
+ // if (strlen($result['genre']))
|
|
164
|
+ // {
|
|
165
|
+ // $genres = $result['genre'];
|
|
166
|
+ // }
|
|
167
|
+ // }
|
|
168
|
+ //
|
|
169
|
+ // $tags_list = '';
|
|
170
|
+ // if (array_key_exists('tag_list', $result) )
|
|
171
|
+ // {
|
|
172
|
+ // if (strlen($result['tag_list']))
|
|
173
|
+ // {
|
|
174
|
+ // $tags_list = $result['tag_list'];
|
|
175
|
+ // }
|
|
176
|
+ // }
|
|
177
|
+ //
|
|
178
|
+ // $tags_string = $genres.' '.$tags_list.' '.str_replace(' ', '-', $genres);
|
|
179
|
+ // $tags_like = array();
|
|
180
|
+ // if (strlen($tags_string))
|
|
181
|
+ // {
|
|
182
|
+ // $tag_like = new TagLike($this->entity_manager);
|
|
183
|
+ // foreach (explode(' ', $tags_string) as $word)
|
|
184
|
+ // {
|
|
185
|
+ // $similar_tags = $tag_like->getSimilarTags($word, ($this->element->getOwner())?$this->element->getOwner()->getId():null);
|
|
186
|
+ // if (count($similar_tags))
|
|
187
|
+ // {
|
|
188
|
+ // if ($similar_tags['same_found'])
|
|
189
|
+ // {
|
|
190
|
+ // $tags_like[] = $similar_tags['tags'][0]['name'];
|
|
191
|
+ // }
|
|
192
|
+ // }
|
|
193
|
+ // }
|
|
194
|
+ // $tags_like[] = $genres;
|
|
195
|
+ // if (count($tags_like))
|
|
196
|
+ // {
|
|
197
|
+ // $this->element->setData(Element::DATA_TAGS, array_unique($tags_like));
|
|
198
|
+ // }
|
|
199
|
+ // }
|
|
200
|
+ //
|
|
201
|
+ // }
|
|
202
|
+ //}
|
|
203
|
+ }
|
|
204
|
+
|
|
205
|
+ protected function setElementDatasWithApi()
|
|
206
|
+ {
|
|
207
|
+ if (($response = $this->getApiDatasResponse()))
|
|
208
|
+ {
|
|
209
|
+ if ($response->get('sharing') == 'public')
|
70
|
210
|
{
|
71
|
|
- return;
|
|
211
|
+ $this->setElementSharingData($response);
|
|
212
|
+ $this->setTagsData($response);
|
72
|
213
|
}
|
73
|
214
|
|
74
|
|
- if (!$result->location)
|
|
215
|
+ if ($response->get('embeddable_by') == 'all')
|
75
|
216
|
{
|
76
|
|
- return;
|
|
217
|
+ $this->setElementEmbeddableData($response);
|
77
|
218
|
}
|
78
|
|
-
|
79
|
|
- $getjsonurl = $result->location;
|
80
|
|
- // On a maintenant la bonne url pour demander les infos
|
81
|
|
- $ch = curl_init($getjsonurl);
|
82
|
|
- curl_setopt_array($ch, $options);
|
83
|
|
- $result = json_decode(curl_exec($ch), true);
|
84
|
|
-
|
85
|
|
- /*
|
86
|
|
- * array
|
87
|
|
- 'kind' => string 'track' (length=5)
|
88
|
|
- 'id' => int 57452080
|
89
|
|
- 'created_at' => string '2012/08/24 20:39:44 +0000' (length=25)
|
90
|
|
- 'user_id' => int 11235441
|
91
|
|
- 'duration' => int 4206558
|
92
|
|
- 'commentable' => boolean true
|
93
|
|
- 'state' => string 'finished' (length=8)
|
94
|
|
- 'original_content_size' => int 168196212
|
95
|
|
- 'sharing' => string 'public' (length=6)
|
96
|
|
- 'tag_list' => string '' (length=0)
|
97
|
|
- 'permalink' => string 'mechanika-crew-andrew-dj-set' (length=28)
|
98
|
|
- 'streamable' => boolean true
|
99
|
|
- 'embeddable_by' => string 'all' (length=3)
|
100
|
|
- 'downloadable' => boolean true
|
101
|
|
- 'purchase_url' => null
|
102
|
|
- 'label_id' => null
|
103
|
|
- 'purchase_title' => null
|
104
|
|
- 'genre' => string '' (length=0)
|
105
|
|
- 'title' => string 'MECHANIKA CREW / ANDREW dj set 24.08.12' (length=39)
|
106
|
|
- 'description' => string '' (length=0)
|
107
|
|
- 'label_name' => string '' (length=0)
|
108
|
|
- 'release' => string '' (length=0)
|
109
|
|
- 'track_type' => string '' (length=0)
|
110
|
|
- 'key_signature' => string '' (length=0)
|
111
|
|
- 'isrc' => string '' (length=0)
|
112
|
|
- 'video_url' => null
|
113
|
|
- 'bpm' => null
|
114
|
|
- 'release_year' => null
|
115
|
|
- 'release_month' => null
|
116
|
|
- 'release_day' => null
|
117
|
|
- 'original_format' => string 'mp3' (length=3)
|
118
|
|
- 'license' => string 'all-rights-reserved' (length=19)
|
119
|
|
- 'uri' => string 'http://api.soundcloud.com/tracks/57452080' (length=41)
|
120
|
|
- 'user' =>
|
121
|
|
- array
|
122
|
|
- 'id' => int 11235441
|
123
|
|
- 'kind' => string 'user' (length=4)
|
124
|
|
- 'permalink' => string 'user4818423' (length=11)
|
125
|
|
- 'username' => string 'Andrea Andrew mechanika' (length=23)
|
126
|
|
- 'uri' => string 'http://api.soundcloud.com/users/11235441' (length=40)
|
127
|
|
- 'permalink_url' => string 'http://soundcloud.com/user4818423' (length=33)
|
128
|
|
- 'avatar_url' => string 'http://i1.sndcdn.com/avatars-000023343399-cp1lvg-large.jpg?04ad178' (length=66)
|
129
|
|
- 'permalink_url' => string 'http://soundcloud.com/user4818423/mechanika-crew-andrew-dj-set' (length=62)
|
130
|
|
- 'artwork_url' => string 'http://i1.sndcdn.com/artworks-000029057120-6fz4k4-large.jpg?04ad178' (length=67)
|
131
|
|
- 'waveform_url' => string 'http://w1.sndcdn.com/udItSnzA5J22_m.png' (length=39)
|
132
|
|
- 'stream_url' => string 'http://api.soundcloud.com/tracks/57452080/stream' (length=48)
|
133
|
|
- 'download_url' => string 'http://api.soundcloud.com/tracks/57452080/download' (length=50)
|
134
|
|
- 'playback_count' => int 502
|
135
|
|
- 'download_count' => int 85
|
136
|
|
- 'favoritings_count' => int 12
|
137
|
|
- 'comment_count' => int 13
|
138
|
|
- 'attachments_uri' => string 'http://api.soundcloud.com/tracks/57452080/attachments' (length=53)
|
139
|
|
-
|
140
|
|
- */
|
141
|
|
-
|
142
|
|
- // En premier lieux il nous faut être sur d'avoir le droit d'utiliser le lecteur exportable
|
143
|
|
- $sharing = false;
|
144
|
|
- if (array_key_exists('sharing', $result) && array_key_exists('embeddable_by', $result))
|
|
219
|
+ }
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ protected function getApiDatasResponse()
|
|
223
|
+ {
|
|
224
|
+ if (($response = $this->getApiConnector()->getResponseForUrl('http://api.soundcloud.com/resolve.json?url='.$this->element->getUrl().'&client_id=39946ea18e3d78d64c0ac95a025794e1')))
|
|
225
|
+ {
|
|
226
|
+ if ($response->haveNot('errors') && $response->have('location'))
|
145
|
227
|
{
|
146
|
|
- if ($result['sharing'] == 'public' && ($result['embeddable_by'] == 'all' || $result['embeddable_by'] == 'me'))
|
147
|
|
- {
|
148
|
|
- $sharing = true;
|
149
|
|
- }
|
|
228
|
+ return $this->getApiConnector()->getResponseForUrl($response->get('location'));
|
150
|
229
|
}
|
151
|
|
-
|
152
|
|
- if ($sharing)
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ return null;
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ protected function setElementSharingData(ApiResponse $response)
|
|
236
|
+ {
|
|
237
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
238
|
+ Element::DATA_NORMALIZED_URL => 'uri',
|
|
239
|
+ Element::DATA_TYPE => 'kind',
|
|
240
|
+ Element::DATA_DOWNLOAD => 'downloadable',
|
|
241
|
+ Element::DATA_DOWNLOAD_URL => 'download_url',
|
|
242
|
+ Element::DATA_TITLE => 'title',
|
|
243
|
+ Element::DATA_ARTIST => array('user' => 'username')
|
|
244
|
+ ));
|
|
245
|
+
|
|
246
|
+ $this->setThumbnailData($response);
|
|
247
|
+ }
|
|
248
|
+
|
|
249
|
+ protected function setThumbnailData(ApiResponse $response)
|
|
250
|
+ {
|
|
251
|
+ if ($response->have('artwork_url'))
|
|
252
|
+ {
|
|
253
|
+ $this->element->setData(Element::DATA_THUMB_URL, $response->get('artwork_url'));
|
|
254
|
+ }
|
|
255
|
+ elseif ($response->have(array('user' => 'avatar_url')))
|
|
256
|
+ {
|
|
257
|
+ $this->element->setData(Element::DATA_THUMB_URL, $response->get(array('user' => 'avatar_url')));
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ protected function setTagsData(ApiResponse $response)
|
|
262
|
+ {
|
|
263
|
+ $tags_string = $response->get('genre').' '.$response->get('tag_list').' '.str_replace(' ', '-', $response->get('genre'));
|
|
264
|
+ $tags_like = array();
|
|
265
|
+ if (strlen($tags_string))
|
|
266
|
+ {
|
|
267
|
+ $tag_like = new TagLike($this->entity_manager);
|
|
268
|
+ foreach (explode(' ', $tags_string) as $word)
|
153
|
269
|
{
|
154
|
|
- if (array_key_exists('id', $result) )
|
155
|
|
- {
|
156
|
|
- $this->element->setData(Element::DATA_REF_ID, $result['id']);
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- if (array_key_exists('uri', $result) )
|
160
|
|
- {
|
161
|
|
- $this->element->setData(Element::DATA_NORMALIZED_URL, $result['uri']);
|
162
|
|
- }
|
163
|
|
-
|
164
|
|
- if (array_key_exists('artwork_url', $result) )
|
165
|
|
- {
|
166
|
|
- if ($result['artwork_url'])
|
167
|
|
- {
|
168
|
|
- $this->element->setData(Element::DATA_THUMB_URL, $result['artwork_url']);
|
169
|
|
- }
|
170
|
|
- else
|
171
|
|
- {
|
172
|
|
- if (array_key_exists('user', $result) )
|
173
|
|
- {
|
174
|
|
- if (array_key_exists('avatar_url', $result['user']) )
|
175
|
|
- {
|
176
|
|
- if ($result['user']['avatar_url'])
|
177
|
|
- {
|
178
|
|
- $this->element->setData(Element::DATA_THUMB_URL, $result['user']['avatar_url']);
|
179
|
|
- }
|
180
|
|
- }
|
181
|
|
- }
|
182
|
|
- }
|
183
|
|
- }
|
184
|
|
-
|
185
|
|
- if (array_key_exists('kind', $result) )
|
186
|
|
- {
|
187
|
|
- $this->element->setData(Element::DATA_TYPE, $result['kind']);
|
188
|
|
- }
|
189
|
|
-
|
190
|
|
- if (array_key_exists('downloadable', $result) )
|
|
270
|
+ $similar_tags = $tag_like->getSimilarTags($word, ($this->element->getOwner())?$this->element->getOwner()->getId():null);
|
|
271
|
+ if (count($similar_tags))
|
191
|
272
|
{
|
192
|
|
- $this->element->setData(Element::DATA_DOWNLOAD, $result['downloadable']);
|
193
|
|
- // FIXME
|
194
|
|
- $this->element->setData(Element::DATA_DOWNLOAD_URL, $this->element->getUrl().'/download');
|
195
|
|
- }
|
196
|
|
-
|
197
|
|
- if (array_key_exists('title', $result) )
|
198
|
|
- {
|
199
|
|
- $this->element->setData(Element::DATA_TITLE, $result['title']);
|
200
|
|
- }
|
201
|
|
-
|
202
|
|
- if (array_key_exists('user', $result) )
|
203
|
|
- {
|
204
|
|
- $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
|
205
|
|
- }
|
206
|
|
-
|
207
|
|
- $genres = '';
|
208
|
|
- if (array_key_exists('genre', $result) )
|
209
|
|
- {
|
210
|
|
- if (strlen($result['genre']))
|
211
|
|
- {
|
212
|
|
- $genres = $result['genre'];
|
213
|
|
- }
|
214
|
|
- }
|
215
|
|
-
|
216
|
|
- $tags_list = '';
|
217
|
|
- if (array_key_exists('tag_list', $result) )
|
218
|
|
- {
|
219
|
|
- if (strlen($result['tag_list']))
|
|
273
|
+ if ($similar_tags['same_found'])
|
220
|
274
|
{
|
221
|
|
- $tags_list = $result['tag_list'];
|
|
275
|
+ $tags_like[] = $similar_tags['tags'][0]['name'];
|
222
|
276
|
}
|
223
|
277
|
}
|
224
|
|
-
|
225
|
|
- $tags_string = $genres.' '.$tags_list.' '.str_replace(' ', '-', $genres);
|
226
|
|
- $tags_like = array();
|
227
|
|
- if (strlen($tags_string))
|
228
|
|
- {
|
229
|
|
- $tag_like = new TagLike($this->entity_manager);
|
230
|
|
- foreach (explode(' ', $tags_string) as $word)
|
231
|
|
- {
|
232
|
|
- $similar_tags = $tag_like->getSimilarTags($word, ($this->element->getOwner())?$this->element->getOwner()->getId():null);
|
233
|
|
- if (count($similar_tags))
|
234
|
|
- {
|
235
|
|
- if ($similar_tags['same_found'])
|
236
|
|
- {
|
237
|
|
- $tags_like[] = $similar_tags['tags'][0]['name'];
|
238
|
|
- }
|
239
|
|
- }
|
240
|
|
- }
|
241
|
|
- $tags_like[] = $genres;
|
242
|
|
- if (count($tags_like))
|
243
|
|
- {
|
244
|
|
- $this->element->setData(Element::DATA_TAGS, array_unique($tags_like));
|
245
|
|
- }
|
246
|
|
- }
|
247
|
|
-
|
|
278
|
+ }
|
|
279
|
+ $tags_like[] = $response->get('genre');
|
|
280
|
+ if (count($tags_like))
|
|
281
|
+ {
|
|
282
|
+ $this->element->setData(Element::DATA_TAGS, array_unique($tags_like));
|
248
|
283
|
}
|
249
|
284
|
}
|
250
|
285
|
}
|
251
|
286
|
|
|
287
|
+ protected function setElementEmbeddableData($response)
|
|
288
|
+ {
|
|
289
|
+ $this->getApiConnector()->setElementDatasWithResponse($response, array(
|
|
290
|
+ Element::DATA_REF_ID => 'id'
|
|
291
|
+ ));
|
|
292
|
+ }
|
|
293
|
+
|
252
|
294
|
public function proceedEmbedCode()
|
253
|
295
|
{
|
254
|
296
|
if (($ref_id = $this->element->getData(Element::DATA_REF_ID))
|