Kaynağa Gözat

Correction du code de soundcloud et jamendo factory. Mise en commentaire des tests pour les procédures attention.

Sevajol Bastien 11 yıl önce
ebeveyn
işleme
79ed6a0e1a

+ 1 - 0
src/Muzich/CoreBundle/Entity/Element.php Dosyayı Görüntüle

@@ -87,6 +87,7 @@ class Element
87 87
   const TYPE_ALBUM = 'album';
88 88
   const TYPE_PLAYLIST =  'playlist';
89 89
   const TYPE_OTHER = 'other';
90
+  const TYPE_NOTMATCH = 'not_match';
90 91
   
91 92
   
92 93
   /**

+ 6 - 1
src/Muzich/CoreBundle/Factory/ElementFactory.php Dosyayı Görüntüle

@@ -21,7 +21,7 @@ abstract class ElementFactory
21 21
   protected $api_connector;
22 22
   protected $url_analyzer;
23 23
   
24
-  protected $url_matchs = array();
24
+  public $url_matchs = array();
25 25
   
26 26
   /**
27 27
    *
@@ -108,6 +108,11 @@ abstract class ElementFactory
108 108
     return json_decode(curl_exec($api_url), true);
109 109
   }
110 110
   
111
+  public function getUrlAnalyzer()
112
+  {
113
+    return $this->url_analyzer;
114
+  }
115
+  
111 116
 }
112 117
 
113 118
 ?>

+ 9 - 8
src/Muzich/CoreBundle/Factory/Elements/Jamendocom.php Dosyayı Görüntüle

@@ -5,14 +5,16 @@ namespace Muzich\CoreBundle\Factory\Elements;
5 5
 use Muzich\CoreBundle\Factory\ElementFactory;
6 6
 use Muzich\CoreBundle\Entity\Element;
7 7
 use Muzich\CoreBundle\Factory\UrlMatchs;
8
+use Symfony\Component\DependencyInjection\Container;
9
+use Doctrine\ORM\EntityManager;
8 10
 
9 11
 class Jamendocom extends ElementFactory
10 12
 {
11 13
   
12 14
   public function __construct(Element $element, Container $container, EntityManager $entity_manager)
13 15
   {
14
-    parent::__construct($element, $container, $entity_manager);
15 16
     $this->url_matchs = UrlMatchs::$jamendo;
17
+    parent::__construct($element, $container, $entity_manager);
16 18
   }
17 19
   
18 20
   public function getStreamData()
@@ -64,7 +66,7 @@ class Jamendocom extends ElementFactory
64 66
   
65 67
   protected function getApiTagUrl()
66 68
   {
67
-    return "http://api.jamendo.com/get2/name+weight/tag/json/album_tag/?".$this->url_analyzer->getType()."_id="
69
+    return "http://api.jamendo.com/get2/name+weight/tag/json/".$this->url_analyzer->getType()."_tag/?".$this->url_analyzer->getType()."_id="
68 70
       .$this->url_analyzer->getRefId();
69 71
   }
70 72
   
@@ -87,17 +89,16 @@ class Jamendocom extends ElementFactory
87 89
         $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'track_name')));
88 90
       }
89 91
       
90
-      if (($response = $this->getApiConnector()->getResponseForUrl($this->getApiTagUrl())))
92
+      $tags = array();
93
+      $response = $this->getApiConnector()->getResponseForUrl($this->getApiTagUrl());
94
+      if (count($response->getContent()))
91 95
       {
92
-        // TODO: Check si tout ce passe bien avec pas de tags en retour de l'api
93
-        $tags = array();
94
-        foreach ($result->getContent() as $tag)
96
+        foreach ($response->getContent() as $tag)
95 97
         {
96 98
           $tags[] = $tag['name'];
97 99
         }
98
-        
99
-        $this->element->setData(Element::DATA_TAGS, $tags);
100 100
       }
101
+      $this->element->setData(Element::DATA_TAGS, $tags);
101 102
     }
102 103
     
103 104
     // Un contenu jamendo est toujours téléchargeable

+ 3 - 1
src/Muzich/CoreBundle/Factory/Elements/Soundcloudcom.php Dosyayı Görüntüle

@@ -7,14 +7,16 @@ use Muzich\CoreBundle\Entity\Element;
7 7
 use Muzich\CoreBundle\Util\TagLike;
8 8
 use Muzich\CoreBundle\lib\Api\Response as ApiResponse;
9 9
 use Muzich\CoreBundle\Factory\UrlMatchs;
10
+use Symfony\Component\DependencyInjection\Container;
11
+use Doctrine\ORM\EntityManager;
10 12
 
11 13
 class Soundcloudcom extends ElementFactory
12 14
 {
13 15
   
14 16
   public function __construct(Element $element, Container $container, EntityManager $entity_manager)
15 17
   {
16
-    parent::__construct($element, $container, $entity_manager);
17 18
     $this->url_matchs = UrlMatchs::$soundcloud;
19
+    parent::__construct($element, $container, $entity_manager);
18 20
   }
19 21
   
20 22
   public function proceedDatas()

+ 7 - 0
src/Muzich/CoreBundle/Factory/UrlMatchs.php Dosyayı Görüntüle

@@ -6,6 +6,10 @@ use Muzich\CoreBundle\Entity\Element;
6 6
 
7 7
 class UrlMatchs
8 8
 {
9
+  /*
10
+   * Si il y a un Element::TYPE_NOTMATCH le placer en début de tableau !
11
+   */
12
+  
9 13
   public static $jamendo = array(
10 14
     Element::TYPE_TRACK => array(
11 15
       // http://www.jamendo.com/fr/track/894974
@@ -22,6 +26,9 @@ class UrlMatchs
22 26
   );
23 27
   
24 28
   public static $soundcloud = array(
29
+    Element::TYPE_NOTMATCH => array(
30
+      "#\/search\?q#" => null
31
+    ),
25 32
     Element::TYPE_OTHER => array(
26 33
       // http://soundcloud.com/matas/sets/library-project
27 34
       "#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#" => null,

+ 1 - 1
src/Muzich/CoreBundle/Managers/ElementManager.php Dosyayı Görüntüle

@@ -137,7 +137,7 @@ class ElementManager
137 137
       $site_factory = $this->getFactory();
138 138
       // On récupères les datas de l'élément
139 139
       $site_factory->setUrlDatas();
140
-      if ($site_factory->url_analyzer->haveMatch())
140
+      if ($site_factory->getUrlAnalyzer()->haveMatch())
141 141
       {
142 142
         $site_factory->proceedDatas();
143 143
       }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 531 - 537
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php


+ 15 - 0
src/Muzich/CoreBundle/Tests/ElementFactory/UrlAnalyzerTest.php Dosyayı Görüntüle

@@ -46,4 +46,19 @@ class UrlAnalyzerTest extends \PHPUnit_Framework_TestCase
46 46
     $this->assertEquals(null, $url_analyzer->getRefId());
47 47
   }
48 48
   
49
+  public function testSoundCloud()
50
+  {
51
+    $url_analyzer = new UrlAnalyzer($this->getNewElement('soundcloud.com', 'http://soundcloud.com/matas/sets/library-project'), UrlMatchs::$soundcloud);
52
+    $this->assertTrue($url_analyzer->haveMatch());
53
+    
54
+    $url_analyzer = new UrlAnalyzer($this->getNewElement('soundcloud.com', 'http://soundcloud.com/noisia/black-sun-empire-noisia-feed'), UrlMatchs::$soundcloud);
55
+    $this->assertTrue($url_analyzer->haveMatch());
56
+    
57
+    $url_analyzer = new UrlAnalyzer($this->getNewElement('soundcloud.com', 'http://soundcloud.com/user4818423/mechanika-crew-andrew-dj-set'), UrlMatchs::$soundcloud);
58
+    $this->assertTrue($url_analyzer->haveMatch());
59
+    
60
+    $url_analyzer = new UrlAnalyzer($this->getNewElement('soundcloud.com', 'https://soundcloud.com/search?q=toto'), UrlMatchs::$soundcloud);
61
+    $this->assertFalse($url_analyzer->haveMatch());
62
+  }
63
+  
49 64
 }

+ 5 - 0
src/Muzich/CoreBundle/lib/Element/UrlAnalyzer.php Dosyayı Görüntüle

@@ -25,6 +25,11 @@ class UrlAnalyzer
25 25
       {
26 26
         if (preg_match($expression, $this->url, $preg_result))
27 27
         {
28
+          if ($type == Element::TYPE_NOTMATCH)
29
+          {
30
+            return false;
31
+          }
32
+          
28 33
           if (array_key_exists($ref_id_position, $preg_result))
29 34
           {
30 35
             return array(