calvinaquino / LNReader-Android

Light novel reader for android test project collab
Apache License 2.0
119 stars 36 forks source link

imageUrls handling #193

Closed yaminorito closed 9 years ago

yaminorito commented 9 years ago

These problems are most likely connected to #186

The app crashes on clicking the cover image thumbnail of some novels. Tried inserting try/catch on CommonParser.getImageFilePageFromImageUrl function:

public static String getImageFilePageFromImageUrl(String imageUrl) {
        String pageUrl = "";
        // http://www.baka-tsuki.org/project/images/4/4a/Bakemonogatari_Up.png
        // http://www.baka-tsuki.org/project/images/thumb/4/4a/Bakemonogatari_Up.png/200px-Bakemonogatari_Up.png
        // http://www.baka-tsuki.org/project/index.php?title=File:Bakemonogatari_Up.png
        String[] tokens = imageUrl.split("/");
        try {
            if (imageUrl.contains("/thumb/")) {
                // from thumbnail
                pageUrl = tokens[8];
            } else {
                // from full page
                pageUrl = tokens[7];
            }
        } catch(Exception e){
            Log.e(TAG, "ERROR OCCURRED with given URL string: "+ imageUrl.toString());
            Log.e(TAG, "ERROR invoked: ", e);
        }
        pageUrl = UIHelper.getBaseUrl(LNReaderApplication.getInstance()) + "/project/index.php?title=File:" + pageUrl;
        return pageUrl;
    }

And got this:

06-14 12:19:49.531    1616-1616/com.erakk.lnreader E/class com.erakk.lnreader.parser.CommonParser﹕ ERROR OCCURRED with given URL string: http://www.baka-tsuki.org/project/thumb.php?f=DAL_v01_cover.jpg&width=300
06-14 12:19:49.543    1616-1616/com.erakk.lnreader E/class com.erakk.lnreader.parser.CommonParser﹕ ERROR invoked:
    java.lang.ArrayIndexOutOfBoundsException: length=5; index=7
            at com.erakk.lnreader.parser.CommonParser.getImageFilePageFromImageUrl(CommonParser.java:300)
            at com.erakk.lnreader.activity.DisplayLightNovelDetailsActivity.handleCoverClick(DisplayLightNovelDetailsActivity.java:626)
            at com.erakk.lnreader.activity.DisplayLightNovelDetailsActivity.access$600(DisplayLightNovelDetailsActivity.java:53)
            at com.erakk.lnreader.activity.DisplayLightNovelDetailsActivity$4.onClick(DisplayLightNovelDetailsActivity.java:570)
            at android.view.View.performClick(View.java:4222)
            at android.view.View$PerformClick.run(View.java:17620)
            at android.os.Handler.handleCallback(Handler.java:800)
            at android.os.Handler.dispatchMessage(Handler.java:100)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5391)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

The culprit:

http://www.baka-tsuki.org/project/thumb.php?f=DAL_v01_cover.jpg&width=300

But thanks to my improper try/catch, these errors followed which should have been fine since these were due to my try/catch:

06-14 12:19:52.861    1616-4499/com.erakk.lnreader E/class com.erakk.lnreader.task.LoadImageTask﹕ Error when getting image: HTTP error fetching URL
    org.jsoup.HttpStatusException: HTTP error fetching URL. Status=400, URL=http://www.baka-tsuki.org/project/index.php?title=File:
            at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:546)
            at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:521)
            at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:225)
            at com.erakk.lnreader.dao.NovelsDao.connect(NovelsDao.java:1486)
            at com.erakk.lnreader.dao.NovelsDao.getImageModelFromInternet(NovelsDao.java:1225)
            at com.erakk.lnreader.dao.NovelsDao.getImageModel(NovelsDao.java:1197)
            at com.erakk.lnreader.task.LoadImageTask.doInBackground(LoadImageTask.java:53)
            at com.erakk.lnreader.task.LoadImageTask.doInBackground(LoadImageTask.java:16)
            at android.os.AsyncTask$2.call(AsyncTask.java:287)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:838)
06-14 12:19:52.890    1616-1616/com.erakk.lnreader E/class com.erakk.lnreader.activity.DisplayImageActivity﹕ Cannot load image.
    org.jsoup.HttpStatusException: HTTP error fetching URL. Status=400, URL=http://www.baka-tsuki.org/project/index.php?title=File:
            at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:546)
            at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:521)
            at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:225)
            at com.erakk.lnreader.dao.NovelsDao.connect(NovelsDao.java:1486)
            at com.erakk.lnreader.dao.NovelsDao.getImageModelFromInternet(NovelsDao.java:1225)
            at com.erakk.lnreader.dao.NovelsDao.getImageModel(NovelsDao.java:1197)
            at com.erakk.lnreader.task.LoadImageTask.doInBackground(LoadImageTask.java:53)
            at com.erakk.lnreader.task.LoadImageTask.doInBackground(LoadImageTask.java:16)
            at android.os.AsyncTask$2.call(AsyncTask.java:287)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:838)
