- commit
- d0039fd46be4c49163ad6cdeb053a0bd7ea2bfc6
- parent
- b6f9336f4a33bfd777a7f177ad2baedb0e4f238f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-02-06 20:43
add series feed
Diffstat
M | dropout.py | 24 | +++++++++++++++++++++--- |
M | templates/base.html | 1 | + |
A | templates/feed.xml | 31 | +++++++++++++++++++++++++++++++ |
M | templates/series.html | 4 | ++++ |
4 files changed, 57 insertions, 3 deletions
diff --git a/dropout.py b/dropout.py
@@ -15,6 +15,7 @@ from aiohttp import web 15 15 16 16 BASE_DIR = Path(__file__).parent 17 17 SITE_ID = 36348 -1 18 ORIGIN = None 18 19 19 20 env = jinja2.Environment( 20 21 loader=jinja2.FileSystemLoader(BASE_DIR / 'templates'), @@ -180,8 +181,7 @@ async def collection_view(request): 180 181 return render_response(request, 'collection.html', **data, items=items) 181 182 182 183183 -1 async def series_view(request):184 -1 id = request.match_info['id']-1 184 async def get_series(id): 185 185 series, _seasons = await asyncio.gather( 186 186 fetch(f'https://api.vhx.tv/collections/{id}'), 187 187 fetch_items(f'https://api.vhx.tv/collections/{id}/items'), @@ -193,7 +193,21 @@ async def series_view(request): 193 193 {**season, 'episodes': episodes} 194 194 for season, episodes in zip(_seasons, season_episodes) 195 195 ]196 -1 return render_response(request, 'series.html', **series, seasons=seasons)-1 196 return {**series, 'seasons': seasons} -1 197 -1 198 -1 199 async def series_view(request): -1 200 series = await get_series(request.match_info['id']) -1 201 return render_response(request, 'series.html', **series) -1 202 -1 203 -1 204 async def series_feed(request): -1 205 if not ORIGIN: -1 206 raise web.HTTPNotFound -1 207 series = await get_series(request.match_info['id']) -1 208 tpl = env.get_template('feed.xml') -1 209 body = tpl.render(**series, origin=ORIGIN) -1 210 return web.Response(body=body, content_type='text/xml') 197 211 198 212 199 213 async def get_next(data): @@ -242,8 +256,11 @@ async def favicon(request): 242 256 if __name__ == '__main__': 243 257 parser = argparse.ArgumentParser() 244 258 parser.add_argument('--port', type=int, default=8000) -1 259 parser.add_argument('--origin') 245 260 args = parser.parse_args() 246 261 -1 262 ORIGIN = args.origin -1 263 247 264 app = web.Application(middlewares=[ 248 265 web.normalize_path_middleware(), 249 266 ]) @@ -253,6 +270,7 @@ if __name__ == '__main__': 253 270 app.router.add_get('/search/', search_view) 254 271 app.router.add_get(r'/movie/{id:\d+}/', collection_view) 255 272 app.router.add_get(r'/series/{id:\d+}/', series_view) -1 273 app.router.add_get(r'/series/{id:\d+}.rss', series_feed) 256 274 app.router.add_get(r'/video/{id:\d+}/', video_view) 257 275 app.router.add_get(r'/video/{id:\d+}-{quality:\d+p}.mp4', file_view) 258 276 web.run_app(app, host='localhost', port=args.port)
diff --git a/templates/base.html b/templates/base.html
@@ -7,6 +7,7 @@ 7 7 <title>{% block title %}Dropin{% endblock %}</title> 8 8 <link rel="stylesheet" href="/static/style.css"> 9 9 <link rel="shortcut icon" href="/static/favicon.svg" type="image/svg+xml"> -1 10 {% block head %}{% endblock %} 10 11 </head> 11 12 <body> 12 13 <header id="header">
diff --git a/templates/feed.xml b/templates/feed.xml
@@ -0,0 +1,31 @@ -1 1 <?xml version="1.0" encoding="UTF-8"?> -1 2 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:podcast="https://podcastindex.org/namespace/1.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> -1 3 <channel> -1 4 <title>{{ title }}</title> -1 5 {% if description %}<description>{{ description }}</description>{% endif %} -1 6 <link>{{ _links.collection_page.href }}</link> -1 7 <language>en-US</language> -1 8 <itunes:author>Dropout</itunes:author> -1 9 <copyright>Dropout Connected Ventures</copyright> -1 10 <podcast:funding url="https://www.dropout.tv">Subscribe</podcast:funding> -1 11 <itunes:image href="{{ additional_images.aspect_ratio_1_1.medium }}" /> -1 12 <itunes:category text="Comedy" /> -1 13 {% for season in seasons %} -1 14 {% for episode in season.episodes %} -1 15 <item> -1 16 <title>{{ season.title }}: {{ episode.title }}</title> -1 17 <link>{{ episode._links.video_page.href }}</link> -1 18 <guid>{{ episode._links.video_page.href }}</guid> -1 19 <pubDate>{{ episode.created_at }}</pubDate> -1 20 {% if description %}<description>{{ episode.description }}</description>{% endif %} -1 21 <itunes:duration>{{ episode.duration.seconds }}</itunes:duration> -1 22 <itunes:image href="{{ episode.additional_images.aspect_ratio_1_1.medium }}" /> -1 23 {% if episode.episode_number %}<itunes:episode>{{ episode.episode_number }}</itunes:episode>{% endif%} -1 24 {% if episode.season_number %}<itunes:season>{{ episode.season_number }}</itunes:season>{% endif%} -1 25 <enclosure url="{{ origin }}/video/{{ episode.id }}-540p.mp4" length="0" type="video/mp4" /> -1 26 </item> -1 27 {% endfor %} -1 28 {% endfor %} -1 29 <atom:link href="{{ origin }}/series/{{ id }}.rss" rel="self" type="application/rss+xml" /> -1 30 </channel> -1 31 </rss>
diff --git a/templates/series.html b/templates/series.html
@@ -2,6 +2,10 @@ 2 2 3 3 {% block title %}{{ title }} - {{ super() }}{% endblock %} 4 4 -1 5 {% block head %} -1 6 <link rel="alternate" type="application/atom+xml" href="/series/{{ id }}.rss"> -1 7 {% endblock %} -1 8 5 9 {% block content %} 6 10 <div class="wrapper-wide"> 7 11 <h1>{{ title }}</h1>