|
@@ -3,6 +3,7 @@
|
3
|
3
|
namespace Muzich\CoreBundle\Factory\Elements;
|
4
|
4
|
|
5
|
5
|
use Muzich\CoreBundle\Factory\ElementFactory;
|
|
6
|
+use Muzich\CoreBundle\Entity\Element;
|
6
|
7
|
|
7
|
8
|
/**
|
8
|
9
|
*
|
|
@@ -20,30 +21,33 @@ class Soundcloudcom extends ElementFactory
|
20
|
21
|
{
|
21
|
22
|
$url_clean = $this->getCleanedUrl();
|
22
|
23
|
|
23
|
|
- $ref_id = null;
|
24
|
|
- // ??SET
|
|
24
|
+ $match = false;
|
|
25
|
+ //
|
25
|
26
|
if (preg_match("#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
|
26
|
27
|
{
|
27
|
|
- $ref_id = $url_clean;
|
|
28
|
+ $match = true;
|
28
|
29
|
}
|
29
|
|
- // ???
|
|
30
|
+ // /noisia/black-sun-empire-noisia-feed
|
|
31
|
+ // /user4818423/mechanika-crew-andrew-dj-set
|
30
|
32
|
else if (preg_match("#^\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
|
31
|
33
|
{
|
32
|
|
- $ref_id = $url_clean;
|
|
34
|
+ $match = true;
|
33
|
35
|
}
|
34
|
36
|
|
35
|
37
|
// On en gère pas encore les recherches
|
36
|
38
|
if (preg_match("#\/search\?q#", $url_clean, $chaines))
|
37
|
39
|
{
|
38
|
|
- $ref_id = null;
|
|
40
|
+ $match = false;
|
39
|
41
|
}
|
40
|
42
|
|
41
|
|
- $this->element->setData('ref_id', $ref_id);
|
|
43
|
+
|
|
44
|
+ //$this->element->setData(Element::DATA_REF_ID, $this->element->getUrl());
|
42
|
45
|
|
43
|
46
|
// récupération de données avec l'API
|
44
|
|
- if ($ref_id)
|
|
47
|
+ if ($match)
|
45
|
48
|
{
|
46
|
|
- $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$ref_id.'&client_id=39946ea18e3d78d64c0ac95a025794e1');
|
|
49
|
+ // La première étape consiste a résoudre l'url
|
|
50
|
+ $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$this->element->getUrl().'&client_id=39946ea18e3d78d64c0ac95a025794e1');
|
47
|
51
|
|
48
|
52
|
$options = array(
|
49
|
53
|
CURLOPT_RETURNTRANSFER => true,
|
|
@@ -62,22 +66,120 @@ class Soundcloudcom extends ElementFactory
|
62
|
66
|
}
|
63
|
67
|
|
64
|
68
|
$getjsonurl = $result->location;
|
|
69
|
+ // On a maintenant la bonne url pour demander les infos
|
65
|
70
|
$ch = curl_init($getjsonurl);
|
66
|
71
|
curl_setopt_array($ch, $options);
|
67
|
|
- $result = json_decode(curl_exec($ch));
|
|
72
|
+ $result = json_decode(curl_exec($ch), true);
|
|
73
|
+
|
|
74
|
+ /*
|
|
75
|
+ * array
|
|
76
|
+ 'kind' => string 'track' (length=5)
|
|
77
|
+ 'id' => int 57452080
|
|
78
|
+ 'created_at' => string '2012/08/24 20:39:44 +0000' (length=25)
|
|
79
|
+ 'user_id' => int 11235441
|
|
80
|
+ 'duration' => int 4206558
|
|
81
|
+ 'commentable' => boolean true
|
|
82
|
+ 'state' => string 'finished' (length=8)
|
|
83
|
+ 'original_content_size' => int 168196212
|
|
84
|
+ 'sharing' => string 'public' (length=6)
|
|
85
|
+ 'tag_list' => string '' (length=0)
|
|
86
|
+ 'permalink' => string 'mechanika-crew-andrew-dj-set' (length=28)
|
|
87
|
+ 'streamable' => boolean true
|
|
88
|
+ 'embeddable_by' => string 'all' (length=3)
|
|
89
|
+ 'downloadable' => boolean true
|
|
90
|
+ 'purchase_url' => null
|
|
91
|
+ 'label_id' => null
|
|
92
|
+ 'purchase_title' => null
|
|
93
|
+ 'genre' => string '' (length=0)
|
|
94
|
+ 'title' => string 'MECHANIKA CREW / ANDREW dj set 24.08.12' (length=39)
|
|
95
|
+ 'description' => string '' (length=0)
|
|
96
|
+ 'label_name' => string '' (length=0)
|
|
97
|
+ 'release' => string '' (length=0)
|
|
98
|
+ 'track_type' => string '' (length=0)
|
|
99
|
+ 'key_signature' => string '' (length=0)
|
|
100
|
+ 'isrc' => string '' (length=0)
|
|
101
|
+ 'video_url' => null
|
|
102
|
+ 'bpm' => null
|
|
103
|
+ 'release_year' => null
|
|
104
|
+ 'release_month' => null
|
|
105
|
+ 'release_day' => null
|
|
106
|
+ 'original_format' => string 'mp3' (length=3)
|
|
107
|
+ 'license' => string 'all-rights-reserved' (length=19)
|
|
108
|
+ 'uri' => string 'http://api.soundcloud.com/tracks/57452080' (length=41)
|
|
109
|
+ 'user' =>
|
|
110
|
+ array
|
|
111
|
+ 'id' => int 11235441
|
|
112
|
+ 'kind' => string 'user' (length=4)
|
|
113
|
+ 'permalink' => string 'user4818423' (length=11)
|
|
114
|
+ 'username' => string 'Andrea Andrew mechanika' (length=23)
|
|
115
|
+ 'uri' => string 'http://api.soundcloud.com/users/11235441' (length=40)
|
|
116
|
+ 'permalink_url' => string 'http://soundcloud.com/user4818423' (length=33)
|
|
117
|
+ 'avatar_url' => string 'http://i1.sndcdn.com/avatars-000023343399-cp1lvg-large.jpg?04ad178' (length=66)
|
|
118
|
+ 'permalink_url' => string 'http://soundcloud.com/user4818423/mechanika-crew-andrew-dj-set' (length=62)
|
|
119
|
+ 'artwork_url' => string 'http://i1.sndcdn.com/artworks-000029057120-6fz4k4-large.jpg?04ad178' (length=67)
|
|
120
|
+ 'waveform_url' => string 'http://w1.sndcdn.com/udItSnzA5J22_m.png' (length=39)
|
|
121
|
+ 'stream_url' => string 'http://api.soundcloud.com/tracks/57452080/stream' (length=48)
|
|
122
|
+ 'download_url' => string 'http://api.soundcloud.com/tracks/57452080/download' (length=50)
|
|
123
|
+ 'playback_count' => int 502
|
|
124
|
+ 'download_count' => int 85
|
|
125
|
+ 'favoritings_count' => int 12
|
|
126
|
+ 'comment_count' => int 13
|
|
127
|
+ 'attachments_uri' => string 'http://api.soundcloud.com/tracks/57452080/attachments' (length=53)
|
68
|
128
|
|
69
|
|
- if (isset($result->artwork_url))
|
|
129
|
+ */
|
|
130
|
+
|
|
131
|
+ if (array_key_exists('id', $result) )
|
|
132
|
+ {
|
|
133
|
+ $this->element->setData(Element::DATA_REF_ID, $result['id']);
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ if (array_key_exists('artwork_url', $result) )
|
|
137
|
+ {
|
|
138
|
+ $this->element->setData(Element::DATA_THUMB_URL, $result['artwork_url']);
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ if (array_key_exists('kind', $result) )
|
|
142
|
+ {
|
|
143
|
+ $this->element->setData(Element::DATA_TYPE, $result['kind']);
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ if (array_key_exists('downloadable', $result) )
|
70
|
147
|
{
|
71
|
|
- $this->element->setData('artwork_url', $result->artwork_url);
|
|
148
|
+ $this->element->setData(Element::DATA_DOWNLOAD, $result['downloadable']);
|
|
149
|
+ // FIXME
|
|
150
|
+ $this->element->setData(Element::DATA_DOWNLOAD_URL, $this->element->getUrl().'/download');
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ if (array_key_exists('title', $result) )
|
|
154
|
+ {
|
|
155
|
+ $this->element->setData(Element::DATA_TITLE, $result['title']);
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ if (array_key_exists('user', $result) )
|
|
159
|
+ {
|
|
160
|
+ $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ if (array_key_exists('genre', $result) )
|
|
164
|
+ {
|
|
165
|
+ if (strlen($result['genre']))
|
|
166
|
+ {
|
|
167
|
+ $this->element->setData(Element::DATA_TAGS, array($result['genre']));
|
|
168
|
+ }
|
72
|
169
|
}
|
|
170
|
+
|
|
171
|
+ /*
|
|
172
|
+ * TODO: Il y a un parametre share:public si a pas public pas de lecteur intégré ??
|
|
173
|
+ */
|
|
174
|
+
|
73
|
175
|
}
|
74
|
176
|
}
|
75
|
177
|
|
76
|
178
|
public function proceedEmbedCode()
|
77
|
179
|
{
|
78
|
|
- if (($ref_id = $this->element->getData('ref_id')))
|
|
180
|
+ if (($ref_id = $this->element->getData(Element::DATA_REF_ID)) && $this->element->getData(Element::DATA_TYPE) == 'track')
|
79
|
181
|
{
|
80
|
|
- $ref_id = 'http://soundcloud.com'.$ref_id;
|
|
182
|
+ $ref_id = $this->element->getUrl();
|
81
|
183
|
$embed_id = md5($ref_id);
|
82
|
184
|
$height = $this->container->getParameter('soundcloud_player_height');
|
83
|
185
|
$this->element->setEmbed(
|
|
@@ -97,7 +199,7 @@ class Soundcloudcom extends ElementFactory
|
97
|
199
|
|
98
|
200
|
public function proceedThumbnailUrl()
|
99
|
201
|
{
|
100
|
|
- if (($thumb = $this->element->getData('artwork_url')))
|
|
202
|
+ if (($thumb = $this->element->getData(Element::DATA_THUMB_URL)))
|
101
|
203
|
{
|
102
|
204
|
$this->element->setThumbnailUrl($thumb);
|
103
|
205
|
}
|