Browse Source

[fix] remove obsolete youtube engine

Adam Tauber 9 years ago
parent
commit
6bcbd633a5
3 changed files with 0 additions and 298 deletions
  1. 0
    93
      searx/engines/youtube.py
  2. 0
    204
      searx/tests/engines/test_youtube.py
  3. 0
    1
      searx/tests/test_engines.py

+ 0
- 93
searx/engines/youtube.py View File

@@ -1,93 +0,0 @@
1
-# Youtube (Videos)
2
-#
3
-# @website     https://www.youtube.com/
4
-# @provide-api yes (http://gdata-samples-youtube-search-py.appspot.com/)
5
-#
6
-# @using-api   yes
7
-# @results     JSON
8
-# @stable      yes
9
-# @parse       url, title, content, publishedDate, thumbnail, embedded
10
-
11
-from json import loads
12
-from urllib import urlencode
13
-from dateutil import parser
14
-
15
-# engine dependent config
16
-categories = ['videos', 'music']
17
-paging = True
18
-language_support = True
19
-
20
-# search-url
21
-base_url = 'https://gdata.youtube.com/feeds/api/videos'
22
-search_url = base_url + '?alt=json&{query}&start-index={index}&max-results=5'
23
-
24
-embedded_url = '<iframe width="540" height="304" ' +\
25
-    'data-src="//www.youtube-nocookie.com/embed/{videoid}" ' +\
26
-    'frameborder="0" allowfullscreen></iframe>'
27
-
28
-
29
-# do search-request
30
-def request(query, params):
31
-    index = (params['pageno'] - 1) * 5 + 1
32
-
33
-    params['url'] = search_url.format(query=urlencode({'q': query}),
34
-                                      index=index)
35
-
36
-    # add language tag if specified
37
-    if params['language'] != 'all':
38
-        params['url'] += '&lr=' + params['language'].split('_')[0]
39
-
40
-    return params
41
-
42
-
43
-# get response from search-request
44
-def response(resp):
45
-    results = []
46
-
47
-    search_results = loads(resp.text)
48
-
49
-    # return empty array if there are no results
50
-    if 'feed' not in search_results:
51
-        return []
52
-
53
-    feed = search_results['feed']
54
-
55
-    # parse results
56
-    for result in feed['entry']:
57
-        url = [x['href'] for x in result['link'] if x['type'] == 'text/html']
58
-
59
-        if not url:
60
-            continue
61
-
62
-        # remove tracking
63
-        url = url[0].replace('feature=youtube_gdata', '')
64
-        if url.endswith('&'):
65
-            url = url[:-1]
66
-
67
-        videoid = url[32:]
68
-
69
-        title = result['title']['$t']
70
-        content = ''
71
-        thumbnail = ''
72
-
73
-        pubdate = result['published']['$t']
74
-        publishedDate = parser.parse(pubdate)
75
-
76
-        if 'media$thumbnail' in result['media$group']:
77
-            thumbnail = result['media$group']['media$thumbnail'][0]['url']
78
-
79
-        content = result['content']['$t']
80
-
81
-        embedded = embedded_url.format(videoid=videoid)
82
-
83
-        # append result
84
-        results.append({'url': url,
85
-                        'title': title,
86
-                        'content': content,
87
-                        'template': 'videos.html',
88
-                        'publishedDate': publishedDate,
89
-                        'embedded': embedded,
90
-                        'thumbnail': thumbnail})
91
-
92
-    # return results
93
-    return results

+ 0
- 204
searx/tests/engines/test_youtube.py View File

