Browse Source

Merge branch 'feature/apis' into master/v0.8

Sevajol Bastien 12 years ago
parent
commit
8761cabbf6

+ 51 - 0
src/Muzich/CoreBundle/Entity/Element.php View File

24
 {
24
 {
25
   
25
   
26
   /**
26
   /**
27
+   * Identifiant de l'objet externe
28
+   * @var string 
29
+   */
30
+  const DATA_REF_ID         = "data_ref_id";
31
+  /**
32
+   * Adresse HTTP(S) de la jaquette
33
+   * @var string 
34
+   */
35
+  const DATA_THUMB_URL      = "data_thumb_url";
36
+  /**
37
+   * Titre de l'objet externe
38
+   * @var string 
39
+   */
40
+  const DATA_TITLE          = "data_title";
41
+  /**
42
+   * Nom de l'artiste
43
+   * @var string 
44
+   */
45
+  const DATA_ARTIST         = "data_artist";
46
+  /**
47
+   * Tags de l'objets externe array("tag1", "tag2", [...])
48
+   * @var string 
49
+   */
50
+  const DATA_TAGS           = "data_tags";
51
+  /**
52
+   * Type de l'objet track|album|
53
+   * @var string 
54
+   */
55
+  const DATA_TYPE           = "data_type";
56
+  /**
57
+   * Contenu téléchargeable ?
58
+   * @var string 
59
+   */
60
+  const DATA_DOWNLOAD       = "data_download";
61
+  /**
62
+   * Adresse du contenu téléchargeable
63
+   * @var string 
64
+   */
65
+  const DATA_DOWNLOAD_URL   = "data_download_url";
66
+  /**
67
+   * Don possible ?
68
+   * @var string 
69
+   */
70
+  const DATA_GIFT           = "data_gift";
71
+  /**
72
+   * Adresse pour effectuer un don
73
+   * @var string 
74
+   */
75
+  const DATA_GIFT_URL       = "data_gift_url";
76
+  
77
+  /**
27
    * @ORM\Id
78
    * @ORM\Id
28
    * @ORM\Column(type="integer")
79
    * @ORM\Column(type="integer")
29
    * @ORM\GeneratedValue(strategy="AUTO")
80
    * @ORM\GeneratedValue(strategy="AUTO")

+ 5 - 4
src/Muzich/CoreBundle/Factory/Elements/Dailymotioncom.php View File

3
 namespace Muzich\CoreBundle\Factory\Elements;
3
 namespace Muzich\CoreBundle\Factory\Elements;
4
 
4
 
5
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
+use Muzich\CoreBundle\Entity\Element;
6
 
7
 
7
 /**
8
 /**
8
  * 
9
  * 
25
     if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_clean, $preg_result))
26
     if (preg_match("#(video\/)([a-zA-Z0-9]+)([a-zA-Z0-9_-]*)#", $url_clean, $preg_result))
26
     {
27
     {
27
       $ref_id = $preg_result[2];
28
       $ref_id = $preg_result[2];
28
-      $this->element->setData('ref_id', $ref_id);
29
+      $this->element->setData(Element::DATA_REF_ID, $ref_id);
29
     }
30
     }
30
     
31
     
31
     // Récupération de données auprés de l'API
32
     // Récupération de données auprés de l'API
45
       // On récupère l'url du thumbnail
46
       // On récupère l'url du thumbnail
46
       if (isset($api_result->thumbnail_medium_url))
47
       if (isset($api_result->thumbnail_medium_url))
47
       {
48
       {
48
-        $this->element->setData('thumb_medium_url', $api_result->thumbnail_medium_url);
49
+        $this->element->setData(Element::DATA_THUMB_URL, $api_result->thumbnail_medium_url);
49
       }
50
       }
50
     }
51
     }
51
   }
52
   }
52
   
53
   
53
   public function proceedEmbedCode()
54
   public function proceedEmbedCode()
54
   {
55
   {
55
-    if (($ref_id = $this->element->getData('ref_id')))
56
+    if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
56
     {
57
     {
57
       $width = $this->container->getParameter('dailymotion_player_width');
58
       $width = $this->container->getParameter('dailymotion_player_width');
58
       $height = $this->container->getParameter('dailymotion_player_height');
59
       $height = $this->container->getParameter('dailymotion_player_height');
65
   
66
   
66
   public function proceedThumbnailUrl()
67
   public function proceedThumbnailUrl()
67
   {
68
   {
68
-    if (($thumb = $this->element->getData('thumb_medium_url')))
69
+    if (($thumb = $this->element->getData(Element::DATA_THUMB_URL)))
69
     {
70
     {
70
       $this->element->setThumbnailUrl($thumb);
71
       $this->element->setThumbnailUrl($thumb);
71
     }
72
     }

+ 7 - 5
src/Muzich/CoreBundle/Factory/Elements/Deezercom.php View File

3
 namespace Muzich\CoreBundle\Factory\Elements;
3
 namespace Muzich\CoreBundle\Factory\Elements;
4
 
4
 
5
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
+use Muzich\CoreBundle\Entity\Element;
6
 
7
 
7
 /**
8
 /**
8
  * 
9
  * 
44
       $ref_id = $chaines[1];
45
       $ref_id = $chaines[1];
45
     }
46
     }
46
     
47
     
47
-    $this->element->setData('type'  , $type);
48
-    $this->element->setData('ref_id', $ref_id);
48
+    $this->element->setData(Element::DATA_TYPE  , $type);
49
+    $this->element->setData(Element::DATA_REF_ID, $ref_id);
49
     
50
     
50
     if ($type && $ref_id)
51
     if ($type && $ref_id)
51
     {
52
     {
60
 
61
 
61
       if (isset($result->cover))
62
       if (isset($result->cover))
62
       {
63
       {
63
-        $this->element->setData('cover_url', $result->cover);
64
+        $this->element->setData(Element::DATA_THUMB_URL, $result->cover);
64
       }
65
       }
65
     }
66
     }
66
   }
67
   }
67
   
68
   
68
   public function proceedEmbedCode()
69
   public function proceedEmbedCode()
69
   {
70
   {
70
-    if (($ref_id = $this->element->getData('ref_id')) && ($type = $this->element->getData('type')))
71
+    if (($ref_id = $this->element->getData(Element::DATA_REF_ID)) 
72
+      && ($type = $this->element->getData(Element::DATA_TYPE)))
71
     {
73
     {
72
       $width = $this->container->getParameter('deezer_player_width');
74
       $width = $this->container->getParameter('deezer_player_width');
73
       $heigth = $this->container->getParameter('deezer_player_height');
75
       $heigth = $this->container->getParameter('deezer_player_height');
82
   
84
   
83
   public function proceedThumbnailUrl()
85
   public function proceedThumbnailUrl()
84
   {
86
   {
85
-    if (($thumb = $this->element->getData('cover_url')))
87
+    if (($thumb = $this->element->getData(Element::DATA_TYPE)))
86
     {
88
     {
87
       $this->element->setThumbnailUrl($thumb);
89
       $this->element->setThumbnailUrl($thumb);
88
     }
90
     }

+ 79 - 32
src/Muzich/CoreBundle/Factory/Elements/Jamendocom.php View File

3
 namespace Muzich\CoreBundle\Factory\Elements;
3
 namespace Muzich\CoreBundle\Factory\Elements;
4
 
4
 
5
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
+use Muzich\CoreBundle\Entity\Element;
6
 
7
 
7
 /**
8
 /**
8
  * 
9
  * 
15
   /**
16
   /**
16
    *  ALBUM = http://www.jamendo.com/fr/album/30661
17
    *  ALBUM = http://www.jamendo.com/fr/album/30661
17
    *  TRACK = http://www.jamendo.com/fr/track/207079
18
    *  TRACK = http://www.jamendo.com/fr/track/207079
19
+   * 
20
+   * API: http://developer.jamendo.com/fr/wiki/Musiclist2ApiFields
18
    */
21
    */
19
   public function retrieveDatas()
22
   public function retrieveDatas()
20
   {
23
   {
21
     $url_clean = $this->getCleanedUrl();
24
     $url_clean = $this->getCleanedUrl();
22
-    
25
+        
23
     // album
26
     // album
27
+    // http://www.jamendo.com/fr/album/3409
24
     $type   = null;
28
     $type   = null;
25
     $ref_id = null;
29
     $ref_id = null;
26
     if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $url_clean, $chaines))
30
     if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $url_clean, $chaines))
