Bionus / imgbrd-grabber

Very customizable imageboard/booru downloader with powerful filenaming features.
https://www.bionus.org/imgbrd-grabber/
Apache License 2.0
2.4k stars 212 forks source link

Allow kemono.su search to work on specific users #3153

Open Gebsfrom404 opened 1 month ago

Gebsfrom404 commented 1 month ago

I tried to use Grabber to collect images from kemono, but run into problem that it cannot search for posts of a specific user. First i tried duplicating and mangling site/Kemono/model.js to work with changed urls that had hardcoded 'service'/user/'user_id' part of the path. This works but it's too cumbersome to do every time.

So i tried changing model.js so it would use regular expression in query string. For example: user:asdasd:123123123 where asdasd is service and 123123123 is a user id.

For this I made changes to kemono.su model.js:

//added this at the beginning of the file before functions
const user_regex = /user:(\D+):(\d+)/; 
//changed json.search.url:
url: function (query, opts) {
    var offset = (query.page - 1) * 50;
    const service_match = query.search.match(user_regex)
    if (service_match){
        return "/api/v1/"+service_match[1]+"/user/"+service_match[2]+"?o=" + offset + "&q=" + encodeURIComponent(query.search.replace(service_match[0],''));
    }
    return "/api/v1/posts?o=" + offset + "&q=" + encodeURIComponent(query.search);
}
//made the same change to html.search.url
url: function (query, opts) {
    var offset = (query.page - 1) * 50;
    const service_match = query.search.match(user_regex)
    if (service_match){
        return "/"+service_match[1]+"/user/"+service_match[2]+"?o=" + offset + "&q=" + encodeURIComponent(query.search.replace(service_match[0],''));
    }
    return "/posts?o=" + offset + "&q=" + encodeURIComponent(query.search);
}
//changed base url in json.gallery to include /api/v1
return "/api/v1/".concat(identity["service"], "/user/").concat(identity["user"], "/post/").concat(identity["id"]);
//Also there is error on line json.gallery.parse
//var data = JSON.parse(src)[0];
//should be
var data = JSON.parse(src);

If something better will be added wonderful but at least there is this solution.

BallOpener commented 1 month ago

This works great, thank you!

Only issue is that the gallery does not display multiple files

Gebsfrom404 commented 1 month ago

Strange, with default sources json+html i can see gallery images. Just html does not have required functions for that. image

BallOpener commented 1 month ago

For some reason, it works for me now. It has to be that the server was down when I was using it or when you hit the IP limit (aka too many IP pings), clicking an image and then cycling through may reach that. Using a VPN bypasses this.

Screenshot 2024-05-24 190925