소스 검색

[fix] flickr engine

Alexandre Flament 10 년 전
부모
커밋
7afd02c94e
2개의 변경된 파일74개의 추가작업 그리고 193개의 파일을 삭제
  1. 6
    11
      searx/engines/flickr_noapi.py
  2. 68
    182
      searx/tests/engines/test_flickr_noapi.py

+ 6
- 11
searx/engines/flickr_noapi.py 파일 보기

25
 url = 'https://www.flickr.com/'
25
 url = 'https://www.flickr.com/'
26
 search_url = url + 'search?{query}&page={page}'
26
 search_url = url + 'search?{query}&page={page}'
27
 photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'
27
 photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'
28
-regex = re.compile(r"\"search-photos-models\",\"photos\":(.*}),\"totalItems\":", re.DOTALL)
28
+regex = re.compile(r"\"search-photos-lite-models\",\"photos\":(.*}),\"totalItems\":", re.DOTALL)
29
 image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'n', 'm', 't', 'q', 's')
29
 image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'n', 'm', 't', 'q', 's')
30
 
30
 
31
 paging = True
31
 paging = True
38
 def request(query, params):
38
 def request(query, params):
39
     params['url'] = search_url.format(query=urlencode({'text': query}),
39
     params['url'] = search_url.format(query=urlencode({'text': query}),
40
                                       page=params['pageno'])
40
                                       page=params['pageno'])
41
+
41
     return params
42
     return params
42
 
43
 
43
 
44
 
75
             logger.debug('cannot find valid image size: {0}'.format(repr(photo)))
76
             logger.debug('cannot find valid image size: {0}'.format(repr(photo)))
76
             continue
77
             continue
77
 
78
 
78
-        if 'id' not in photo['owner']:
79
+        if 'ownerNsid' not in photo:
79
             continue
80
             continue
80
 
81
 
81
-# For a bigger thumbnail, keep only the url_z, not the url_n
82
+        # For a bigger thumbnail, keep only the url_z, not the url_n
82
         if 'n' in photo['sizes']:
83
         if 'n' in photo['sizes']:
83
             thumbnail_src = photo['sizes']['n']['url']
84
             thumbnail_src = photo['sizes']['n']['url']
84
         elif 'z' in photo['sizes']:
85
         elif 'z' in photo['sizes']:
86
         else:
87
         else:
87
             thumbnail_src = img_src
88
             thumbnail_src = img_src
88
 
89
 
89
-        url = build_flickr_url(photo['owner']['id'], photo['id'])
90
+        url = build_flickr_url(photo['ownerNsid'], photo['id'])
90
 
91
 
91
         title = photo.get('title', '')
92
         title = photo.get('title', '')
92
 
93
 
93
         content = '<span class="photo-author">' +\
94
         content = '<span class="photo-author">' +\
94
-                  photo['owner']['username'] +\
95
+                  photo['username'] +\
95
                   '</span><br />'
96
                   '</span><br />'
96
 
97
 
97
-        if 'description' in photo:
98
-            content = content +\
99
-                '<span class="description">' +\
100
-                photo['description'] +\
101
-                '</span>'
102
-
103
         # append result
98
         # append result