29
       $ref_id = $chaines[1];
33
       $ref_id = $chaines[1];
30
     }
34
     }
31
     // track
35
     // track
36
+    // http://www.jamendo.com/fr/track/894974
32
     else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $url_clean, $chaines))
37
     else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $url_clean, $chaines))
33
     {
38
     {
34
       $type = 'track';
39
       $type = 'track';
35
       $ref_id = $chaines[1];
40
       $ref_id = $chaines[1];
36
     }
41
     }
42
+    // album new ver
43
+    // http://www.jamendo.com/fr/list/a45666/proceed-positron...
44
+    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/list\/a([0-9]+)\/.#", $url_clean, $chaines))
45
+    {
46
+      $type   = 'album';
47
+      $ref_id = $chaines[1];
48
+    }
49
+    // track new ver
50
+    // http://www.jamendo.com/fr/track/347602/come-come
51
+    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)\/.#", $url_clean, $chaines))
52
+    {
53
+      $type = 'track';
54
+      $ref_id = $chaines[1];
55
+    }
37
     
56
     
38
-    $this->element->setData('type'  , $type);
39
-    $this->element->setData('ref_id', $ref_id);
57
+    $this->element->setData(Element::DATA_TYPE  , $type);
58
+    $this->element->setData(Element::DATA_REF_ID, $ref_id);
40
     
