.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

logging logger .Logger
 
EngineTraits traits
 
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 202 of file dailymotion.py.

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

◆ request()

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

Definition at line 103 of file dailymotion.py.

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

◆ response()

searx.engines.dailymotion.response ( resp)

Definition at line 149 of file dailymotion.py.

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

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 34 of file dailymotion.py.

◆ categories

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

Definition at line 44 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 66 of file dailymotion.py.

◆ iframe_src

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

Definition at line 99 of file dailymotion.py.

◆ logger

logging searx.engines.dailymotion.logger .Logger

Definition at line 29 of file dailymotion.py.

◆ number_of_results

int searx.engines.dailymotion.number_of_results = 10

Definition at line 46 of file dailymotion.py.

◆ paging

bool searx.engines.dailymotion.paging = True

Definition at line 45 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 76 of file dailymotion.py.

◆ safesearch

bool searx.engines.dailymotion.safesearch = True

Definition at line 56 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 57 of file dailymotion.py.

◆ search_url

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

Definition at line 91 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 49 of file dailymotion.py.

◆ time_range_support

bool searx.engines.dailymotion.time_range_support = True

Definition at line 48 of file dailymotion.py.

◆ traits

EngineTraits searx.engines.dailymotion.traits

Definition at line 31 of file dailymotion.py.