06-14 12:20:33.382    1616-1616/com.erakk.lnreader E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: /mnt/sdcard/.0bakafiles/project: open failed: EISDIR (Is a directory)

It resulted on getting Bitmap Empty message whenever the novel was opened. As I said, this should have been fine and all, but I can't get it back to the way it was(NOTE: restoring from a backup should not be the solution here).

I looked into pages.db and this is what happened: pages db browsed

Tried deleting the novel and re-downloaded it's info but it didn't work. Tried all the "refresh"es on the app but it didn't work either. I tried using "Download All Info", and it made things worse, rendering all updated novels missing it's cover image as shown in the image above. If nothing worked, then when is the cover image url updated properly?

Nandaka commented 9 years ago

baka tsuki change the thumbnail generator using thumb.php, so the cover detection is broken. I have working copy (in testing) because I'm doing some major reworking on the ui :P I'll upload the beta tomorrow.

Nandaka commented 9 years ago

Try this version: http://www.mediafire.com/download/qdzdzootvrxv957/BakaReader-EX-1.1.31-beta2.apk

yaminorito commented 9 years ago

I am trying it out now, so far it is working. The covers are properly displayed now, and simply downloading the novel info fixes the missing cover. Thanks! I have some things I'd like to say about the UI, I'll make a new issue for that.

Suika commented 9 years ago

Sorry for that. I had to make all the changes at once or else some parts of the wiki wouldn't work. As Nandaka said, the thumbs.php is being used. https://www.mediawiki.org/wiki/Manual:Thumb.php

Mithgol commented 9 years ago

I've installed version 1.1.31 (201506180) from Google Play.

I still can't see the cover for “Rokujouma no Shinryakusha!?” or “Tokyo Ravens” even after a refresh (“REFRESH CHAPTER LIST”).

yaminorito commented 9 years ago

Mine is showing. Have you tried "Download novel info"? Try deleting the novel, refresh novel list, then redownload novel, don't worry any images linked with the novel wont be gone.

Mithgol commented 9 years ago

I've tried deleting the novel, refreshing, redownloading.

The cover is still missing.

When downloading, the following message is briefly displayed:

(screenshot)

This is strange, because the URL in the message is correct (I can open it on the mobile device using Firefox and the cover is there).

Nandaka commented 9 years ago

If you using firewall/antivirus, try to disable it first? possible to get the log cat?

Mithgol commented 9 years ago

Upgraded to 1.1.32 (201507090).

I now see pictures in chapters but BakaReader EX doesn't seem to download their large scale versions. (That includes novel covers because “Settings” → “General” → “Use Hi-Res Cover” is on.)

I do not use firewall or antivirus on Android, though I may be affected by the country-wide anti-lolicon censorship on the Internet. (I still think the latter's not the case because it's not natural for censorship to target only hi-res images and also because I was able to open the same URL from mobile Firefox on the same device.)

What is the log cat?

yaminorito commented 9 years ago

logcat is a command that can be used thru an adb shell for android logging purposes. There are apps you can use to directly get the logs in realtime without using adb shell or a computer. more on logcat: https://developer.android.com/tools/help/logcat.html App I use: https://play.google.com/store/apps/details?id=com.nolanlawson.logcat&hl=en There are others, just search logcat on playstore.

Nandaka commented 9 years ago

For big image in contents, ensure the settings in Settings -> Storage -> Images -> Download Full-Res Image is tick.

Tested with Boku to Kanojo Vol.1 Ilust, it does download the big image.

Mithgol commented 9 years ago

That setting (“Download Full-Res Image”) is tick.

I have yet another guess. My current BakaReader EX on HTC One M9 has a database that has been restored (“Settings” → “Storage” → “Database” → “Restore Novel Database Backup”) from the backup made on my old HTC One M7 phone. That old phone hadn't “Settings” → “Storage” → “Image Backup” → “Process All Images” ticked because the phone was short on internal memory. Could that be the real reason behind all that?

Nandaka commented 9 years ago

If you restore only the DB, then you need to redownload the images.

Try to refresh the content and check if it download the big images.

Also, in the Settings -> Storage -> Images -> Image Save Location, make sure it point to the correct path.

Mithgol commented 9 years ago

Thanks for that tip.

In “Settings” → “Storage” → “Images” → “Image Save Location”, the value was “/storage/emulated/0/Android/data/com.erakk.lnreader/files”. However, when I visited that directory (in Total Commander), I couldn't see any image files there (only 46k project file and a subdirectory called databases with two files pages.db and pages.db-journal which I assume are SQLite).

Fortunately, I have a 128 Gb microSD card installed. I've changed “Image Save Location” to the value “/storage/ext_sd/Android/data/com.erakk.lnreader/files” and now the large images are downloaded (to that directory) as they should.

My problem's gone, though I'm left with the question: what was wrong with the “/storage/emulated/0/Android/data/com.erakk.lnreader/files” path?