59
     
41
     // Récupération de données avec l'API
60
     // Récupération de données avec l'API
42
     $api_url = null;
61
     $api_url = null;
43
     switch ($type)
62
     switch ($type)
44
     {
63
     {
45
       case 'album':
64
       case 'album':
46
-        $api_url = "http://api.jamendo.com/get2/image/album/json/?id=".$ref_id;
65
+        $api_url = "http://api.jamendo.com/get2/"
66
+          ."id+name+url+image+artist_name+artist_url/album/jsonpretty/?album_id=".$ref_id;
67
+        $api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/album_tag/?album_id=".$ref_id;
47
       break;
68
       break;
48
     
69
     
49
-      /**
50
-       * Lorsque l'on a une track, il faut récupérer les infos sur l'album dans laquelle
51
-       * est la track
52
-       */
53
       case 'track':
70
       case 'track':
54
-        $get_album_url = "http://www.jamendo.com/get/album/id/track/page/json/".$ref_id.'/';
55
-
56
-        $ch = curl_init($get_album_url);
57
-        curl_setopt_array($ch, array(
58
-          CURLOPT_RETURNTRANSFER => true,
59
-          CURLOPT_HTTPHEADER => array('Content-type: application/json')
60
-        ));
61
-        $result = json_decode(curl_exec($ch));
62
-        if (count($result))
63
-        {
64
-          $album_url = str_replace('http://www.jamendo.com', '', $result[0]);
65
-
66
-          $expl_alb = null;
67
-          if (preg_match("#^\/album\/([0-9]+)#", $album_url, $expl_alb))
68
-          {
69
-            $id_album = $expl_alb[1];
70
-            $api_url = "http://api.jamendo.com/get2/image/album/json/?id=".$id_album;
71
-          }
72
-        }
71
+        $api_url = "http://api.jamendo.com/get2/"
72
+          ."id+name+url+image+artist_name+artist_url+track_name/album/json/?track_id=".$ref_id;
73
+        $api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/track_tag/?track_id=".$ref_id;
73
       break;
74
       break;
74
     }
75
     }
75
     
76
     
81
         CURLOPT_HTTPHEADER => array('Content-type: text/plain')
82
         CURLOPT_HTTPHEADER => array('Content-type: text/plain')
82
       );
83
       );
83
       curl_setopt_array( $ch, $options );
84
       curl_setopt_array( $ch, $options );
84
-      $result = json_decode(curl_exec($ch));
85
-      
85
+      $result = json_decode(curl_exec($ch), true);
86
+            
86
       if (count($result))
87
       if (count($result))
