Browse Source

Evolution #100: Ecrire des récupérations de vignette

bastien 13 years ago
parent
commit
f7e947792f

+ 28 - 0
src/Muzich/CoreBundle/ElementFactory/Site/DeezercomFactory.php View File

@@ -47,6 +47,34 @@ class DeezercomFactory extends BaseFactory
47 47
     
48 48
     return $embed;
49 49
   }
50
+  
51
+  public function getThumbnailUrl()
52
+  {
53
+    $url_object = $this->getCleanedUrl();
54
+    $url = null;
55
+    
56
+    // album
57
+    // http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398
58
+    if (preg_match("#^\/[a-zA-Z_-]+\/music\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+-([0-9]+)#", $url_object, $chaines))
59
+    {
60
+      $id = $chaines[1];
61
+      $ch = curl_init('http://api.deezer.com/2.0/album/'.$id);
62
+      $options = array(
63
+        CURLOPT_RETURNTRANSFER => true,
64
+        CURLOPT_HTTPHEADER => array('Content-type: application/json')
65
+      );
66
+      curl_setopt_array( $ch, $options );
67
+      $result = json_decode(curl_exec($ch));
68
+      
69
+      if (isset($result->cover))
70
+      {
71
+        $url = $result->cover;
72
+      }
73
+    }
74
+    
75
+    return $url;
76
+  }
77
+  
50 78
 }
51 79
 
52 80
 ?>

+ 60 - 0
src/Muzich/CoreBundle/ElementFactory/Site/JamendocomFactory.php View File

@@ -52,6 +52,66 @@ class JamendocomFactory extends BaseFactory
52 52
     
53 53
     return null;
54 54
   }
55
+  
56
+  public function getThumbnailUrl()
57
+  {
58
+    $url_object = $this->getCleanedUrl();
59
+    $url = null;
60
+    
61
+    // http://www.jamendo.com/fr/album/30661
62
+    if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $url_object, $chaines))
63
+    {
64
+      $id_album = $chaines[1];
65
+      $get_url = "http://api.jamendo.com/get2/image/album/json/?id=".$id_album;
66
+    }
67
+    // http://www.jamendo.com/fr/track/207079
68
+    else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $url_object, $chaines))
69
+    {
70
+      $id_track = $chaines[1];
71
+      $get_url = "http://api.jamendo.com/get2/image/track/json/?id=".$id_track;
72
+    }
73
+    
74
+    if ($get_url)
75
+    {
76
+      $ch = curl_init($get_url);
77
+      $options = array(
78
+        CURLOPT_RETURNTRANSFER => true,
79
+        CURLOPT_HTTPHEADER => array('Content-type: application/json')
80
+      );
81
+      curl_setopt_array( $ch, $options );
82
+      $result = json_decode(curl_exec($ch));
83
+      
84
+      if (count($result))
85
+      {
86
+        $url = $result[0];
87
+      }
88
+    }
89
+    
90
+      
91
+    
92
+
93
+    
94
+    
95
+//    if (isset($result->errors))
96
+//    {
97
+//      if (count($result->errors))
98
+//      {
99
+//        return null;
100
+//      }
101
+//    }
102
+//    
103
+//    $getjsonurl = $result->location;
104
+//    $ch = curl_init($getjsonurl);
105
+//    curl_setopt_array($ch, $options);
106
+//    $result = json_decode(curl_exec($ch));
107
+//    
108
+//    $url = $result->artwork_url;
109
+    
110
+    
111
+    return $url;
112
+  }
113
+  
114
+  //http://api.jamendo.com/get2/name+url/album/json/?id=116
55 115
 }
56 116
 
57 117
 ?>