ahodesuka / ahoviewer

A GTK image viewer, manga reader, and booru browser
MIT License
483 stars 30 forks source link

Wrong URLs for Safebooru #52

Closed vijuarez closed 7 years ago

vijuarez commented 7 years ago

Hey.

Something broke with Safebooru, it doesn't seem to be fetching the right URLs. No images or thumbnails load at all, terminal gives the problem right away:

Error while downloading thumbnail http://safebooru.org//safebooru.org/thumbnails/1919/thumbnail_0cb8d7abc5140263a2c3ddf8a0d8dff088aa12c4.png HTTP response code said error

I'm using Ubuntu 16.04 LTS. Everything working fine for other boorus.

ahodesuka commented 7 years ago

Looks like they added the domain to the file urls in their api.

XenosisReaper commented 7 years ago

Is there any way to fix this on our end?

OrdinaryMagician commented 7 years ago

This is done on gelbooru and konachan now, too.

And... it was also being done on sites like rule34.xxx since long ago.

It should be an easy fix, just appending the protocol if the two first characters of the URL are //, I guess.

Here's a hastily written patch to fix it.

diff --git a/src/booru/imagelist.cc b/src/booru/imagelist.cc
index 756a118..08a75e0 100644
--- a/src/booru/imagelist.cc
+++ b/src/booru/imagelist.cc
@@ -38,10 +38,16 @@ void ImageList::load(const xmlDocument &posts, const Page &page)
         page.get_site()->add_tags(tags);

         if (thumbUrl[0] == '/')
-            thumbUrl = page.get_site()->get_url() + thumbUrl;
+            if (thumbUrl[1] == '/')
+                thumbUrl = "http:" + thumbUrl;
+            else
+                thumbUrl = page.get_site()->get_url() + thumbUrl;

         if (imageUrl[0] == '/')
-            imageUrl = page.get_site()->get_url() + imageUrl;
+            if (imageUrl[1] == '/')
+                imageUrl = "http:" + imageUrl;
+            else
+                imageUrl = page.get_site()->get_url() + imageUrl;

         std::string postUrl = page.get_site()->get_post_url(post.get_attribute("id"));