.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
tagesschau.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""ARD: `Tagesschau API`_
3
4The Tagesschau is a news program of the ARD. Via the `Tagesschau API`_, current
5news and media reports are available in JSON format. The `Bundesstelle für Open
6Data`_ offers a `OpenAPI`_ portal at bundDEV_ where APIs are documented an can
7be tested.
8
9This SearXNG engine uses the `/api2u/search`_ API.
10
11.. _/api2u/search: http://tagesschau.api.bund.dev/
12.. _bundDEV: https://bund.dev/apis
13.. _Bundesstelle für Open Data: https://github.com/bundesAPI
14.. _Tagesschau API: https://github.com/AndreasFischer1985/tagesschau-api/blob/main/README_en.md
15.. _OpenAPI: https://swagger.io/specification/
16
17"""
18
19from datetime import datetime
20from urllib.parse import urlencode
21import re
22
23about = {
24 'website': "https://tagesschau.de",
25 'wikidata_id': "Q703907",
26 'official_api_documentation': None,
27 'use_official_api': True,
28 'require_api_key': False,
29 'results': 'JSON',
30 'language': 'de',
31}
32categories = ['general', 'news']
33paging = True
34
35results_per_page = 10
36base_url = "https://www.tagesschau.de"
37
38use_source_url = True
39"""When set to false, display URLs from Tagesschau, and not the actual source
40(e.g. NDR, WDR, SWR, HR, ...)
41
42.. note::
43
44 The actual source may contain additional content, such as commentary, that is
45 not displayed in the Tagesschau.
46
47"""
48
49
50def request(query, params):
51 args = {
52 'searchText': query,
53 'pageSize': results_per_page,
54 'resultPage': params['pageno'] - 1,
55 }
56
57 params['url'] = f"{base_url}/api2u/search?{urlencode(args)}"
58
59 return params
60
61
62def response(resp):
63 results = []
64
65 json = resp.json()
66
67 for item in json['searchResults']:
68 item_type = item.get('type')
69 if item_type in ('story', 'webview'):
70 results.append(_story(item))
71 elif item_type == 'video':
72 results.append(_video(item))
73 else:
74 logger.error("unknown result type: %s", item_type)
75
76 return results
77
78
79def _story(item):
80 return {
81 'title': item['title'],
82 'thumbnail': item.get('teaserImage', {}).get('imageVariants', {}).get('16x9-256'),
83 'publishedDate': datetime.strptime(item['date'][:19], '%Y-%m-%dT%H:%M:%S'),
84 'content': item['firstSentence'],
85 'url': item['shareURL'] if use_source_url else item['detailsweb'],
86 }
87
88
89def _video(item):
90 streams = item['streams']
91 video_url = streams.get('h264s') or streams.get('h264m') or streams.get('h264l') or streams.get('h264xl')
92 title = item['title']
93
94 if "_vapp.mxf" in title:
95 title = title.replace("_vapp.mxf", "")
96 title = re.sub(r"APP\d+ (FC-)?", "", title, count=1)
97
98 # sometimes, only adaptive m3u8 streams are available, so video_url is None
99 url = video_url or f"{base_url}/multimedia/video/{item['sophoraId']}.html"
100
101 return {
102 'template': 'videos.html',
103 'title': title,
104 'thumbnail': item.get('teaserImage', {}).get('imageVariants', {}).get('16x9-256'),
105 'publishedDate': datetime.strptime(item['date'][:19], '%Y-%m-%dT%H:%M:%S'),
106 'content': item.get('firstSentence', ''),
107 'iframe_src': video_url,
108 'url': url,
109 }
request(query, params)
Definition tagesschau.py:50