87
       {
88
       {
88
-        $this->element->setData('thumb_url', $result[0]);
89
+        // Thumb
90
+        if (array_key_exists('image', $result[0]))
91
+        {
92
+          $this->element->setData(Element::DATA_THUMB_URL, $result[0]['image']);
93
+        }
94
+        
95
+        // Album name
96
+        if (array_key_exists('name', $result[0]) && $type == 'album')
97
+        {
98
+          $this->element->setData(Element::DATA_TITLE, $result[0]['name']);
99
+        }
100
+        
101
+        // Artist name
102
+        if (array_key_exists('artist_name', $result[0]))
103
+        {
104
+          $this->element->setData(Element::DATA_ARTIST, $result[0]['artist_name']);
105
+        }
106
+        
107
+        // track name
108
+        if (array_key_exists('track_name', $result[0])  && $type == 'track')
109
+        {
110
+          $this->element->setData(Element::DATA_TITLE, $result[0]['track_name']);
111
+        }
112
+        
113
+        // Maintenant au tour des tags (deuxième requete a l'api)
114
+        $ch = curl_init($api_tag_url);
115
+        $options = array(
116
+          CURLOPT_RETURNTRANSFER => true,
117
+          CURLOPT_HTTPHEADER => array('Content-type: text/plain')
118
+        );
119
+        curl_setopt_array( $ch, $options );
120
+        $result = json_decode(curl_exec($ch), true);
121
+      
122
+        if (count($result))
123
+        {
124
+          $tags = array();
125
+          foreach ($result as $tag)
126
+          {
127
+            $tags[] = $tag['name'];
128
+          }
129
+          
130
+          $this->element->setData(Element::DATA_TAGS, $tags);
131
+        }
89
       }
132
       }
90
     }
133
     }
134
+    
135
+    // Un contenu jamendo est toujours téléchargeable
136
+    $this->element->setData(Element::DATA_DOWNLOAD, true);
91
   }
137
   }
92
   
138
   
93
   public function proceedEmbedCode()
139
   public function proceedEmbedCode()
