Update main.py
Browse files
main.py
CHANGED
@@ -58,13 +58,14 @@ def generate_root_feed():
|
|
58 |
ns = "http://www.w3.org/2005/Atom"
|
59 |
ET.register_namespace("", ns)
|
60 |
feed = ET.Element("feed", xmlns=ns)
|
|
|
61 |
ET.SubElement(feed, "title").text = "DuckDuckGo OPDS Catalog"
|
62 |
ET.SubElement(feed, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
63 |
|
64 |
# Relative search link (OpenSearch template)
|
65 |
feed.append(ET.Element("link", {
|
66 |
"rel": "search",
|
67 |
-
"type": "application/atom+xml",
|
68 |
"href": "/opds/search?q={searchTerms}",
|
69 |
"templated": "true"
|
70 |
}))
|
@@ -76,6 +77,7 @@ def generate_search_feed(query: str, results):
|
|
76 |
ns = "http://www.w3.org/2005/Atom"
|
77 |
ET.register_namespace("", ns)
|
78 |
feed = ET.Element("feed", xmlns=ns)
|
|
|
79 |
ET.SubElement(feed, "title").text = f"Search results for '{query}'"
|
80 |
ET.SubElement(feed, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
81 |
|
@@ -96,17 +98,23 @@ def generate_search_feed(query: str, results):
|
|
96 |
@app.get("/opds", include_in_schema=False)
|
97 |
def opds_root() -> Response:
|
98 |
xml_data = generate_root_feed()
|
99 |
-
return Response(
|
|
|
|
|
|
|
100 |
|
101 |
@app.get("/opds/search")
|
102 |
def opds_search(
|
103 |
q: str = Query(..., description="Search query"),
|
104 |
searchType: str = Query(None, alias="searchType")
|
105 |
) -> Response:
|
106 |
-
# Ignoring searchType parameter
|
107 |
results = duckduckgo_search(q)
|
108 |
xml_data = generate_search_feed(q, results)
|
109 |
-
return Response(
|
|
|
|
|
|
|
110 |
|
111 |
@app.get("/download")
|
112 |
def download_fb2(url: str) -> Response:
|
@@ -122,4 +130,3 @@ def download_fb2(url: str) -> Response:
|
|
122 |
media_type="application/fb2+xml",
|
123 |
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
124 |
)
|
125 |
-
|
|
|
58 |
ns = "http://www.w3.org/2005/Atom"
|
59 |
ET.register_namespace("", ns)
|
60 |
feed = ET.Element("feed", xmlns=ns)
|
61 |
+
ET.SubElement(feed, "id").text = "urn:uuid:duckopds-catalog"
|
62 |
ET.SubElement(feed, "title").text = "DuckDuckGo OPDS Catalog"
|
63 |
ET.SubElement(feed, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
64 |
|
65 |
# Relative search link (OpenSearch template)
|
66 |
feed.append(ET.Element("link", {
|
67 |
"rel": "search",
|
68 |
+
"type": "application/atom+xml;profile=opds-catalog;kind=acquisition",
|
69 |
"href": "/opds/search?q={searchTerms}",
|
70 |
"templated": "true"
|
71 |
}))
|
|
|
77 |
ns = "http://www.w3.org/2005/Atom"
|
78 |
ET.register_namespace("", ns)
|
79 |
feed = ET.Element("feed", xmlns=ns)
|
80 |
+
ET.SubElement(feed, "id").text = f"urn:uuid:duckopds-search-{quote(query)}"
|
81 |
ET.SubElement(feed, "title").text = f"Search results for '{query}'"
|
82 |
ET.SubElement(feed, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
83 |
|
|
|
98 |
@app.get("/opds", include_in_schema=False)
|
99 |
def opds_root() -> Response:
|
100 |
xml_data = generate_root_feed()
|
101 |
+
return Response(
|
102 |
+
content=xml_data,
|
103 |
+
media_type="application/atom+xml;profile=opds-catalog;kind=navigation"
|
104 |
+
)
|
105 |
|
106 |
@app.get("/opds/search")
|
107 |
def opds_search(
|
108 |
q: str = Query(..., description="Search query"),
|
109 |
searchType: str = Query(None, alias="searchType")
|
110 |
) -> Response:
|
111 |
+
# Ignoring searchType parameter
|
112 |
results = duckduckgo_search(q)
|
113 |
xml_data = generate_search_feed(q, results)
|
114 |
+
return Response(
|
115 |
+
content=xml_data,
|
116 |
+
media_type="application/atom+xml;profile=opds-catalog;kind=acquisition"
|
117 |
+
)
|
118 |
|
119 |
@app.get("/download")
|
120 |
def download_fb2(url: str) -> Response:
|
|
|
130 |
media_type="application/fb2+xml",
|
131 |
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
132 |
)
|
|