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

Functions

 request (query, params)
 response (resp)
 fetch_traits (EngineTraits engine_traits)

Variables

dict about
list categories = ['videos']
bool paging = True
int number_of_results = 10
bool time_range_support = True
dict time_delta_dict
bool safesearch = True
dict safesearch_params
dict family_filter_map
list result_fields
str search_url = 'https://api.dailymotion.com/videos?'
str iframe_src = "https://www.dailymotion.com/embed/video/{video_id}"

Detailed Description

Dailymotion (Videos)
~~~~~~~~~~~~~~~~~~~~

.. _REST GET: https://developers.dailymotion.com/tools/
.. _Global API Parameters: https://developers.dailymotion.com/api/#global-parameters
.. _Video filters API: https://developers.dailymotion.com/api/#video-filters
.. _Fields selection: https://developers.dailymotion.com/api/#fields-selection

Function Documentation

◆ fetch_traits()

searx.engines.dailymotion.fetch_traits ( EngineTraits engine_traits)
Fetch locales & languages from dailymotion.

Locales fetched from `api/locales <https://api.dailymotion.com/locales>`_.
There are duplications in the locale codes returned from Dailymotion which
can be ignored::

  en_EN --> en_GB, en_US
  ar_AA --> ar_EG, ar_AE, ar_SA

The language list `api/languages <https://api.dailymotion.com/languages>`_
contains over 7000 *languages* codes (see PR1071_).  We use only those
language codes that are used in the locales.

.. _PR1071: https://github.com/searxng/searxng/pull/1071

Definition at line 193 of file dailymotion.py.

