Просмотр исходного кода

Evolution #383: Gestion des api indisponibles

Sevajol Bastien 11 лет назад
Родитель
Сommit
32c97f0edc

+ 2 - 2
src/Muzich/CoreBundle/Factory/Elements/Dailymotioncom.php Просмотреть файл

@@ -23,7 +23,7 @@ class Dailymotioncom extends ElementFactory
23 23
     $ref_id = null;
24 24
     
25 25
     // Récupération de l'id
26
-    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))
27 27
     {
28 28
       $ref_id = $preg_result[2];
29 29
       $this->element->setData(Element::DATA_REF_ID, $ref_id);
@@ -42,7 +42,7 @@ class Dailymotioncom extends ElementFactory
42 42
       
43 43
       curl_setopt_array($api_url, $options);
44 44
       $api_result = json_decode(curl_exec($api_url));
45
-      
45
+            
46 46
       // On récupère l'url du thumbnail
47 47
       if (isset($api_result->thumbnail_medium_url))
48 48
       {

+ 18 - 6
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php Просмотреть файл

@@ -57,14 +57,26 @@ class Soundcloudcom extends ElementFactory
57 57
       curl_setopt_array( $ch, $options );
58 58
       $result = json_decode(curl_exec($ch));
59 59
 
60
-      if (isset($result->errors))
60
+      if (!isset($result->errors))
61 61
       {
62
-        if (count($result->errors))
63
-        {
64
-          return null;
65
-        }
62
+        return;
66 63
       }
67
-
64
+      
65
+      if (count($result->errors))
66
+      {
67
+        return;  
68
+      }
69
+      
70
+      if (!isset($result->location))
71
+      {
72
+        return null;
73
+      }
74
+      
75
+      if (!$result->location)
76
+      {
77
+        return null;
78
+      }
79
+      
68 80
       $getjsonurl = $result->location;
69 81
       // On a maintenant la bonne url pour demander les infos
70 82
       $ch = curl_init($getjsonurl);

+ 16 - 4
src/Muzich/CoreBundle/Factory/Elements/Youtubecom.php Просмотреть файл

@@ -16,11 +16,23 @@ class Youtubecom extends ElementFactory
16 16
   protected function proceedAPIDatas($ref_id)
17 17
   {
18 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))
19
+    try {
20
+      $video_data_dom->load("http://gdata.youtube.com/feeds/api/videos/". $ref_id);
21
+
22
+      if ($video_data_dom->getElementsByTagName("title"))
23
+      {
24
+        if ($video_data_dom->getElementsByTagName("title")->item(0))
25
+        {
26
+          if (($title = $video_data_dom->getElementsByTagName("title")->item(0)->nodeValue))
27
+          {
28
+            $this->element->setData(Element::DATA_TITLE, $title);
29
+          }
30
+        }
31
+      }
32
+    }
33
+    catch (\ErrorException $e)
22 34
     {
23
-      $this->element->setData(Element::DATA_TITLE, $title);
35
+      // Api injoignable
24 36
     }
25 37
   }
26 38