Update main.py
Browse files
main.py
CHANGED
|
@@ -62,13 +62,27 @@ def generate_root_feed():
|
|
| 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 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
return ET.tostring(feed, encoding="utf-8", xml_declaration=True)
|
| 74 |
|
|
@@ -83,8 +97,8 @@ def generate_search_feed(query: str, results):
|
|
| 83 |
|
| 84 |
for title, url in results:
|
| 85 |
entry = ET.SubElement(feed, "entry")
|
| 86 |
-
ET.SubElement(entry, "title").text = title
|
| 87 |
ET.SubElement(entry, "id").text = url
|
|
|
|
| 88 |
ET.SubElement(entry, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 89 |
ET.SubElement(entry, "link", {
|
| 90 |
"rel": "http://opds-spec.org/acquisition",
|
|
@@ -108,7 +122,7 @@ def opds_search(
|
|
| 108 |
q: str = Query(..., description="Search query"),
|
| 109 |
searchType: str = Query(None, alias="searchType")
|
| 110 |
) -> Response:
|
| 111 |
-
#
|
| 112 |
results = duckduckgo_search(q)
|
| 113 |
xml_data = generate_search_feed(q, results)
|
| 114 |
return Response(
|
|
@@ -130,3 +144,4 @@ def download_fb2(url: str) -> Response:
|
|
| 130 |
media_type="application/fb2+xml",
|
| 131 |
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
| 132 |
)
|
|
|
|
|
|
| 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 |
+
# Entry for search subsection
|
| 66 |
+
entry_search = ET.SubElement(feed, "entry")
|
| 67 |
+
ET.SubElement(entry_search, "id").text = "urn:uuid:duckopds-search-section"
|
| 68 |
+
ET.SubElement(entry_search, "title").text = "Search"
|
| 69 |
+
ET.SubElement(entry_search, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 70 |
+
ET.SubElement(entry_search, "link", {
|
| 71 |
+
"rel": "subsection",
|
| 72 |
+
"href": "/opds/search",
|
| 73 |
+
"type": "application/atom+xml;profile=opds-catalog;kind=acquisition"
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
# Entry for cached subsection (placeholder)
|
| 77 |
+
entry_cached = ET.SubElement(feed, "entry")
|
| 78 |
+
ET.SubElement(entry_cached, "id").text = "urn:uuid:duckopds-cached-section"
|
| 79 |
+
ET.SubElement(entry_cached, "title").text = "Cached"
|
| 80 |
+
ET.SubElement(entry_cached, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 81 |
+
ET.SubElement(entry_cached, "link", {
|
| 82 |
+
"rel": "subsection",
|
| 83 |
+
"href": "/opds/cached",
|
| 84 |
+
"type": "application/atom+xml;profile=opds-catalog;kind=navigation"
|
| 85 |
+
})
|
| 86 |
|
| 87 |
return ET.tostring(feed, encoding="utf-8", xml_declaration=True)
|
| 88 |
|
|
|
|
| 97 |
|
| 98 |
for title, url in results:
|
| 99 |
entry = ET.SubElement(feed, "entry")
|
|
|
|
| 100 |
ET.SubElement(entry, "id").text = url
|
| 101 |
+
ET.SubElement(entry, "title").text = title
|
| 102 |
ET.SubElement(entry, "updated").text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 103 |
ET.SubElement(entry, "link", {
|
| 104 |
"rel": "http://opds-spec.org/acquisition",
|
|
|
|
| 122 |
q: str = Query(..., description="Search query"),
|
| 123 |
searchType: str = Query(None, alias="searchType")
|
| 124 |
) -> Response:
|
| 125 |
+
# Ignore searchType parameter
|
| 126 |
results = duckduckgo_search(q)
|
| 127 |
xml_data = generate_search_feed(q, results)
|
| 128 |
return Response(
|
|
|
|
| 144 |
media_type="application/fb2+xml",
|
| 145 |
headers={"Content-Disposition": f"attachment; filename={filename}"}
|
| 146 |
)
|
| 147 |
+
|