.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.flickr_noapi Namespace Reference

Functions

 build_flickr_url (user_id, photo_id)
 _get_time_range_url (time_range)
 request (query, params)
 response (resp)

Variables

dict about
list categories = ['images']
bool paging = True
bool time_range_support = True
bool safesearch = False
dict time_range_dict
tuple image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'm', 'n', 't', 'q', 's')
str search_url = 'https://www.flickr.com/search?{query}&page={page}'
str time_range_url = '&min_upload_date={start}&max_upload_date={end}'
str photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'
 modelexport_re = re.compile(r"^\s*modelExport:\s*({.*}),$", re.M)

Detailed Description

Flickr (Images)

Function Documentation

◆ _get_time_range_url()

searx.engines.flickr_noapi._get_time_range_url ( time_range)
protected

Definition at line 46 of file flickr_noapi.py.

46def _get_time_range_url(time_range):
47 if time_range in time_range_dict:
48 return time_range_url.format(start=time(), end=str(int(time()) - time_range_dict[time_range]))
49 return ''
50
51

Referenced by request().

Here is the caller graph for this function:

◆ build_flickr_url()

searx.engines.flickr_noapi.build_flickr_url ( user_id,
photo_id )

Definition at line 42 of file flickr_noapi.py.

42def build_flickr_url(user_id, photo_id):
43 return photo_url.format(userid=user_id, photoid=photo_id)
44
45

Referenced by response().

Here is the caller graph for this function:

◆ request()

searx.engines.flickr_noapi.request ( query,
params )

Definition at line 52 of file flickr_noapi.py.

52def request(query, params):
53 params['url'] = search_url.format(query=urlencode({'text': query}), page=params['pageno']) + _get_time_range_url(
54 params['time_range']
55 )
56 return params
57
58

References _get_time_range_url().

Here is the call graph for this function:

◆ response()

searx.engines.flickr_noapi.response ( resp)

Definition at line 59 of file flickr_noapi.py.

59def response(resp): # pylint: disable=too-many-branches
60 results = []
61
62 matches = modelexport_re.search(resp.text)
63 if matches is None:
64 return results
65
66 match = matches.group(1)
67 model_export = json.loads(match)
68
69 if 'legend' not in model_export:
70 return results
71 legend = model_export['legend']
72
73 # handle empty page
74 if not legend or not legend[0]:
75 return results
76
77 for x, index in enumerate(legend):
78 if len(index) != 8:
79 logger.debug("skip legend enty %s : %s", x, index)
80 continue
81
82 photo = model_export['main'][index[0]][int(index[1])][index[2]][index[3]][index[4]][index[5]][int(index[6])][
83 index[7]
84 ]
85 author = ecma_unescape(photo.get('realname', ''))
86 source = ecma_unescape(photo.get('username', ''))
87 if source:
88 source += ' @ Flickr'
89 title = ecma_unescape(photo.get('title', ''))
90 content = html_to_text(ecma_unescape(photo.get('description', '')))
91 img_src = None
92
93 # From the biggest to the lowest format
94 size_data = None
95 for image_size in image_sizes:
96 if image_size in photo['sizes']['data']:
97 size_data = photo['sizes']['data'][image_size]['data']
98 break
99
100 if not size_data:
101 logger.debug('cannot find valid image size: {0}'.format(repr(photo['sizes']['data'])))
102 continue
103
104 img_src = size_data['url']
105 resolution = f"{size_data['width']} x {size_data['height']}"
106
107 # For a bigger thumbnail, keep only the url_z, not the url_n
108 if 'n' in photo['sizes']['data']:
109 thumbnail_src = photo['sizes']['data']['n']['data']['url']
110 elif 'z' in photo['sizes']['data']:
111 thumbnail_src = photo['sizes']['data']['z']['data']['url']
112 else:
113 thumbnail_src = img_src
114
115 if 'ownerNsid' not in photo:
116 # should not happen, disowned photo? Show it anyway
117 url = img_src
118 else:
119 url = build_flickr_url(photo['ownerNsid'], photo['id'])
120
121 result = {
122 'url': url,
123 'img_src': img_src,
124 'thumbnail_src': thumbnail_src,
125 'source': source,
126 'resolution': resolution,
127 'template': 'images.html',
128 }
129 result['author'] = author.encode(errors='ignore').decode()
130 result['source'] = source.encode(errors='ignore').decode()
131 result['title'] = title.encode(errors='ignore').decode()
132 result['content'] = content.encode(errors='ignore').decode()
133 results.append(result)
134
135 return results

References build_flickr_url().

Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.flickr_noapi.about
Initial value:
1= {
2 "website": 'https://www.flickr.com',
3 "wikidata_id": 'Q103204',
4 "official_api_documentation": 'https://secure.flickr.com/services/api/flickr.photos.search.html',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 13 of file flickr_noapi.py.

◆ categories

list searx.engines.flickr_noapi.categories = ['images']

Definition at line 23 of file flickr_noapi.py.

◆ image_sizes

tuple searx.engines.flickr_noapi.image_sizes = ('o', 'k', 'h', 'b', 'c', 'z', 'm', 'n', 't', 'q', 's')

Definition at line 34 of file flickr_noapi.py.

◆ modelexport_re

searx.engines.flickr_noapi.modelexport_re = re.compile(r"^\s*modelExport:\s*({.*}),$", re.M)

Definition at line 39 of file flickr_noapi.py.

◆ paging

bool searx.engines.flickr_noapi.paging = True

Definition at line 24 of file flickr_noapi.py.

◆ photo_url

str searx.engines.flickr_noapi.photo_url = 'https://www.flickr.com/photos/{userid}/{photoid}'

Definition at line 38 of file flickr_noapi.py.

◆ safesearch

bool searx.engines.flickr_noapi.safesearch = False

Definition at line 26 of file flickr_noapi.py.

◆ search_url

str searx.engines.flickr_noapi.search_url = 'https://www.flickr.com/search?{query}&page={page}'

Definition at line 36 of file flickr_noapi.py.

◆ time_range_dict

dict searx.engines.flickr_noapi.time_range_dict
Initial value:
1= {
2 'day': 60 * 60 * 24,
3 'week': 60 * 60 * 24 * 7,
4 'month': 60 * 60 * 24 * 7 * 4,
5 'year': 60 * 60 * 24 * 7 * 52,
6}

Definition at line 28 of file flickr_noapi.py.

◆ time_range_support

bool searx.engines.flickr_noapi.time_range_support = True

Definition at line 25 of file flickr_noapi.py.

◆ time_range_url

str searx.engines.flickr_noapi.time_range_url = '&min_upload_date={start}&max_upload_date={end}'

Definition at line 37 of file flickr_noapi.py.