Skip to content

[feat] Support mimetypes in DocumentRegistry:hasProvider()#7155

Merged
Frenzie merged 7 commits intokoreader:masterfrom
Frenzie:5478-support-url-mimetype-in-hasProvider
Jan 17, 2021
Merged

[feat] Support mimetypes in DocumentRegistry:hasProvider()#7155
Frenzie merged 7 commits intokoreader:masterfrom
Frenzie:5478-support-url-mimetype-in-hasProvider

Conversation

@Frenzie
Copy link
Copy Markdown
Member

@Frenzie Frenzie commented Jan 16, 2021

Fixes #5478.


This change is Reviewable

@Frenzie Frenzie added this to the 2021.02 milestone Jan 16, 2021
Copy link
Copy Markdown
Contributor

@poire-z poire-z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing needed on the OPDS side ?

@Frenzie
Copy link
Copy Markdown
Member Author

Frenzie commented Jan 16, 2021

Nothing needed on the OPDS side ?

I found "can someone explain to me" a bit rude, so I wasn't feeling it tonight.

But it'd look something like this:

diff --git a/frontend/ui/widget/opdsbrowser.lua b/frontend/ui/widget/opdsbrowser.lua
index c8c0b4ca..cdceffde 100644
--- a/frontend/ui/widget/opdsbrowser.lua
+++ b/frontend/ui/widget/opdsbrowser.lua
@@ -4,6 +4,7 @@ local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
 local Cache = require("cache")
 local CacheItem = require("cacheitem")
 local ConfirmBox = require("ui/widget/confirmbox")
+local DocumentRegistry = require("document/documentregistry")
 local InfoMessage = require("ui/widget/infomessage")
 local Menu = require("ui/widget/menu")
 local MultiInputDialog = require("ui/widget/multiinputdialog")
@@ -45,27 +46,6 @@ local OPDSBrowser = Menu:extend{
     image_rel = "http://opds-spec.org/image",
     thumbnail_rel = "http://opds-spec.org/image/thumbnail",
 
-    formats = {
-        ["application/epub+zip"] = "EPUB",
-        ["application/fb2+zip"] = "FB2",
-        ["application/pdf"] = "PDF",
-        ["text/html"] = "HTML",
-        ["text/plain"] = "TXT",
-        ["application/x-mobipocket-ebook"] = "MOBI",
-        ["application/x-mobi8-ebook"] = "AZW3",
-        ["application/vnd.amazon.mobi8-ebook"] = "AZW3",
-        ["application/x-cbz"] = "CBZ",
-        ["application/vnd.comicbook+zip"] = "CBZ",
-        ["application/zip"] = "CBZ",
-        ["application/x-cbr"] = "CBR",
-        ["application/vnd.comicbook-rar"] = "CBR",
-        ["application/x-rar-compressed"] = "CBR",
-        ["application/vnd.rar"] = "CBR",
-        ["application/djvu"] = "DJVU",
-        ["image/x-djvu"] = "DJVU",
-        ["image/vnd.djvu"] = "DJVU",
-    },
-
     width = Screen:getWidth(),
     height = Screen:getHeight(),
     no_title = false,
@@ -646,12 +626,17 @@ function OPDSBrowser:showDownloads(item)
             local index = (i-1)*downloadsperline + j
             local acquisition = acquisitions[index]
             if acquisition then
-                local format = self.formats[acquisition.type]
-                if format then
+                local filetype
+                if DocumentRegistry:hasProvider(nil, acquisition.type) then
+                    filetype = DocumentRegistry:mimeToExt(acquisition.type)
+                elseif DocumentRegistry:hasProvider(acquisition.href) then
+                    filetype = string.upper(util.getFileNameSuffix(acquisition.href))
+                end
+                if filetype then
                     -- append DOWNWARDS BLACK ARROW ⬇ U+2B07 to format
-                    button.text = format .. "\xE2\xAC\x87"
+                    button.text = filetype .. "\xE2\xAC\x87"
                     button.callback = function()
-                        self:downloadFile(item, format, acquisition.href)
+                        self:downloadFile(item, filetype, acquisition.href)
                         UIManager:close(self.download_dialog)
                     end
                     table.insert(line, button)

@Frenzie Frenzie modified the milestones: 2021.02, 2021.01 Jan 17, 2021
@Frenzie Frenzie merged commit 1ef6d0b into koreader:master Jan 17, 2021
@Frenzie Frenzie deleted the 5478-support-url-mimetype-in-hasProvider branch January 17, 2021 08:22
@Draic
Copy link
Copy Markdown

Draic commented Jan 17, 2021

Nothing needed on the OPDS side ?

I found "can someone explain to me" a bit rude, so I wasn't feeling it tonight.

wasn't meant to be rude, sorry.

@Frenzie
Copy link
Copy Markdown
Member Author

Frenzie commented Jan 17, 2021

Alright, no problem. A file as described in #6585 (comment) should now work with the fallback, but I've only been able to test it for Wallabag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend DocumentRegistry to provide supported document info to OPDS & Wallabag

3 participants