音楽で楽しみましょう!-Let's have fun with music!-
Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
This commit is contained in:
parent
7c3206bf83
commit
54c6d22102
517 changed files with 637 additions and 639 deletions
35
api/funquail_api/audio/renderers.py
Normal file
35
api/funquail_api/audio/renderers.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import xml.etree.ElementTree as ET
|
||||
|
||||
from rest_framework import negotiation, renderers
|
||||
|
||||
from funkwhale_api.subsonic.renderers import dict_to_xml_tree
|
||||
|
||||
|
||||
class PodcastRSSRenderer(renderers.JSONRenderer):
|
||||
media_type = "application/rss+xml"
|
||||
|
||||
def render(self, data, accepted_media_type=None, renderer_context=None):
|
||||
if not data:
|
||||
# when stream view is called, we don't have any data
|
||||
return super().render(data, accepted_media_type, renderer_context)
|
||||
final = {
|
||||
"version": "2.0",
|
||||
"xmlns:atom": "http://www.w3.org/2005/Atom",
|
||||
"xmlns:itunes": "http://www.itunes.com/dtds/podcast-1.0.dtd",
|
||||
"xmlns:content": "http://purl.org/rss/1.0/modules/content/",
|
||||
"xmlns:media": "http://search.yahoo.com/mrss/",
|
||||
}
|
||||
final.update(data)
|
||||
tree = dict_to_xml_tree("rss", final)
|
||||
return render_xml(tree)
|
||||
|
||||
|
||||
class PodcastRSSContentNegociation(negotiation.DefaultContentNegotiation):
|
||||
def select_renderer(self, request, renderers, format_suffix=None):
|
||||
return (PodcastRSSRenderer(), PodcastRSSRenderer.media_type)
|
||||
|
||||
|
||||
def render_xml(tree):
|
||||
return b'<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(
|
||||
tree, encoding="utf-8"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue