Update main.py
Browse files
main.py
CHANGED
|
@@ -54,34 +54,20 @@ def duckduckgo_search(query: str):
|
|
| 54 |
|
| 55 |
# ========== OPDS Feed Generators ==========
|
| 56 |
|
| 57 |
-
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 |
-
#
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
"
|
| 70 |
-
|
| 71 |
-
"type": "application/atom+xml;profile=opds-catalog;kind=acquisition"
|
| 72 |
-
})
|
| 73 |
-
ET.SubElement(entry, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 74 |
-
|
| 75 |
-
# Link to cached (not implemented yet)
|
| 76 |
-
entry2 = ET.SubElement(feed, "entry")
|
| 77 |
-
ET.SubElement(entry2, "title").text = "Cached"
|
| 78 |
-
ET.SubElement(entry2, "id").text = "cached"
|
| 79 |
-
ET.SubElement(entry2, "link", {
|
| 80 |
-
"rel": "subsection",
|
| 81 |
-
"href": "/opds/cached",
|
| 82 |
-
"type": "application/atom+xml;profile=opds-catalog;kind=navigation"
|
| 83 |
-
})
|
| 84 |
-
ET.SubElement(entry2, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 85 |
|
| 86 |
return ET.tostring(feed, encoding="utf-8", xml_declaration=True)
|
| 87 |
|
|
@@ -109,7 +95,9 @@ def generate_search_feed(query: str, results):
|
|
| 109 |
|
| 110 |
@app.get("/opds", include_in_schema=False)
|
| 111 |
def opds_root() -> Response:
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
return Response(content=xml_data, media_type="application/atom+xml")
|
| 114 |
|
| 115 |
@app.get("/opds/search")
|
|
@@ -131,4 +119,5 @@ def download_fb2(url: str) -> Response:
|
|
| 131 |
content=fb2,
|
| 132 |
media_type="application/fb2+xml",
|
| 133 |
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
| 134 |
-
)
|
|
|
|
|
|
| 54 |
|
| 55 |
# ========== OPDS Feed Generators ==========
|
| 56 |
|
| 57 |
+
def generate_root_feed(base_url: str):
|
| 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 |
+
# Templated search link (OpenSearch-style)
|
| 65 |
+
feed.append(ET.Element("link", {
|
| 66 |
+
"rel": "search",
|
| 67 |
+
"type": "application/atom+xml",
|
| 68 |
+
"href": f"{base_url}/opds/search?q={{searchTerms}}",
|
| 69 |
+
"templated": "true"
|
| 70 |
+
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
return ET.tostring(feed, encoding="utf-8", xml_declaration=True)
|
| 73 |
|
|
|
|
| 95 |
|
| 96 |
@app.get("/opds", include_in_schema=False)
|
| 97 |
def opds_root() -> Response:
|
| 98 |
+
# derive base URL dynamically or configure
|
| 99 |
+
base_url = "http://localhost:8000"
|
| 100 |
+
xml_data = generate_root_feed(base_url)
|
| 101 |
return Response(content=xml_data, media_type="application/atom+xml")
|
| 102 |
|
| 103 |
@app.get("/opds/search")
|
|
|
|
| 119 |
content=fb2,
|
| 120 |
media_type="application/fb2+xml",
|
| 121 |
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
| 122 |
+
)
|
| 123 |
+
|