Last active
December 29, 2020 03:38
-
-
Save GiovanH/7ab8fb009e4233c939abb95a05096ad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function completeImage(img) { | |
if ((!img.file_url || img.file_url.length < 5) && img.preview_url) { | |
img.file_url = img.preview_url | |
.replace("/thumbnails/", "/images/") | |
.replace("/thumbnail_", "/"); | |
} | |
return img; | |
} | |
var fake_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.112 Safari/537.36)" | |
export var source = { | |
name: "Gelbooru (0.1)", | |
modifiers: ["rating:safe", "rating:questionable", "rating:explicit", "user:", "fav:", "fastfav:", "md5:", "source:", "id:", "width:", "height:", "score:", "mpixels:", "filesize:", "date:", "gentags:", "arttags:", "chartags:", "copytags:", "approver:", "parent:", "sub:", "order:id", "order:id_desc", "order:score", "order:score_asc", "order:mpixels", "order:mpixels_asc", "order:filesize", "order:landscape", "order:portrait", "order:favcount", "order:rank", "parent:none", "unlocked:rating"], | |
tagFormat: { | |
case: "lower", | |
wordSeparator: "_", | |
}, | |
searchFormat: { | |
and: " ", | |
}, | |
auth: {}, | |
apis: { | |
html: { | |
name: "Regex", | |
auth: [], | |
forcedLimit: 20, | |
search: { | |
url: function (query) { | |
var page = (query.page - 1) * 20; | |
var search = query.search && query.search.length > 0 ? encodeURIComponent(query.search) : "all"; | |
return { | |
url: "/index.php?page=post&s=list&tags=" + search + "&pid=" + page, | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
var pageCount = Grabber.regexToConst("page", '<a href="[^"]+pid=(?<page>\\d+)" alt="last page">>></a>', src); | |
return { | |
images: Grabber.regexToImages('<span class="thumb"><a id="p(?<id>\\d+)" href="[^"]+"><img src="(?<preview_url>[^"]*thumbnail_(?<md5>[^.]+)\\.[^"]+)" alt="post" border="0" title=" *(?<tags>[^"]*) *score:(?<score>[^ "]+) *rating:(?<rating>[^ "]+) *"/></a>[^<]*(?:<script type="text/javascript">[^<]*//<!\\[CDATA\\[[^<]*posts\\[[^]]+\\] = \\{\'tags\':\'(?<tags_2>[^\']+)\'\\.split\\(/ /g\\), \'rating\':\'(?<rating_2>[^\']+)\', \'score\':(?<score_2>[^,]+), \'user\':\'(?<author>[^\']+)\'\\}[^<]*//\\]\\]>[^<]*</script>)?</span>', src).map(completeImage), | |
pageCount: pageCount ? (parseInt(pageCount, 10) / 20) + 1 : undefined, | |
tags: Grabber.regexToTags('<li><a[^>]*>\\+</a><a [^>]*>-</a> <span [^>]*>\\? <a href="[^"]*">(?<name>[^<]+)</a> (?<count>\\d+)</span></li>', src), | |
}; | |
}, | |
}, | |
details: { | |
url: function (id, md5) { | |
return { | |
url: "/index.php?page=post&s=view&id=" + id, | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
return { | |
tags: Grabber.regexToTags('<li><a[^>]*>\\+</a><a [^>]*>-</a> <span [^>]*>\\? <a href="[^"]*">(?<name>[^<]+)</a> (?<count>\\d+)</span></li>', src), | |
imageUrl: Grabber.regexToConst("url", '<img[^>]+src="([^"]+)"[^>]+onclick="Note\\.toggle\\(\\);"[^>]*/>', src), | |
}; | |
}, | |
}, | |
check: { | |
url: function () { | |
return { | |
url: "/", | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
return src.search(/Running Gelbooru(?: Beta)? 0\.1/) !== -1 | |
|| src.search(/Running <a[^>]*>Gelbooru<\/a>(?: Beta)? 0\.1/) !== -1; | |
}, | |
}, | |
}, | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function completeImage(img) { | |
if ((!img.file_url || img.file_url.length < 5) && img.preview_url) { | |
img.file_url = img.preview_url | |
.replace("/thumbnails/", "/images/") | |
.replace("/thumbnail_", "/"); | |
} | |
return img; | |
} | |
var fake_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.112 Safari/537.36)" | |
export var source = { | |
name: "Gelbooru (0.2)", | |
modifiers: ["rating:safe", "rating:questionable", "rating:explicit", "user:", "fav:", "fastfav:", "md5:", "source:", "id:", "width:", "height:", "score:", "mpixels:", "filesize:", "date:", "gentags:", "arttags:", "chartags:", "copytags:", "approver:", "parent:", "sub:", "order:id", "order:id_desc", "order:score", "order:score_asc", "order:mpixels", "order:mpixels_asc", "order:filesize", "order:landscape", "order:portrait", "order:favcount", "order:rank", "parent:none", "unlocked:rating", "sort:updated", "sort:id", "sort:score", "sort:rating", "sort:user", "sort:height", "sort:width", "sort:parent", "sort:source", "sort:updated"], | |
tagFormat: { | |
case: "lower", | |
wordSeparator: "_", | |
}, | |
searchFormat: { | |
and: " ", | |
}, | |
auth: { | |
url: { | |
type: "url", | |
fields: [ | |
{ | |
id: "userId", | |
key: "user_id", | |
}, | |
{ | |
id: "apiKey", | |
key: "api_key", | |
}, | |
], | |
}, | |
session: { | |
type: "post", | |
url: "/index.php?page=account&s=login&code=00", | |
fields: [ | |
{ | |
id: "pseudo", | |
key: "user", | |
}, | |
{ | |
id: "password", | |
key: "pass", | |
type: "password", | |
}, | |
], | |
check: { | |
type: "cookie", | |
key: "user_id", | |
}, | |
}, | |
}, | |
apis: { | |
xml: { | |
name: "XML", | |
auth: [], | |
maxLimit: 1000, | |
search: { | |
url: function (query, opts) { | |
var page = query.page - 1; | |
var search = query.search.replace(/(^| )order:/gi, "$1sort:"); | |
var fav = search.match(/(?:^| )fav:(\d+)(?:$| )/); | |
if (fav) { | |
return { error: "XML API cannot search favorites" }; | |
} | |
return { | |
url: "/index.php?page=dapi&s=post&q=index&limit=" + opts.limit + "&pid=" + page + "&tags=" + encodeURIComponent(search), | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
var parsed = Grabber.parseXML(src); | |
// Handle error messages | |
if ("response" in parsed && parsed["response"]["@attributes"]["success"] === "false") { | |
return { error: parsed["response"]["@attributes"]["reason"] }; | |
} | |
var data = Grabber.makeArray(parsed.posts.post); | |
var images = []; | |
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) { | |
var image = data_1[_i]; | |
if (image && "@attributes" in image) { | |
images.push(completeImage(image["@attributes"])); | |
} | |
} | |
return { | |
images: images, | |
imageCount: parsed.posts["@attributes"]["count"], | |
}; | |
}, | |
}, | |
}, | |
html: { | |
name: "Regex", | |
auth: [], | |
forcedLimit: 42, | |
search: { | |
url: function (query, opts, previous) { | |
try { | |
var search = query.search.replace(/(^| )order:/gi, "$1sort:"); | |
var fav = search.match(/(?:^| )fav:(\d+)(?:$| )/); | |
if (fav) { | |
var pagePart = Grabber.pageUrl(query.page, previous, 20000, "&pid={page}", "&pid={page}", " id:<{min}&p=1", function (p) { return (p - 1) * 50; }); | |
return { | |
url: "/index.php?page=favorites&s=view&id=" + fav[1] + pagePart, | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
} | |
else { | |
var pagePart = Grabber.pageUrl(query.page, previous, 20000, "&pid={page}", "&pid={page}", " id:<{min}&p=1", function (p) { return (p - 1) * 42; }); | |
return { | |
url: "/index.php?page=post&s=list&tags=" + encodeURIComponent(search) + pagePart, | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
} | |
} | |
catch (e) { | |
return { error: e.message }; | |
} | |
}, | |
parse: function (src) { | |
if (src.indexOf("Unable to search this deep") !== -1) { | |
return { error: "Page too far" }; | |
} | |
var pageCountRaw = Grabber.regexMatch('<a href="[^"]+pid=(?<page>\\d+)[^"]*"[^>]*>[^<]+</a>\\s*(?:<b>(?<last>\\d+)</b>\\s*)?(?:</div>|<br ?/>)', src); | |
var pageCount = pageCountRaw && (pageCountRaw["last"] || pageCountRaw["page"]); | |
return { | |
images: Grabber.regexToImages('<span[^>]*(?: id="?\\w(?<id>\\d+)"?)?>\\s*<a[^>]*(?: id="?\\w(?<id_2>\\d+)"?)[^>]*>\\s*<img [^>]*(?:src|data-original)="(?<preview_url>[^"]+/thumbnail_(?<md5>[^.]+)\\.[^"]+)" [^>]*title="\\s*(?<tags>[^"]+)"[^>]*/?>\\s*</a>|<img\\s+class="preview"\\s+src="(?<preview_url_2>[^"]+/thumbnail_(?<md5_2>[^.]+)\\.[^"]+)" [^>]*title="\\s*(?<tags_2>[^"]+)"[^>]*/?>', src).map(completeImage), | |
tags: Grabber.regexToTags('<li class="tag-type-(?<type>[^"]+)">(?:[^<]*<a[^>]*>[^<]*</a>)*[^<]*<a[^>]*>(?<name>[^<]*)</a>[^<]*<span[^>]*>(?<count>\\d+)</span>[^<]*</li>', src), | |
pageCount: pageCount && parseInt(pageCount, 10) / 42 + 1, | |
}; | |
}, | |
}, | |
details: { | |
url: function (id, md5) { | |
return { | |
url: "/index.php?page=post&s=view&id=" + id, | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
return { | |
tags: Grabber.regexToTags('<li class="tag-type-(?<type>[^"]+)">(?:[^<]*<a[^>]*>[^<]*</a>)*[^<]*<a[^>]*>(?<name>[^<]*)</a>[^<]*<span[^>]*>(?<count>\\d+)</span>[^<]*</li>', src), | |
imageUrl: Grabber.regexToConst("url", '<img[^>]+src="([^"]+)"[^>]+onclick="Note\\.toggle\\(\\);"[^>]*/>', src), | |
}; | |
}, | |
}, | |
tagTypes: false, | |
tags: { | |
url: function (query) { | |
var sorts = { count: "desc", date: "asc", name: "asc" }; | |
var orderBys = { count: "index_count", date: "updated", name: "tag" }; | |
var page = (query.page - 1) * 50; | |
return { | |
url: "/index.php?page=tags&s=list&pid=" + page + "&sort=" + sorts[query.order] + "&order_by=" + orderBys[query.order], | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
return { | |
tags: Grabber.regexToTags('<tr>\\s*<td>(?<count>\\d+)</td>\\s*<td><span class="tag-type-(?<type>[^"]+)"><a[^>]+>(?<name>.+?)</a></span></td>', src), | |
}; | |
}, | |
}, | |
check: { | |
url: function () { | |
return { | |
url: "/", | |
headers: { | |
"User-Agent": fake_agent | |
} | |
}; | |
}, | |
parse: function (src) { | |
return src.search(/Running Gelbooru(?: Beta)? 0\.2/) !== -1 | |
|| src.search(/Running <a[^>]*>Gelbooru<\/a>(?: Beta)? 0\.2/) !== -1; | |
}, | |
}, | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment