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
   const TYPE_ALBUM = 'album';
87
   const TYPE_ALBUM = 'album';
88
   const TYPE_PLAYLIST =  'playlist';
88
   const TYPE_PLAYLIST =  'playlist';
89
   const TYPE_OTHER = 'other';
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
   protected $api_connector;
21
   protected $api_connector;
22
   protected $url_analyzer;
22
   protected $url_analyzer;
23
   
23
   
24
-  protected $url_matchs = array();
24
+  public $url_matchs = array();
25
   
25
   
26
   /**
26
   /**
27
    *
27
    *
108
     return json_decode(curl_exec($api_url), true);
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
 use Muzich\CoreBundle\Factory\ElementFactory;
5
 use Muzich\CoreBundle\Factory\ElementFactory;
6
 use Muzich\CoreBundle\Entity\Element;
6
 use Muzich\CoreBundle\Entity\Element;
7
 use Muzich\CoreBundle\Factory\UrlMatchs;
7
 use Muzich\CoreBundle\Factory\UrlMatchs;
8
+use Symfony\Component\DependencyInjection\Container;
9
+use Doctrine\ORM\EntityManager;
8
 
10
 
9
 class Jamendocom extends ElementFactory
11
 class Jamendocom extends ElementFactory
10
 {
12
 {
11
   
13
   
12
   public function __construct(Element $element, Container $container, EntityManager $entity_manager)
14
   public function __construct(Element $element, Container $container, EntityManager $entity_manager)
13
   {
15
   {
14
-    parent::__construct($element, $container, $entity_manager);
15
     $this->url_matchs = UrlMatchs::$jamendo;
16
     $this->url_matchs = UrlMatchs::$jamendo;
17
+    parent::__construct($element, $container, $entity_manager);
16
   }
18
   }
17
   
19
   
18
   public function getStreamData()
20
   public function getStreamData()
64
   
66
   
65
   protected function getApiTagUrl()
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
       .$this->url_analyzer->getRefId();
70
       .$this->url_analyzer->getRefId();
69
   }
71
   }
70
   
72
   
87
         $this->element->setData(Element::DATA_TITLE, $response->get(array(0 => 'track_name')));
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
           $tags[] = $tag['name'];
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
     // Un contenu jamendo est toujours téléchargeable
104
     // Un contenu jamendo est toujours téléchargeable

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

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

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

6
 
6
 
7
 class UrlMatchs
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
   public static $jamendo = array(
13
   public static $jamendo = array(
10
     Element::TYPE_TRACK => array(
14
     Element::TYPE_TRACK => array(
11
       // http://www.jamendo.com/fr/track/894974
15
       // http://www.jamendo.com/fr/track/894974
22
   );
26
   );
23
   
27
   
24
   public static $soundcloud = array(
28
   public static $soundcloud = array(
29
+    Element::TYPE_NOTMATCH => array(
30
+      "#\/search\?q#" => null
31
+    ),
25
     Element::TYPE_OTHER => array(
32
     Element::TYPE_OTHER => array(
26
       // http://soundcloud.com/matas/sets/library-project
33
       // http://soundcloud.com/matas/sets/library-project
27
       "#^\/[a-zA-Z0-9_-]+\/sets\/[a-zA-Z0-9_-]+#" => null,
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
       $site_factory = $this->getFactory();
137
       $site_factory = $this->getFactory();
138
       // On récupères les datas de l'élément
138
       // On récupères les datas de l'élément
139
       $site_factory->setUrlDatas();
139
       $site_factory->setUrlDatas();
140
-      if ($site_factory->url_analyzer->haveMatch())
140
+      if ($site_factory->getUrlAnalyzer()->haveMatch())
141
       {
141
       {
142
         $site_factory->proceedDatas();
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
     $this->assertEquals(null, $url_analyzer->getRefId());
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
       {
25
       {
26
         if (preg_match($expression, $this->url, $preg_result))
26
         if (preg_match($expression, $this->url, $preg_result))
27
         {
27
         {
28
+          if ($type == Element::TYPE_NOTMATCH)
29
+          {
30
+            return false;
31
+          }
32
+          
28
           if (array_key_exists($ref_id_position, $preg_result))
33
           if (array_key_exists($ref_id_position, $preg_result))
29
           {
34
           {
30
             return array(
35
             return array(