104
         results.append({'url': url,
99
         results.append({'url': url,
105
                         'title': title,
100
                         'title': title,

+ 68
- 182
searx/tests/engines/test_flickr_noapi.py 파일 보기

26
         self.assertRaises(AttributeError, flickr_noapi.response, '')
26
         self.assertRaises(AttributeError, flickr_noapi.response, '')
27
         self.assertRaises(AttributeError, flickr_noapi.response, '[]')
27
         self.assertRaises(AttributeError, flickr_noapi.response, '[]')
28
 
28
 
29
-        response = mock.Mock(text='"search-photos-models","photos":{},"totalItems":')
29
+        response = mock.Mock(text='"search-photos-lite-models","photos":{},"totalItems":')
30
         self.assertEqual(flickr_noapi.response(response), [])
30
         self.assertEqual(flickr_noapi.response(response), [])
31
 
31
 
32
-        response = mock.Mock(text='search-photos-models","photos":{"data": []},"totalItems":')
32
+        response = mock.Mock(text='search-photos-lite-models","photos":{"data": []},"totalItems":')
33
         self.assertEqual(flickr_noapi.response(response), [])
33
         self.assertEqual(flickr_noapi.response(response), [])
34
 
34
 
35
+        # everthing is ok test
35
         json = """
36
         json = """
36
-        "search-photos-models","photos":
37
+        "search-photos-lite-models","photos":
37
         {
38
         {
38
           "_data": [
39
           "_data": [
39
             {
40
             {
40
-              "_flickrModelRegistry": "photo-models",
41
+              "_flickrModelRegistry": "photo-lite-models",
41
               "title": "This is the title",
42
               "title": "This is the title",
43
+              "username": "Owner",
44
+              "pathAlias": "klink692",
45
+              "realname": "Owner",
46
+              "license": 0,
47
+              "ownerNsid": "59729010@N00",
48
+              "canComment": false,
49
+              "commentCount": 14,
50
+              "faveCount": 21,
51
+              "id": "14001294434",
42
               "sizes": {
52
               "sizes": {
43
                 "c": {
53
                 "c": {
44
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_c.jpg",
54
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_c.jpg",
117
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg",
127
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg",
118
                   "key": "z"
128
                   "key": "z"
119
                 }
129
                 }
120
-              },
121
-              "canComment": false,
122
-              "rotation": 0,
123
-              "owner": {
124
-                "_flickrModelRegistry": "person-models",
125
-                "pathAlias": "klink692",
126
-                "username": "Owner",
127
-                "buddyicon": {
128
-                  "retina": null,
129
-                  "large": null,
130
-                  "medium": null,
131
-                  "small": null,
132
-                  "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00"
133
-                },
134
-                "isPro": true,
135
-                "id": "59729010@N00"
136
-              },
137
-              "engagement": {
138
-                "_flickrModelRegistry": "photo-engagement-models",
139
-                "ownerNsid": "59729010@N00",
140
-                "faveCount": 21,
141
-                "commentCount": 14,
142
-                "viewCount": 10160,
143
-                "id": "14001294434"
144
-              },
145
-              "description": "Description",
146
-              "isHD": false,
147
-              "secret": "410f653777",
148
-              "canAddMeta": false,
149
-              "license": 0,
150
-              "oWidth": 1803,
151
-              "oHeight": 2669,
152
-              "safetyLevel": 0,
153
-              "id": "14001294434"
130
+              }
154
             }
131
             }
155
           ],
132
           ],
156
           "fetchedStart": true,
133
           "fetchedStart": true,
168
         self.assertIn('k.jpg', results[0]['img_src'])
145
         self.assertIn('k.jpg', results[0]['img_src'])
169
         self.assertIn('n.jpg', results[0]['thumbnail_src'])
146
         self.assertIn('n.jpg', results[0]['thumbnail_src'])
170
         self.assertIn('Owner', results[0]['content'])
147
         self.assertIn('Owner', results[0]['content'])
171
-        self.assertIn('Description', results[0]['content'])
172
 
148
 
149
+        # no n size, only the z size
173
         json = """
150
         json = """
174
-        "search-photos-models","photos":
151
+        "search-photos-lite-models","photos":
175
         {
152
         {
176
           "_data": [
153
           "_data": [
177
             {
154
             {
178
-              "_flickrModelRegistry": "photo-models",
155
+              "_flickrModelRegistry": "photo-lite-models",
179
               "title": "This is the title",
156
               "title": "This is the title",
157
+              "username": "Owner",
158
+              "pathAlias": "klink692",
159
+              "realname": "Owner",
160
+              "license": 0,
161
+              "ownerNsid": "59729010@N00",
162
+              "canComment": false,
163
+              "commentCount": 14,
164
+              "faveCount": 21,
165
+              "id": "14001294434",
180
               "sizes": {
166
               "sizes": {
181
                 "z": {
167
                 "z": {
182
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg",
168
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg",
185
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg",
171
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg",
186
                   "key": "z"
172
                   "key": "z"
187
                 }
173
                 }
188
-              },
189
-              "canComment": false,
190
-              "rotation": 0,
191
-              "owner": {
192
-                "_flickrModelRegistry": "person-models",
193
-                "pathAlias": "klink692",
194
-                "username": "Owner",
195
-                "buddyicon": {
196
-                  "retina": null,
197
-                  "large": null,
198
-                  "medium": null,
199
-                  "small": null,
200
-                  "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00"
201
-                },
202
-                "isPro": true,
203
-                "id": "59729010@N00"
204
-              },
205
-              "engagement": {
206
-                "_flickrModelRegistry": "photo-engagement-models",
207
-                "ownerNsid": "59729010@N00",
208
-                "faveCount": 21,
209
-                "commentCount": 14,
210
-                "viewCount": 10160,
211
-                "id": "14001294434"
212
-              },
213
-              "description": "Description",
214
-              "isHD": false,
215
-              "secret": "410f653777",
216
-              "canAddMeta": false,
217
-              "license": 0,
218
-              "oWidth": 1803,
219
-              "oHeight": 2669,
220
-              "safetyLevel": 0,
221
-              "id": "14001294434"
174
+              }
222
             }
175
             }
223
           ],
176
           ],
224
           "fetchedStart": true,
177
           "fetchedStart": true,
235
         self.assertIn('z.jpg', results[0]['img_src'])
188
         self.assertIn('z.jpg', results[0]['img_src'])
236
         self.assertIn('z.jpg', results[0]['thumbnail_src'])
189
         self.assertIn('z.jpg', results[0]['thumbnail_src'])
237
         self.assertIn('Owner', results[0]['content'])
190
         self.assertIn('Owner', results[0]['content'])
238
-        self.assertIn('Description', results[0]['content'])
239
 
191
 
192
+        # no z or n size
240
         json = """
193
         json = """
241
-        "search-photos-models","photos":
194
+        "search-photos-lite-models","photos":
242
         {
195
         {
243
           "_data": [
196
           "_data": [
244
             {
197
             {
245
-              "_flickrModelRegistry": "photo-models",
198
+              "_flickrModelRegistry": "photo-lite-models",
246
               "title": "This is the title",
199
               "title": "This is the title",
200
+              "username": "Owner",
201
+              "pathAlias": "klink692",
202
+              "realname": "Owner",
203
+              "license": 0,
204
+              "ownerNsid": "59729010@N00",
205
+              "canComment": false,
206
+              "commentCount": 14,
207
+              "faveCount": 21,
208
+              "id": "14001294434",
247
               "sizes": {
209
               "sizes": {
248
                 "o": {
210
                 "o": {
249
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg",
211
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg",
252
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg",
214
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg",
253
                   "key": "o"
215
                   "key": "o"
254
                 }
216
                 }
255
-              },
256
-              "canComment": false,
257
-              "rotation": 0,
258
-              "owner": {
259
-                "_flickrModelRegistry": "person-models",
260
-                "pathAlias": "klink692",
261
-                "username": "Owner",
262
-                "buddyicon": {
263
-                  "retina": null,
264
-                  "large": null,
265
-                  "medium": null,
266
-                  "small": null,
267
-                  "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00"
268
-                },
269
-                "isPro": true,
270
-                "id": "59729010@N00"
271
-              },
272
-              "engagement": {
273
-                "_flickrModelRegistry": "photo-engagement-models",
274
-                "ownerNsid": "59729010@N00",
275
-                "faveCount": 21,
276
-                "commentCount": 14,
277
-                "viewCount": 10160,
278
-                "id": "14001294434"
279
-              },
280
-              "isHD": false,
281
-              "secret": "410f653777",
282
-              "canAddMeta": false,
283
-              "license": 0,
284
-              "oWidth": 1803,
285
-              "oHeight": 2669,
286
-              "safetyLevel": 0,
287
-              "id": "14001294434"
217
+              }
288
             }
218
             }
289
           ],
219
           ],
290
           "fetchedStart": true,
220
           "fetchedStart": true,
302
         self.assertIn('o.jpg', results[0]['thumbnail_src'])
232
         self.assertIn('o.jpg', results[0]['thumbnail_src'])
303
         self.assertIn('Owner', results[0]['content'])
233
         self.assertIn('Owner', results[0]['content'])
304
 
234
 
235
+        # no image test
305
         json = """
236
         json = """
306
-        "search-photos-models","photos":
237
+        "search-photos-lite-models","photos":
307
         {
238
         {
308
           "_data": [
239
           "_data": [
309
             {
240
             {
310
-              "_flickrModelRegistry": "photo-models",
241
+              "_flickrModelRegistry": "photo-lite-models",
311
               "title": "This is the title",
242
               "title": "This is the title",
312
-              "sizes": {
313
-              },
314
-              "canComment": false,
315
-              "rotation": 0,
316
-              "owner": {
317
-                "_flickrModelRegistry": "person-models",
318
-                "pathAlias": "klink692",
319
-                "username": "Owner",
320
-                "buddyicon": {
321
-                  "retina": null,
322
-                  "large": null,
323
-                  "medium": null,
324
-                  "small": null,
325
-                  "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00"
326
-                },
327
-                "isPro": true,
328
-                "id": "59729010@N00"
329
-              },
330
-              "engagement": {
331
-                "_flickrModelRegistry": "photo-engagement-models",
332
-                "ownerNsid": "59729010@N00",
333
-                "faveCount": 21,
334
-                "commentCount": 14,
335
-                "viewCount": 10160,
336
-                "id": "14001294434"
337
-              },
338
-              "description": "Description",
339
-              "isHD": false,
340
-              "secret": "410f653777",
341
-              "canAddMeta": false,
243
+              "username": "Owner",
244
+              "pathAlias": "klink692",
245
+              "realname": "Owner",
342
               "license": 0,
246
               "license": 0,
343
-              "oWidth": 1803,
344
-              "oHeight": 2669,
345
-              "safetyLevel": 0,
346
-              "id": "14001294434"
247
+              "ownerNsid": "59729010@N00",
248
+              "canComment": false,
249
+              "commentCount": 14,
250
+              "faveCount": 21,
251
+              "id": "14001294434",
252
+              "sizes": {
253
+              }
347
             }
254
             }
348
           ],
255
           ],
349
           "fetchedStart": true,
256
           "fetchedStart": true,
356
         self.assertEqual(type(results), list)
263
         self.assertEqual(type(results), list)
357
         self.assertEqual(len(results), 0)
264
         self.assertEqual(len(results), 0)
358
 
265
 
266
+        # null test
359
         json = """
267
         json = """
360
         "search-photos-models","photos":
268
         "search-photos-models","photos":
361
         {
269
         {
370
         self.assertEqual(type(results), list)
278
         self.assertEqual(type(results), list)
371
         self.assertEqual(len(results), 0)
279
         self.assertEqual(len(results), 0)
372
 
280
 
281
+        # no ownerNsid test
373
         json = """
282
         json = """
374
-        "search-photos-models","photos":
283
+        "search-photos-lite-models","photos":
375
         {
284
         {
376
           "_data": [
285
           "_data": [
377
             {
286
             {
378
-              "_flickrModelRegistry": "photo-models",
287
+              "_flickrModelRegistry": "photo-lite-models",
379
               "title": "This is the title",
288
               "title": "This is the title",
289
+              "username": "Owner",
290
+              "pathAlias": "klink692",
291
+              "realname": "Owner",
292
+              "license": 0,
293
+              "canComment": false,
294
+              "commentCount": 14,
295
+              "faveCount": 21,
296
+              "id": "14001294434",
380
               "sizes": {
297
               "sizes": {
381
                 "o": {
298
                 "o": {
382
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg",
299
                   "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg",
385
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg",
302
                   "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg",
386
                   "key": "o"
303
                   "key": "o"
387
                 }
304
                 }
388
-              },
389
-              "canComment": false,
390
-              "rotation": 0,
391
-              "owner": {
392
-                "_flickrModelRegistry": "person-models",
393
-                "pathAlias": "klink692",
394
-                "username": "Owner",
395
-                "buddyicon": {
396
-                  "retina": null,
397
-                  "large": null,
398
-                  "medium": null,
399
-                  "small": null,
400
-                  "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00"
401
-                },
402
-                "isPro": true
403
-              },
404
-              "engagement": {
405
-                "_flickrModelRegistry": "photo-engagement-models",
406
-                "ownerNsid": "59729010@N00",
407
-                "faveCount": 21,
408
-                "commentCount": 14,
409
-                "viewCount": 10160,
410
-                "id": "14001294434"
411
-              },
412
-              "description": "Description",
413
-              "isHD": false,
414
-              "secret": "410f653777",
415
-              "canAddMeta": false,
416
-              "license": 0,
417
-              "oWidth": 1803,
418
-              "oHeight": 2669,
419
-              "safetyLevel": 0,
420
-              "id": "14001294434"
305
+              }
421
             }
306
             }
422
           ],
307
           ],
423
           "fetchedStart": true,
308
           "fetchedStart": true,
430
         self.assertEqual(type(results), list)
315
         self.assertEqual(type(results), list)
431
         self.assertEqual(len(results), 0)
316
         self.assertEqual(len(results), 0)
432
 
317
 
318
+        # garbage test
433
         json = """
319
         json = """
434
         {"toto":[
320
         {"toto":[
435
             {"id":200,"name":"Artist Name",
321
             {"id":200,"name":"Artist Name",