audiothek

alternative frontend for ardaudiothek.de  https://audiothek.ce9e.org/
git clone https://git.ce9e.org/audiothek.git

commit
a5d58767fe926258a56dbc5fa750750d3150b65d
parent
f286a408b9df2ba966182f7d03ccfce67ae50375
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-02-14 08:35
refactor field mapping

see https://github.com/Podcast-Standards-Project/PSP-1-Podcast-RSS-Specification
and https://www.castfeedvalidator.com

Diffstat

M audiothek.py 61 +++++++++++++++++++++++++++++++++++++++++++++++++------------

1 files changed, 49 insertions, 12 deletions


diff --git a/audiothek.py b/audiothek.py

@@ -13,9 +13,11 @@ query ProgramSetEpisodesQuery($id:ID!, $offset:Int!, $count:Int!) {
   13    13     result:programSet(id:$id) {
   14    14         id
   15    15         title
   16    -1         path
   -1    16         synopsis
   -1    17         sharingUrl
   17    18         image{ url1X1 }
   18    19         publicationService{ title }
   -1    20         editorialCategory{ title }
   19    21         items(offset:$offset first:$count orderBy:PUBLISH_DATE_DESC filter:{isPublished:{equalTo:true}}) {
   20    22             pageInfo{hasNextPage endCursor}
   21    23             nodes{
@@ -24,15 +26,37 @@ query ProgramSetEpisodesQuery($id:ID!, $offset:Int!, $count:Int!) {
   24    26                 publishDate
   25    27                 summary
   26    28                 duration
   27    -1                 path
   -1    29                 sharingUrl
   28    30                 image{ url1X1 }
   29    -1                 audios{ url }
   -1    31                 audios{ url size mimeType }
   30    32             }
   31    33         }
   32    34     }
   33    35 }
   34    36 """.replace('    ', '').replace('\n', ' ').strip()
   35    37 
   -1    38 CATEGORIES = {
   -1    39     'Doku & Reportage': 'Society & Culture',
   -1    40     'True Crime': 'True Crime',
   -1    41     'Hörbuch': 'Fiction',
   -1    42     'Hörspiel': 'Fiction',
   -1    43     'Politik & Hintergrund': 'News',
   -1    44     'Krieg in der Ukraine': 'News',
   -1    45     'Geschichte': 'History',
   -1    46     'Wissen': 'Education',
   -1    47     'Musik entdecken': 'Music',
   -1    48     'Leben': 'Society & Culture',
   -1    49     'Liebe, Sex & Psychologie': 'Society & Culture',
   -1    50     'Comedy & Satire': 'Comedy',
   -1    51     'Sport': 'Sports',
   -1    52     'Für Kinder': 'Kids & Family',
   -1    53     'Retro': 'Society & Culture',
   -1    54     'Gesellschaft': 'Society & Culture',
   -1    55     'Wirtschaft': 'Business',
   -1    56     'Religion & Philosophie': 'Society & Culture',
   -1    57     'Kultur': 'Society & Culture',
   -1    58 }
   -1    59 
   36    60 
   37    61 def indent(lines):
   38    62     return [f'\t{line}' for line in lines]
@@ -52,20 +76,29 @@ def el(tag, content=None, attrs={}):
   52    76         return f'<{tag}{a}>{escape(content)}</{tag}>'
   53    77 
   54    78 
   -1    79 def get_itunes_category(show):
   -1    80     title = show['editorialCategory']['title'].strip()
   -1    81     return CATEGORIES.get(title, title)
   -1    82 
   -1    83 
   55    84 def render_items(items):
   56    85     lines = []
   57    86     for item in reversed(items):
   58    87         lines += el('item', [
   59    88             el('title', item['title']),
   60    -1             el('link', 'https://www.ardaudiothek.de' + item['path']),
   61    -1             el('guid', 'https://www.ardaudiothek.de' + item['path']),
   -1    89             el('link', item['sharingUrl']),
   -1    90             el('guid', item['sharingUrl']),
   62    91             el('enclosure', attrs={
   63    92                 'url': item['audios'][0]['url'],
   64    -1                 'type': 'audio/mpeg',
   -1    93                 'length': str(item['audios'][0]['size'] or 0),
   -1    94                 'type': item['audios'][0]['mimeType'],
   65    95             }),
   66    96             el('pubDate', item['publishDate']),
   67    97             el('description', item['summary']),
   68    98             el('itunes:duration', str(item['duration'])),
   -1    99             el('itunes:image', attrs={
   -1   100                 'href': item['image']['url1X1'].replace('{width}', '1400'),
   -1   101             }),
   69   102         ])
   70   103     return lines
   71   104 
@@ -79,12 +112,16 @@ def render_feed(show, links):
   79   112             'xmlns:itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd',
   80   113         }, content=el('channel', [
   81   114             el('title', show['title']),
   82    -1             el('link', 'https://www.ardaudiothek.de' + show['path']),
   83    -1             *el('image', [
   84    -1                 el('url', show['image']['url1X1'].replace('{width}', '64')),
   85    -1                 el('width', '64'),
   86    -1                 el('height', '64'),
   87    -1             ]),
   -1   115             el('description', show['synopsis']),
   -1   116             el('link', show['sharingUrl']),
   -1   117             el('language', 'de-DE'),
   -1   118             el('category', show['editorialCategory']['title']),
   -1   119             el('itunes:author', show['publicationService']['title']),
   -1   120             el('itunes:category', attrs={'text': get_itunes_category(show)}),
   -1   121             el('itunes:image', attrs={
   -1   122                 'href': show['image']['url1X1'].replace('{width}', '1400'),
   -1   123             }),
   -1   124             el('generator', 'audiothek.ce9e.org'),
   88   125             *render_items(show['items']['nodes']),
   89   126             *[
   90   127                 el('atom:link', attrs={