summaryrefslogtreecommitdiff
path: root/searx/engines/podcastindex.py
blob: d0aa85fb82f883400d59b3bc2833d241cb0cbca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Podcast Index
"""

from urllib.parse import quote_plus
from datetime import datetime

about = {
    'website': 'https://podcastindex.org',
    'official_api_documentation': None,  # requires an account
    'use_official_api': False,
    'require_api_key': False,
    'results': 'JSON',
}
categories = []

base_url = "https://podcastindex.org"


def request(query, params):
    params['url'] = f"{base_url}/api/search/byterm?q={quote_plus(query)}"
    return params


def response(resp):
    results = []

    json = resp.json()

    for result in json['feeds']:
        results.append(
            {
                'url': result['link'],
                'title': result['title'],
                'content': result['description'],
                'thumbnail': result['image'],
                'publishedDate': datetime.utcfromtimestamp(result['newestItemPubdate']),
                'metadata': f"{result['author']}, {result['episodeCount']} episodes",
            }
        )

    return results