Browse Source

Merge pull request #17 from pw3t/vimeo

Vimeo engine added
Adam Tauber 11 years ago
parent
commit
1ba2762b67
3 changed files with 46 additions and 1 deletions
  1. 7
    0
      engines.cfg_sample
  2. 38
    0
      searx/engines/vimeo.py
  3. 1
    1
      searx/webapp.py

+ 7
- 0
engines.cfg_sample View File

@@ -86,3 +86,10 @@ engine = dailymotion
86 86
 locale = en_US
87 87
 categories = videos
88 88
 
89
+[vimeo]
90
+engine = vimeo
91
+categories = videos
92
+results_xpath = //div[@id="browse_content"]/ol/li
93
+url_xpath=./a/@href
94
+title_xpath=./a/div[@class="data"]/p[@class="title"]/text()
95
+content_xpath=./a/img/@src

+ 38
- 0
searx/engines/vimeo.py View File

@@ -0,0 +1,38 @@
1
+from urllib import urlencode
2
+from HTMLParser import HTMLParser
3
+from xpath import extract_text
4
+from lxml import html
5
+
6
+base_url = 'http://vimeo.com'
7
+search_url = base_url + '/search?{query}'
8
+
9
+# the cookie set by vime contains all the following values, but only __utma seems to be requiered 
10
+Cookie = {
11
+    #'vuid':'918282893.1027205400'
12
+    # 'ab_bs':'%7B%223%22%3A279%7D'
13
+     '__utma':'00000000.000#0000000.0000000000.0000000000.0000000000.0'
14
+    # '__utmb':'18302654.1.10.1388942090'
15
+    #, '__utmc':'18302654'
16
+    #, '__utmz':'18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)'
17
+    #, '__utml':'search'
18
+}
19
+
20
+def request(query, params):
21
+    params['url'] = search_url.format(query=urlencode({'q' :query}))
22
+    print params['url']
23
+    params['cookies'] = Cookie
24
+    return params
25
+
26
+def response(resp):
27
+    results = []
28
+    dom = html.fromstring(resp.text)
29
+    
30
+    p = HTMLParser()
31
+
32
+    for result in dom.xpath(results_xpath):
33
+        url = base_url + result.xpath(url_xpath)[0]
34
+        title = p.unescape(extract_text(result.xpath(title_xpath)))
35
+        content = '<a href="{0}">  <img src="{2}"/> </a>'.format(url, title, extract_text(result.xpath(content_xpath)[0]))
36
+        results.append({'url': url, 'title': title, 'content': content})
37
+
38
+    return results

+ 1
- 1
searx/webapp.py View File

@@ -107,7 +107,7 @@ def index():
107 107
         if len(result['url']) > 74:
108 108
             result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]
109 109
         else:
110
-             result['pretty_url'] = result['url']
110
+            result['pretty_url'] = result['url']
111 111
 
112 112
     if request_data.get('format') == 'json':
113 113
         return Response(json.dumps({'query': query, 'results': results}), mimetype='application/json')