audiothek

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

commit
be0cd1a2cbe6f909ed7293adc123ae48238432b4
parent
bbee907e67099fcee9f5ae4e4e83d0a3613ca906
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-05-31 20:15
add m3u support

Diffstat

M audiothek.py 32 ++++++++++++++++++++++++++++----

1 files changed, 28 insertions, 4 deletions


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

@@ -140,14 +140,12 @@ def render_feed(show, links):
  140   140     return ''.join(f'{line}\n' for line in feed)
  141   141 
  142   142 
  143    -1 async def feed(request):
  144    -1     offset = int(request.query.get('offset', '0'), 10)
  145    -1 
   -1   143 async def fetch_show(id, offset):
  146   144     url = 'https://api.ardaudiothek.de/graphql'
  147   145     params = {
  148   146         'query': QUERY,
  149   147         'variables': json.dumps({
  150    -1             'id': request.match_info['id'],
   -1   148             'id': id,
  151   149             'offset': offset,
  152   150             'count': COUNT,
  153   151         }),
@@ -165,6 +163,14 @@ async def feed(request):
  165   163     if show is None:
  166   164         raise web.HTTPNotFound
  167   165 
   -1   166     return show
   -1   167 
   -1   168 
   -1   169 async def feed(request):
   -1   170     id = int(request.match_info['id'], 10)
   -1   171     offset = int(request.query.get('offset', '0'), 10)
   -1   172     show = await fetch_show(id, offset)
   -1   173 
  168   174     links = {}
  169   175     if ORIGIN:
  170   176         links['self'] = f'{ORIGIN}{request.url.path_qs}'
@@ -183,6 +189,23 @@ async def feed(request):
  183   189     )
  184   190 
  185   191 
   -1   192 async def playlist(request):
   -1   193     id = int(request.match_info['id'], 10)
   -1   194     offset = int(request.query.get('offset', '0'), 10)
   -1   195     show = await fetch_show(id, offset)
   -1   196 
   -1   197     body = '#EXTM3U\n'
   -1   198     for item in reversed(show['items']['nodes']):
   -1   199         if item['audios']:
   -1   200             body += f'\n#EXTINF:{item["duration"]},{item["title"]}\n'
   -1   201             body += f'{item["audios"][0]["url"]}\n'
   -1   202 
   -1   203     return web.Response(
   -1   204         body=body.encode('utf8'),
   -1   205         content_type='text/plain',
   -1   206     )
   -1   207 
   -1   208 
  186   209 if __name__ == '__main__':
  187   210     parser = argparse.ArgumentParser()
  188   211     parser.add_argument('--port', type=int)
@@ -194,4 +217,5 @@ if __name__ == '__main__':
  194   217 
  195   218     app = web.Application()
  196   219     app.router.add_get('/{id:[0-9]+}.rss', feed)
   -1   220     app.router.add_get('/{id:[0-9]+}.m3u', playlist)
  197   221     web.run_app(app, host='localhost', port=args.port)