From 42b58eb4489e0493dc97a4a35b49921539c36d90 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 25 Apr 2024 18:47:39 +0200 Subject: [PATCH] [feat] media.ccc.de: implement module with pagination and iframe --- searx/engines/ccc_media.py | 54 ++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 29 ++++++-------------- 2 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 searx/engines/ccc_media.py diff --git a/searx/engines/ccc_media.py b/searx/engines/ccc_media.py new file mode 100644 index 000000000..1b5235220 --- /dev/null +++ b/searx/engines/ccc_media.py @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""media.ccc.de""" + +import datetime +from urllib.parse import urlencode + +from dateutil import parser + +about = { + 'website': 'https://media.ccc.de', + 'official_api_documentation': 'https://github.com/voc/voctoweb', + 'use_official_api': True, + 'require_api_key': False, + 'results': 'JSON', +} +categories = ['videos'] +paging = True + +api_url = "https://api.media.ccc.de" + + +def request(query, params): + args = {'q': query, 'page': params['pageno']} + params['url'] = f"{api_url}/public/events/search?{urlencode(args)}" + + return params + + +def response(resp): + results = [] + + for item in resp.json()['events']: + publishedDate = None + if item.get('date'): + publishedDate = parser.parse(item['date']) + + iframe_src = None + if len(item['recordings']) > 0: + iframe_src = item['recordings'][0]['recording_url'] + + results.append( + { + 'template': 'videos.html', + 'url': item['frontend_link'], + 'title': item['title'], + 'content': item['description'], + 'thumbnail': item['thumb_url'], + 'publishedDate': publishedDate, + 'length': datetime.timedelta(seconds=item['length']), + 'iframe_src': iframe_src, + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 6bf060144..6b169a86e 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -438,32 +438,19 @@ engines: shortcut: bt disabled: true - - name: ccc-tv - engine: xpath - paging: false - search_url: https://media.ccc.de/search/?q={query} - url_xpath: //div[@class="caption"]/h3/a/@href - title_xpath: //div[@class="caption"]/h3/a/text() - content_xpath: //div[@class="caption"]/h4/@title - categories: videos - disabled: true - shortcut: c3tv - about: - website: https://media.ccc.de/ - wikidata_id: Q80729951 - official_api_documentation: https://github.com/voc/voctoweb - use_official_api: false - require_api_key: false - results: HTML - # We don't set language: de here because media.ccc.de is not just - # for a German audience. It contains many English videos and many - # German videos have English subtitles. - - name: openverse engine: openverse categories: images shortcut: opv + - name: media.ccc.de + engine: ccc_media + shortcut: c3tv + # We don't set language: de here because media.ccc.de is not just + # for a German audience. It contains many English videos and many + # German videos have English subtitles. + disabled: true + - name: chefkoch engine: chefkoch shortcut: chef