123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
-
- namespace Muzich\CoreBundle\Factory\Elements;
-
- use Muzich\CoreBundle\Factory\ElementFactory;
- use Muzich\CoreBundle\Entity\Element;
- use Muzich\CoreBundle\Util\TagLike;
-
- /**
- *
- *
- * @author bux
- */
- class Soundcloudcom extends ElementFactory
- {
-
- /**
- * ??SET = http://soundcloud.com/matas/sets/library-project
- * ?? = http://soundcloud.com/matas/anadrakonic-waltz
- */
- public function retrieveDatas()
- {
- $url_clean = $this->getCleanedUrl();
-
- $match = false;
- //
- if (preg_match("#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
- {
- $match = true;
- }
- // /noisia/black-sun-empire-noisia-feed
- // /user4818423/mechanika-crew-andrew-dj-set
- else if (preg_match("#^\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
- {
- $match = true;
- }
-
- // On en gère pas encore les recherches
- if (preg_match("#\/search\?q#", $url_clean, $chaines))
- {
- $match = false;
- }
-
-
- //$this->element->setData(Element::DATA_REF_ID, $this->element->getUrl());
-
- // récupération de données avec l'API
- if ($match)
- {
- // La première étape consiste a résoudre l'url
- $ch = curl_init('http://api.soundcloud.com/resolve.json?url='.$this->element->getUrl().'&client_id=39946ea18e3d78d64c0ac95a025794e1');
-
- $options = array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPHEADER => array('Content-type: application/json')
- );
-
- curl_setopt_array( $ch, $options );
- $result = json_decode(curl_exec($ch));
-
- if (isset($result->errors))
- {
- if (count($result->errors))
- {
- return;
- }
- }
-
- if (!isset($result->location))
- {
- return;
- }
-
- if (!$result->location)
- {
- return;
- }
-
- $getjsonurl = $result->location;
- // On a maintenant la bonne url pour demander les infos
- $ch = curl_init($getjsonurl);
- curl_setopt_array($ch, $options);
- $result = json_decode(curl_exec($ch), true);
-
- /*
- * array
- 'kind' => string 'track' (length=5)
- 'id' => int 57452080
- 'created_at' => string '2012/08/24 20:39:44 +0000' (length=25)
- 'user_id' => int 11235441
- 'duration' => int 4206558
- 'commentable' => boolean true
- 'state' => string 'finished' (length=8)
- 'original_content_size' => int 168196212
- 'sharing' => string 'public' (length=6)
- 'tag_list' => string '' (length=0)
- 'permalink' => string 'mechanika-crew-andrew-dj-set' (length=28)
- 'streamable' => boolean true
- 'embeddable_by' => string 'all' (length=3)
- 'downloadable' => boolean true
- 'purchase_url' => null
- 'label_id' => null
- 'purchase_title' => null
- 'genre' => string '' (length=0)
- 'title' => string 'MECHANIKA CREW / ANDREW dj set 24.08.12' (length=39)
- 'description' => string '' (length=0)
- 'label_name' => string '' (length=0)
- 'release' => string '' (length=0)
- 'track_type' => string '' (length=0)
- 'key_signature' => string '' (length=0)
- 'isrc' => string '' (length=0)
- 'video_url' => null
- 'bpm' => null
- 'release_year' => null
- 'release_month' => null
- 'release_day' => null
- 'original_format' => string 'mp3' (length=3)
- 'license' => string 'all-rights-reserved' (length=19)
- 'uri' => string 'http://api.soundcloud.com/tracks/57452080' (length=41)
- 'user' =>
- array
- 'id' => int 11235441
- 'kind' => string 'user' (length=4)
- 'permalink' => string 'user4818423' (length=11)
- 'username' => string 'Andrea Andrew mechanika' (length=23)
- 'uri' => string 'http://api.soundcloud.com/users/11235441' (length=40)
- 'permalink_url' => string 'http://soundcloud.com/user4818423' (length=33)
- 'avatar_url' => string 'http://i1.sndcdn.com/avatars-000023343399-cp1lvg-large.jpg?04ad178' (length=66)
- 'permalink_url' => string 'http://soundcloud.com/user4818423/mechanika-crew-andrew-dj-set' (length=62)
- 'artwork_url' => string 'http://i1.sndcdn.com/artworks-000029057120-6fz4k4-large.jpg?04ad178' (length=67)
- 'waveform_url' => string 'http://w1.sndcdn.com/udItSnzA5J22_m.png' (length=39)
- 'stream_url' => string 'http://api.soundcloud.com/tracks/57452080/stream' (length=48)
- 'download_url' => string 'http://api.soundcloud.com/tracks/57452080/download' (length=50)
- 'playback_count' => int 502
- 'download_count' => int 85
- 'favoritings_count' => int 12
- 'comment_count' => int 13
- 'attachments_uri' => string 'http://api.soundcloud.com/tracks/57452080/attachments' (length=53)
-
- */
-
- // En premier lieux il nous faut être sur d'avoir le droit d'utiliser le lecteur exportable
- $sharing = false;
- if (array_key_exists('sharing', $result) && array_key_exists('embeddable_by', $result))
- {
- if ($result['sharing'] == 'public' && ($result['embeddable_by'] == 'all' || $result['embeddable_by'] == 'me'))
- {
- $sharing = true;
- }
- }
-
- if ($sharing)
- {
- if (array_key_exists('id', $result) )
- {
- $this->element->setData(Element::DATA_REF_ID, $result['id']);
- }
-
- if (array_key_exists('uri', $result) )
- {
- $this->element->setData(Element::DATA_NORMALIZED_URL, $result['uri']);
- }
-
- if (array_key_exists('artwork_url', $result) )
- {
- if ($result['artwork_url'])
- {
- $this->element->setData(Element::DATA_THUMB_URL, $result['artwork_url']);
- }
- else
- {
- if (array_key_exists('user', $result) )
- {
- if (array_key_exists('avatar_url', $result['user']) )
- {
- if ($result['user']['avatar_url'])
- {
- $this->element->setData(Element::DATA_THUMB_URL, $result['user']['avatar_url']);
- }
- }
- }
- }
- }
-
- if (array_key_exists('kind', $result) )
- {
- $this->element->setData(Element::DATA_TYPE, $result['kind']);
- }
-
- if (array_key_exists('downloadable', $result) )
- {
- $this->element->setData(Element::DATA_DOWNLOAD, $result['downloadable']);
- // FIXME
- $this->element->setData(Element::DATA_DOWNLOAD_URL, $this->element->getUrl().'/download');
- }
-
- if (array_key_exists('title', $result) )
- {
- $this->element->setData(Element::DATA_TITLE, $result['title']);
- }
-
- if (array_key_exists('user', $result) )
- {
- $this->element->setData(Element::DATA_ARTIST, $result['user']['username']);
- }
-
- $genres = '';
- if (array_key_exists('genre', $result) )
- {
- if (strlen($result['genre']))
- {
- $genres = $result['genre'];
- }
- }
-
- $tags_list = '';
- if (array_key_exists('tag_list', $result) )
- {
- if (strlen($result['tag_list']))
- {
- $tags_list = $result['tag_list'];
- }
- }
-
- $tags_string = $genres.' '.$tags_list.' '.str_replace(' ', '-', $genres);
- $tags_like = array();
- if (strlen($tags_string))
- {
- $tag_like = new TagLike($this->entity_manager);
- foreach (explode(' ', $tags_string) as $word)
- {
- $similar_tags = $tag_like->getSimilarTags($word, $this->element->getOwner()->getId());
- if (count($similar_tags))
- {
- if ($similar_tags['same_found'])
- {
- $tags_like[] = $similar_tags['tags'][0]['name'];
- }
- }
- }
- $tags_like[] = $genres;
- if (count($tags_like))
- {
- $this->element->setData(Element::DATA_TAGS, array_unique($tags_like));
- }
- }
-
- }
- }
- }
-
- public function proceedEmbedCode()
- {
- if (($ref_id = $this->element->getData(Element::DATA_REF_ID))
- && ($this->element->getData(Element::DATA_TYPE) == 'track' || $this->element->getData(Element::DATA_TYPE) == 'playlist' ))
- {
- $ref_id = $this->element->getUrl();
- $embed_id = md5($ref_id);
- $height = $this->container->getParameter('soundcloud_player_height');
- $this->element->setEmbed(
- '<object height="'.$height.'" width="100%" id="embed_'.$embed_id.'" '
- .'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
- <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$ref_id.'&'
- .'enable_api=true&object_id=embed_'.$embed_id.'"></param>
- <param name="allowscriptaccess" value="always"></param>
- <embed allowscriptaccess="always" height="'.$height.'" '
- .'src="http://player.soundcloud.com/player.swf?url='.$ref_id.'&enable_api=true'
- .'&object_id=embed_'.$embed_id.'" type="application/x-shockwave-flash" '
- .'width="100%" name="embed_'.$embed_id.'"></embed>
- </object>'
- );
- // $this->element->setEmbed(
- // '<iframe id="sc-widget_'.$this->element->getData(Element::DATA_REF_ID).
- // '" src="http://w.soundcloud.com/player/?url='.
- // $ref_id.'" width="100%" '.
- // 'height="'.$height.'" scrolling="no" frameborder="no"></iframe>'
- // );
- }
- }
-
- public function proceedThumbnailUrl()
- {
- if (($thumb = $this->element->getData(Element::DATA_THUMB_URL)))
- {
- $this->element->setThumbnailUrl($thumb);
- }
- }
-
- }
|