-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve algorithm to generate a filename from an image download #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve algorithm to generate a filename from an image download #896
Conversation
cmonfortep
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really liked to review the PR starting with the unit tests you prepared, it made me easier to understand the algorithm. I posted a few questions though.
Also, while testing this I found a difference between current develop (and main) vs this branch.
- Go to DDG and search something (e.g: wombat)
- Go to image tab
- Long press on an image
- Develop will download something like
downloadfile.binthat can be opened by any app gallery. - This branch will download something like
downloadfile(without extension), and file can't be opened.
app/src/androidTest/java/com/duckduckgo/app/browser/downloader/UriUtilsFilenameExtractorTest.kt
Outdated
Show resolved
Hide resolved
app/src/androidTest/java/com/duckduckgo/app/browser/downloader/UriUtilsFilenameExtractorTest.kt
Outdated
Show resolved
Hide resolved
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
|
|
||
| class UriUtilsFilenameExtractorTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to look the real implementation, but after going through the test cases, I have a question: What happens
- if
urlis empty,mimeTypeandcontentDispositionare not, which one of them as prevalence over the other? - if
urlis not empty and contains a filename, butmimetypesays another thing. which one will be returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- we would still fall back on
URLUtil.guessFileNamewhich is ultimately deciding on the precedence between them. I think that might even be varying the precedence based on OS version which isn't ideal, but that is unchanged from current behavior - I see
mimetypebeing preferred, but again, deferring that logic toURLUtil.guessFileName. so for this scenario, the behavior is unchanged from the current behavior.
| return NotGoodEnough | ||
| } | ||
|
|
||
| private fun guessFromUrl(url: String, contentDisposition: String?, mimeType: String?): String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That made me think this method was going to use only url: String to guess the fileName, but I think we will also use also the other params. Wanted to check if my assumption is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point; changed to guessFilename() which is hopefully clearer
app/src/main/java/com/duckduckgo/app/browser/downloader/FileDownloader.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/duckduckgo/app/browser/downloader/FileDownloader.kt
Outdated
Show resolved
Hide resolved
…craig/improve_download_filename_guessing
…craig/improve_download_filename_guessing # Conflicts: # app/src/main/java/com/duckduckgo/app/browser/DownloadConfirmationFragment.kt # app/src/main/java/com/duckduckgo/app/browser/downloader/FileDownloader.kt
cmonfortep
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for the changes!
Task/Issue URL: https://app.asana.com/0/0/1187737416677993/f
Tech Design URL:
CC:
Description:
When trying to download images, our app currently tries to guess what a good filename for the download will be, and often fails to produce something nice; it'll often end in a .*bin file type as its current implementation is somewhat naive in turning a URL into a filename.
This PR improves that situation by walking back the URL path, trying each to make a filename, and then returning the best filename produced. Worst case, this should produce the same result as the old algorithm, but best case it will pick out a much better filename.
Steps to test this PR:
FHJ84.jpgand notlatest.binas it was beforeInternal references:
Software Engineering Expectations
Technical Design Template