@@ -1,204 +0,0 @@
1
-from collections import defaultdict
2
-import mock
3
-from searx.engines import youtube
4
-from searx.testing import SearxTestCase
5
-
6
-
7
-class TestYoutubeEngine(SearxTestCase):
8
-
9
-    def test_request(self):
10
-        query = 'test_query'
11
-        dicto = defaultdict(dict)
12
-        dicto['pageno'] = 0
13
-        dicto['language'] = 'fr_FR'
14
-        params = youtube.request(query, dicto)
15
-        self.assertTrue('url' in params)
16
-        self.assertTrue(query in params['url'])
17
-        self.assertTrue('youtube.com' in params['url'])
18
-        self.assertTrue('fr' in params['url'])
19
-
20
-        dicto['language'] = 'all'
21
-        params = youtube.request(query, dicto)
22
-        self.assertFalse('fr' in params['url'])
23
-
24
-    def test_response(self):
25
-        self.assertRaises(AttributeError, youtube.response, None)
26
-        self.assertRaises(AttributeError, youtube.response, [])
27
-        self.assertRaises(AttributeError, youtube.response, '')
28
-        self.assertRaises(AttributeError, youtube.response, '[]')
29
-
30
-        response = mock.Mock(text='{}')
31
-        self.assertEqual(youtube.response(response), [])
32
-
33
-        response = mock.Mock(text='{"data": []}')
34
-        self.assertEqual(youtube.response(response), [])
35
-
36
-        json = """
37
-        {"feed":{"entry":[{
38
-            "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
39
-            "published":{"$t":"2015-01-23T21:25:00.000Z"},
40
-            "updated":{"$t":"2015-01-26T14:38:15.000Z"},
41
-            "title":{"$t":"Title",
42
-                "type":"text"},"content":{"$t":"Description","type":"text"},
43
-            "link":[{"rel":"alternate","type":"text/html",
44
-                "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata"},
45
-                {"rel":"http://gdata.youtube.com/schemas/2007#video.related",
46
-                "type":"application/atom+xml",
47
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
48
-                {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html",
49
-                "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"},
50
-                {"rel":"self","type":"application/atom+xml",
51
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
52
-            "author":[{"name":{"$t":"Cauet"},
53
-                "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
54
-            "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
55
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
56
-                "countHint":8} },
57
-            "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
58
-                "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
59
-            "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
60
-                "type":"application/x-shockwave-flash","medium":"video",
61
-                "isDefault":"true","expression":"full","duration":354,"yt$format":5},
62
-    {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
63
-                "type":"video/3gpp","medium":"video","expression":"full","duration":354,
64
-                "yt$format":1},
65
-    {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
66
-                "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
67
-            "media$description":{"$t":"Desc","type":"plain"},
68
-            "media$keywords":{},
69
-            "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
70
-            "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg",
71
-                    "height":360,"width":480,"time":"00:02:57"},
72
-                {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"},
73
-                {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"},
74
-                {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}],
75
-            "media$title":{"$t":"Title","type":"plain"},
76
-            "yt$duration":{"seconds":"354"} },
77
-            "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
78
-                "rel":"http://schemas.google.com/g/2005#overall"},
79
-            "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
80
-            ]
81
-        }
82
-        }
83
-        """
84
-        response = mock.Mock(text=json)
85
-        results = youtube.response(response)
86
-        self.assertEqual(type(results), list)
87
-        self.assertEqual(len(results), 1)
88
-        self.assertEqual(results[0]['title'], 'Title')
89
-        self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM')
90
-        self.assertEqual(results[0]['content'], 'Description')
91
-        self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg')
92
-        self.assertTrue('DIVZCPfAOeM' in results[0]['embedded'])
93
-
94
-        json = """
95
-        {"feed":{"entry":[{
96
-            "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
97
-            "published":{"$t":"2015-01-23T21:25:00.000Z"},
98
-            "updated":{"$t":"2015-01-26T14:38:15.000Z"},
99
-            "title":{"$t":"Title",
100
-                "type":"text"},"content":{"$t":"Description","type":"text"},
101
-            "link":[{"rel":"http://gdata.youtube.com/schemas/2007#video.related",
102
-                "type":"application/atom+xml",
103
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
104
-                {"rel":"self","type":"application/atom+xml",
105
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
106
-            "author":[{"name":{"$t":"Cauet"},
107
-                "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
108
-            "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
109
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
110
-                "countHint":8} },
111
-            "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
112
-                "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
113
-            "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
114
-                "type":"application/x-shockwave-flash","medium":"video",
115
-                "isDefault":"true","expression":"full","duration":354,"yt$format":5},
116
-    {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
117
-                "type":"video/3gpp","medium":"video","expression":"full","duration":354,
118
-                "yt$format":1},
119
-    {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
120
-                "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
121
-            "media$description":{"$t":"Desc","type":"plain"},
122
-            "media$keywords":{},
123
-            "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
124
-            "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg",
125
-                    "height":360,"width":480,"time":"00:02:57"},
126
-                {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"},
127
-                {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"},
128
-                {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}],
129
-            "media$title":{"$t":"Title","type":"plain"},
130
-            "yt$duration":{"seconds":"354"} },
131
-            "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
132
-                "rel":"http://schemas.google.com/g/2005#overall"},
133
-            "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
134
-            ]
135
-        }
136
-        }
137
-        """
138
-        response = mock.Mock(text=json)
139
-        results = youtube.response(response)
140
-        self.assertEqual(type(results), list)
141
-        self.assertEqual(len(results), 0)
142
-
143
-        json = """
144
-        {"feed":{"entry":[{
145
-            "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"},
146
-            "published":{"$t":"2015-01-23T21:25:00.000Z"},
147
-            "updated":{"$t":"2015-01-26T14:38:15.000Z"},
148
-            "title":{"$t":"Title",
149
-                "type":"text"},"content":{"$t":"Description","type":"text"},
150
-            "link":[{"rel":"alternate","type":"text/html",
151
-                "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM"},
152
-                {"rel":"http://gdata.youtube.com/schemas/2007#video.related",
153
-                "type":"application/atom+xml",
154
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"},
155
-                {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html",
156
-                "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"},
157
-                {"rel":"self","type":"application/atom+xml",
158
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}],
159
-            "author":[{"name":{"$t":"Cauet"},
160
-                "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }],
161
-            "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments",
162
-                "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments",
163
-                "countHint":8} },
164
-            "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy",
165
-                "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],
166
-            "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata",
167
-                "type":"application/x-shockwave-flash","medium":"video",
168
-                "isDefault":"true","expression":"full","duration":354,"yt$format":5},
169
-    {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
170
-                "type":"video/3gpp","medium":"video","expression":"full","duration":354,
171
-                "yt$format":1},
172
-    {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
173
-                "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}],
174
-            "media$description":{"$t":"Desc","type":"plain"},
175
-            "media$keywords":{},
176
-            "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}],
177
-            "media$title":{"$t":"Title","type":"plain"},
178
-            "yt$duration":{"seconds":"354"} },
179
-            "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533,
180
-                "rel":"http://schemas.google.com/g/2005#overall"},
181
-            "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} }
182
-            ]
183
-        }
184
-        }
185
-        """
186
-        response = mock.Mock(text=json)
187
-        results = youtube.response(response)
188
-        self.assertEqual(type(results), list)
189
-        self.assertEqual(len(results), 1)
190
-        self.assertEqual(results[0]['title'], 'Title')
191
-        self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM')
192
-        self.assertEqual(results[0]['content'], 'Description')
193
-        self.assertEqual(results[0]['thumbnail'], '')
194
-        self.assertTrue('DIVZCPfAOeM' in results[0]['embedded'])
195
-
196
-        json = """
197
-        {"toto":{"entry":[]
198
-        }
199
-        }
200
-        """
201
-        response = mock.Mock(text=json)
202
-        results = youtube.response(response)
203
-        self.assertEqual(type(results), list)
204
-        self.assertEqual(len(results), 0)

+ 0
- 1
searx/tests/test_engines.py View File

@@ -40,7 +40,6 @@ from searx.tests.engines.test_www1x import *  # noqa
40 40
 from searx.tests.engines.test_www500px import *  # noqa
41 41
 from searx.tests.engines.test_yacy import *  # noqa
42 42
 from searx.tests.engines.test_yahoo import *  # noqa
43
-from searx.tests.engines.test_youtube import *  # noqa
44 43
 from searx.tests.engines.test_youtube_api import *  # noqa
45 44
 from searx.tests.engines.test_youtube_noapi import *  # noqa
46 45
 from searx.tests.engines.test_yahoo_news import *  # noqa