Parcourir la source

Fix Vimeo engine.

Cqoicebordel il y a 9 ans
Parent
révision
ab273e2faa
2 fichiers modifiés avec 41 ajouts et 24 suppressions
  1. 6
    6
      searx/engines/vimeo.py
  2. 35
    18
      searx/tests/engines/test_vimeo.py

+ 6
- 6
searx/engines/vimeo.py Voir le fichier

27
 search_url = base_url + '/search/page:{pageno}?{query}'
27
 search_url = base_url + '/search/page:{pageno}?{query}'
28
 
28
 
29
 # specific xpath variables
29
 # specific xpath variables
30
-results_xpath = '//div[@id="browse_content"]/ol/li'
31
-url_xpath = './a/@href'
32
-title_xpath = './a/div[@class="data"]/p[@class="title"]'
33
-content_xpath = './a/img/@src'
34
-publishedDate_xpath = './/p[@class="meta"]//attribute::datetime'
30
+results_xpath = '//div[contains(@class,"results_grid")]/ul/li'
31
+url_xpath = './/a/@href'
32
+title_xpath = './/span[@class="title"]'
33
+thumbnail_xpath = './/img[@class="js-clip_thumbnail_image"]/@src'
34
+publishedDate_xpath = './/time/attribute::datetime'
35
 
35
 
36
 embedded_url = '<iframe data-src="//player.vimeo.com/video{videoid}" ' +\
36
 embedded_url = '<iframe data-src="//player.vimeo.com/video{videoid}" ' +\
37
     'width="540" height="304" frameborder="0" ' +\
37
     'width="540" height="304" frameborder="0" ' +\
58
         videoid = result.xpath(url_xpath)[0]
58
         videoid = result.xpath(url_xpath)[0]
59
         url = base_url + videoid
59
         url = base_url + videoid
60
         title = p.unescape(extract_text(result.xpath(title_xpath)))
60
         title = p.unescape(extract_text(result.xpath(title_xpath)))
61
-        thumbnail = extract_text(result.xpath(content_xpath)[0])
61
+        thumbnail = extract_text(result.xpath(thumbnail_xpath)[0])
62
         publishedDate = parser.parse(extract_text(result.xpath(publishedDate_xpath)[0]))
62
         publishedDate = parser.parse(extract_text(result.xpath(publishedDate_xpath)[0]))
63
         embedded = embedded_url.format(videoid=videoid)
63
         embedded = embedded_url.format(videoid=videoid)
64
 
64
 

+ 35
- 18
searx/tests/engines/test_vimeo.py Voir le fichier

1
+# -*- coding: utf-8 -*-
1
 from collections import defaultdict
2
 from collections import defaultdict
2
 import mock
3
 import mock
3
 from searx.engines import vimeo
4
 from searx.engines import vimeo
25
         self.assertEqual(vimeo.response(response), [])
26
         self.assertEqual(vimeo.response(response), [])
26
 
27
 
27
         html = """
28
         html = """
28
-        <div id="browse_content" class="" data-search-id="696d5f8366914ec4ffec33cf7652de384976d4f4">
29
-            <ol class="js-browse_list clearfix browse browse_videos browse_videos_thumbnails kane"
29
+        <div id="browse_content" class="results_grid" data-search-id="696d5f8366914ec4ffec33cf7652de384976d4f4">
30
+            <ul class="js-browse_list clearfix browse browse_videos browse_videos_thumbnails kane"
30
                 data-stream="c2VhcmNoOjo6ZGVzYzp7InF1ZXJ5IjoidGVzdCJ9">
31
                 data-stream="c2VhcmNoOjo6ZGVzYzp7InF1ZXJ5IjoidGVzdCJ9">
31
-                <li id="clip_100785455" data-start-page="/search/page:1/sort:relevant/" data-position="1">
32
-                    <a href="/videoid" title="Futurama 3d (test shot)">
33
-                        <img src="http://image.url.webp"
34
-                            srcset="http://i.vimeocdn.com/video/482375085_590x332.webp 2x" alt=""
35
-                            class="thumbnail thumbnail_lg_wide">
36
-                        <div class="data">
37
-                            <p class="title">
38
-                                This is the title
39
-                            </p>
40
-                            <p class="meta">
41
-                                <time datetime="2014-07-15T04:16:27-04:00"
42
-                                    title="mardi 15 juillet 2014 04:16">Il y a 6 mois</time>
43
-                            </p>
44
-                        </div>
45
-                    </a>
32
+                <li data-position="7" data-result-id="clip_79600943">
33
+                    <div class="clip_thumbnail">
34
+                        <a href="/videoid" class="js-result_url">
35
+                            <div class="thumbnail_wrapper">
36
+                                <img src="http://image.url.webp" class="js-clip_thumbnail_image">
37
+                                <div class="overlay overlay_clip_meta">
38
+                                    <div class="meta_data_footer">
39
+                                        <span class="clip_upload_date">
40
+                                            <time datetime="2013-11-17T08:49:09-05:00"
41
+                                                title="dimanche 17 novembre 2013 08:49">Il y a 1 an</time>
42
+                                        </span>
43
+                                        <span class="clip_likes">
44
+                                            <img src="https://f.vimeocdn.com/images_v6/svg/heart-icon.svg">2 215
45
+                                        </span>
46
+                                        <span class="clip_comments">
47
+                                            <img src="https://f.vimeocdn.com/images_v6/svg/comment-icon.svg">75
48
+                                        </span>
49
+                                        <span class="overlay meta_data_footer clip_duration">01:12</span>
50
+                                    </div>
51
+                                </div>
52
+                            </div>
53
+                            <span class="title">This is the title</span>
54
+                        </a>
55
+                    </div>
56
+                    <div class="clip_thumbnail_attribution">
57
+                        <a href="/fedorshmidt">
58
+                            <img src="https://i.vimeocdn.com/portrait/6628061_100x100.jpg" class="avatar">
59
+                            <span class="display_name">Fedor Shmidt</span>
60
+                        </a>
61
+                        <span class="plays">2,1M lectures</span>
62
+                    </div>
46
                 </li>
63
                 </li>
47
-            </ol>
64
+            </ul>
48
         </div>
65
         </div>
49
         """
66
         """
50
         response = mock.Mock(text=html)
67
         response = mock.Mock(text=html)