94
   {
140
   {
95
-    if (($ref_id = $this->element->getData('ref_id')) && ($type = $this->element->getData('type')))
141
+    if (($ref_id = $this->element->getData(Element::DATA_REF_ID)) 
142
+      && ($type = $this->element->getData(Element::DATA_TYPE)))
96
     {
143
     {
97
       $height = $this->container->getParameter('jamendo_player_height');
144
       $height = $this->container->getParameter('jamendo_player_height');
98
       $width = $this->container->getParameter('jamendo_player_width');
145
       $width = $this->container->getParameter('jamendo_player_width');
118
   
165
   
119
   public function proceedThumbnailUrl()
166
   public function proceedThumbnailUrl()
120
   {
167
   {
121
-    if (($thumb = $this->element->getData('thumb_url')))
168
+    if (($thumb = $this->element->getData(Element::DATA_THUMB_URL)))
122
     {
169
     {
123
       $this->element->setThumbnailUrl($thumb);
170
       $this->element->setThumbnailUrl($thumb);
124
     }
171
     }

+ 117 - 15
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php View File

3
 namespace Muzich\CoreBundle\Factory\Elements;
3
 namespace Muzich\CoreBundle\Factory\Elements;
4
 
4
 
5
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
+use Muzich\CoreBundle\Entity\Element;
6
 
7
 
7
 /**
8
 /**
8
  * 
9
  * 
20
   {
21
   {
21
     $url_clean = $this->getCleanedUrl();
22
     $url_clean = $this->getCleanedUrl();
22
     
23
     
23
-    $ref_id = null;
24
-    // ??SET
24
+    $match = false;
25
+    //
25
     if (preg_match("#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
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
     else if (preg_match("#^\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+#", $url_clean, $chaines))
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
     // On en gère pas encore les recherches
37
     // On en gère pas encore les recherches
36
     if (preg_match("#\/search\?q#", $url_clean, $chaines))
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
     // récupération de données avec l'API
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
       $options = array(
52
       $options = array(
49
         CURLOPT_RETURNTRANSFER => true,
53
         CURLOPT_RETURNTRANSFER => true,
62
       }
66
       }
63
 
67
 
64
       $getjsonurl = $result->location;
68
       $getjsonurl = $result->location;
69
+      // On a maintenant la bonne url pour demander les infos
65
       $ch = curl_init($getjsonurl);
70
       $ch = curl_init($getjsonurl);
66
       curl_setopt_array($ch, $options);
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
   public function proceedEmbedCode()
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
       $embed_id = md5($ref_id);
183
       $embed_id = md5($ref_id);
82
       $height = $this->container->getParameter('soundcloud_player_height');
184
       $height = $this->container->getParameter('soundcloud_player_height');
83
       $this->element->setEmbed(
185
       $this->element->setEmbed(
97
   
199
   
98
   public function proceedThumbnailUrl()
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
       $this->element->setThumbnailUrl($thumb);
204
       $this->element->setThumbnailUrl($thumb);
103
     }
205
     }

+ 2 - 1
src/Muzich/CoreBundle/Factory/Elements/Youtube.php View File

3
 namespace Muzich\CoreBundle\Factory\Elements;
3
 namespace Muzich\CoreBundle\Factory\Elements;
4
 
4
 
5
 use Muzich\CoreBundle\Factory\Elements\Youtubecom;
5
 use Muzich\CoreBundle\Factory\Elements\Youtubecom;
6
+use Muzich\CoreBundle\Entity\Element;
6
 
7
 
7
 /**
8
 /**
8
  * 
9
  * 
22
       $ref_id = $chaines[1];
23
       $ref_id = $chaines[1];
23
     }
24
     }
24
     
25
     
25
-    $this->element->setData('ref_id', $ref_id);
26
+    $this->element->setData(Element::DATA_REF_ID, $ref_id);
26
     
27
     
27
     // Données API
28
     // Données API
28
     if ($ref_id)
29
     if ($ref_id)

+ 16 - 4
src/Muzich/CoreBundle/Factory/Elements/Youtubecom.php View File

3
 namespace Muzich\CoreBundle\Factory\Elements;
3
 namespace Muzich\CoreBundle\Factory\Elements;
4
 
4
 
5
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
+use Muzich\CoreBundle\Entity\Element;
6
 
7
 
7
 /**
8
 /**
8
  * 
9
  * 
12
 class Youtubecom extends ElementFactory
13
 class Youtubecom extends ElementFactory
13
 {
14
 {
14
   
15
   
16
+  protected function proceedAPIDatas($ref_id)
17
+  {
18
+    $video_data_dom = new \DOMDocument;
19
+    $video_data_dom->load("http://gdata.youtube.com/feeds/api/videos/". $ref_id);
20
+    
21
+    if (($title = $video_data_dom->getElementsByTagName("title")->item(0)->nodeValue))
22
+    {
23
+      $this->element->setData(Element::DATA_TITLE, $title);
24
+    }
25
+  }
26
+  
15
   public function retrieveDatas()
27
   public function retrieveDatas()
16
   {
28
   {
17
     $url_clean = $this->getCleanedUrl();
29
     $url_clean = $this->getCleanedUrl();
26
       $ref_id = $chaines[2];
38
       $ref_id = $chaines[2];
27
     }
39
     }
28
     
40
     
29
-    $this->element->setData('ref_id', $ref_id);
41
+    $this->element->setData(Element::DATA_REF_ID, $ref_id);
30
     
42
     
31
     // Données API TODO: REFACTORISER
43
     // Données API TODO: REFACTORISER
32
     if ($ref_id)
44
     if ($ref_id)
33
     {
45
     {
34
-      
46
+      $this->proceedAPIDatas($ref_id);
35
     }
47
     }
36
   }
48
   }
37
   
49
   
38
   public function proceedEmbedCode()
50
   public function proceedEmbedCode()
39
   {
51
   {
40
-    if (($ref_id = $this->element->getData('ref_id')))
52
+    if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
41
     {
53
     {
42
       $width = $this->container->getParameter('youtube_player_width');
54
       $width = $this->container->getParameter('youtube_player_width');
43
       $height = $this->container->getParameter('youtube_player_height');
55
       $height = $this->container->getParameter('youtube_player_height');
51
   
63
   
52
   public function proceedThumbnailUrl()
64
   public function proceedThumbnailUrl()
53
   {
65
   {
54
-    if (($ref_id = $this->element->getData('ref_id')))
66
+    if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
55
     {
67
     {
56
       $this->element->setThumbnailUrl(
68
       $this->element->setThumbnailUrl(
57
         'http://img.youtube.com/vi/'.$ref_id.'/default.jpg'        
69
         'http://img.youtube.com/vi/'.$ref_id.'/default.jpg'