193def fetch_traits(engine_traits: EngineTraits):
194 """Fetch locales & languages from dailymotion.
195
196 Locales fetched from `api/locales <https://api.dailymotion.com/locales>`_.
197 There are duplications in the locale codes returned from Dailymotion which
198 can be ignored::
199
200 en_EN --> en_GB, en_US
201 ar_AA --> ar_EG, ar_AE, ar_SA
202
203 The language list `api/languages <https://api.dailymotion.com/languages>`_
204 contains over 7000 *languages* codes (see PR1071_). We use only those
205 language codes that are used in the locales.
206
207 .. _PR1071: https://github.com/searxng/searxng/pull/1071
208
209 """
210
211 resp = get('https://api.dailymotion.com/locales')
212 if not resp.ok: # type: ignore
213 print("ERROR: response from dailymotion/locales is not OK.")
214
215 for item in resp.json()['list']: # type: ignore
216 eng_tag = item['locale']
217 if eng_tag in ('en_EN', 'ar_AA'):
218 continue
219 try:
220 sxng_tag = region_tag(babel.Locale.parse(eng_tag))
221 except babel.UnknownLocaleError:
222 print("ERROR: item unknown --> %s" % item)
223 continue
224
225 conflict = engine_traits.regions.get(sxng_tag)
226 if conflict:
227 if conflict != eng_tag:
228 print("CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
229 continue
230 engine_traits.regions[sxng_tag] = eng_tag
231
232 locale_lang_list = [x.split('_')[0] for x in engine_traits.regions.values()]
233
234 resp = get('https://api.dailymotion.com/languages')
235 if not resp.ok: # type: ignore
236 print("ERROR: response from dailymotion/languages is not OK.")
237
238 for item in resp.json()['list']: # type: ignore
239 eng_tag = item['code']
240 if eng_tag in locale_lang_list:
241 sxng_tag = language_tag(babel.Locale.parse(eng_tag))
242 engine_traits.languages[sxng_tag] = eng_tag

◆ request()

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

Definition at line 94 of file dailymotion.py.

94def request(query, params):
95
96 if not query:
97 return False
98
99 eng_region: str = traits.get_region(params['searxng_locale'], 'en_US') # type: ignore
100 eng_lang = traits.get_language(params['searxng_locale'], 'en')
101
102 args = {
103 'search': query,
104 'family_filter': family_filter_map.get(params['safesearch'], 'false'),
105 'thumbnail_ratio': 'original', # original|widescreen|square
106 # https://developers.dailymotion.com/api/#video-filters
107 'languages': eng_lang,
108 'page': params['pageno'],
109 'password_protected': 'false',
110 'private': 'false',
111 'sort': 'relevance',
112 'limit': number_of_results,
113 'fields': ','.join(result_fields),
114 }
115
116 args.update(safesearch_params.get(params['safesearch'], {}))
117
118 # Don't add localization and country arguments if the user does select a
119 # language (:de, :en, ..)
120
121 if len(params['searxng_locale'].split('-')) > 1:
122 # https://developers.dailymotion.com/api/#global-parameters
123 args['localization'] = eng_region
124 args['country'] = eng_region.split('_')[1]
125 # Insufficient rights for the `ams_country' parameter of route `GET /videos'
126 # 'ams_country': eng_region.split('_')[1],
127
128 time_delta = time_delta_dict.get(params["time_range"])
129 if time_delta:
130 created_after = datetime.now() - time_delta
131 args['created_after'] = datetime.timestamp(created_after)
132
133 query_str = urlencode(args)
134 params['url'] = search_url + query_str
135
136 return params
137
138
139# get response from search-request

◆ response()

searx.engines.dailymotion.response ( resp)

Definition at line 140 of file dailymotion.py.

140def response(resp):
141 results = []
142
143 search_res = resp.json()
144
145 # check for an API error
146 if 'error' in search_res:
147 raise SearxEngineAPIException(search_res['error'].get('message'))
148
149 raise_for_httperror(resp)
150
151 # parse results
152 for res in search_res.get('list', []):
153
154 title = res['title']
155 url = res['url']
156
157 content = html_to_text(res['description'])
158 if len(content) > 300:
159 content = content[:300] + '...'
160
161 publishedDate = datetime.fromtimestamp(res['created_time'], None)
162
163 length = time.gmtime(res.get('duration'))
164 if length.tm_hour:
165 length = time.strftime("%H:%M:%S", length)
166 else:
167 length = time.strftime("%M:%S", length)
168
169 thumbnail = res['thumbnail_360_url']
170 thumbnail = thumbnail.replace("http://", "https://")
171
172 item = {
173 'template': 'videos.html',
174 'url': url,
175 'title': title,
176 'content': content,
177 'publishedDate': publishedDate,
178 'length': length,
179 'thumbnail': thumbnail,
180 }
181
182 # HINT: no mater what the value is, without API token videos can't shown
183 # embedded
184 if res['allow_embed']:
185 item['iframe_src'] = iframe_src.format(video_id=res['id'])
186
187 results.append(item)
188
189 # return results
190 return results
191
192

Variable Documentation

◆ about

dict searx.engines.dailymotion.about
Initial value:
1= {
2 "website": 'https://www.dailymotion.com',
3 "wikidata_id": 'Q769222',
4 "official_api_documentation": 'https://www.dailymotion.com/developer',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 25 of file dailymotion.py.

◆ categories

list searx.engines.dailymotion.categories = ['videos']

Definition at line 35 of file dailymotion.py.

◆ family_filter_map

dict searx.engines.dailymotion.family_filter_map
Initial value:
1= {
2 2: 'true',
3 1: 'true',
4 0: 'false',
5}

Definition at line 57 of file dailymotion.py.

◆ iframe_src

str searx.engines.dailymotion.iframe_src = "https://www.dailymotion.com/embed/video/{video_id}"

Definition at line 90 of file dailymotion.py.

◆ number_of_results

int searx.engines.dailymotion.number_of_results = 10

Definition at line 37 of file dailymotion.py.

◆ paging

bool searx.engines.dailymotion.paging = True

Definition at line 36 of file dailymotion.py.

◆ result_fields

list searx.engines.dailymotion.result_fields
Initial value:
1= [
2 'allow_embed',
3 'description',
4 'title',
5 'created_time',
6 'duration',
7 'url',
8 'thumbnail_360_url',
9 'id',
10]

Definition at line 67 of file dailymotion.py.

◆ safesearch

bool searx.engines.dailymotion.safesearch = True

Definition at line 47 of file dailymotion.py.

◆ safesearch_params

dict searx.engines.dailymotion.safesearch_params
Initial value:
1= {
2 2: {'is_created_for_kids': 'true'},
3 1: {'is_created_for_kids': 'true'},
4 0: {},
5}

Definition at line 48 of file dailymotion.py.

◆ search_url

str searx.engines.dailymotion.search_url = 'https://api.dailymotion.com/videos?'

Definition at line 82 of file dailymotion.py.

◆ time_delta_dict

dict searx.engines.dailymotion.time_delta_dict
Initial value:
1= {
2 "day": timedelta(days=1),
3 "week": timedelta(days=7),
4 "month": timedelta(days=31),
5 "year": timedelta(days=365),
6}

Definition at line 40 of file dailymotion.py.

◆ time_range_support

bool searx.engines.dailymotion.time_range_support = True

Definition at line 39 of file dailymotion.py.