Here is are all the functions you should need, scroll down to the implementation. First is the original javascript code, after that a test, then the actual code.
Code:
package com.example.demo;
import java.util.*;
import java.util.regex.*;
import org.junit.*;
/*
var adapose = false;
function subdomain_from_galleryid(g, number_of_frontends) {
if (adapose) {
return '0';
}
var o = g % number_of_frontends;
return String.fromCharCode(97 + o);
}
function subdomain_from_url(url, base) {
var retval = 'a';
if (base) {
retval = base;
}
var number_of_frontends = 3;
var b = 16;
var r = /\/[0-9a-f]\/([0-9a-f]{2})\//;
var m = r.exec(url);
if (!m) {
return retval;
}
var g = parseInt(m[1], b);
if (!isNaN(g)) {
if (g < 0x30) {
number_of_frontends = 2;
}
if (g < 0x09) {
g = 1;
}
retval = subdomain_from_galleryid(g, number_of_frontends) + retval;
}
return retval;
}
function url_from_url(url, base) {
return url.replace(/\/\/..?\.hitomi\.la\//, '//'+subdomain_from_url(url, base)+'.hitomi.la/');
}
function full_path_from_hash(hash) {
if (hash.length < 3) {
return hash;
}
return hash.replace(/^.*(..)(.)$/, '$2/$1/'+hash);
}
function url_from_hash(galleryid, image, dir, ext) {
ext = ext || dir || image.name.split('.').pop();
dir = dir || 'images';
return '//a.hitomi.la/'+dir+'/'+full_path_from_hash(image.hash)+'.'+ext;
}
function url_from_url_from_hash(galleryid, image, dir, ext, base) {
return url_from_url(url_from_hash(galleryid, image, dir, ext), base);
}
*/
public class Hito {
/*
url_from_url_from_hash("1566712", {"width":300,"hash":"4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3","haswebp":1,"name":"1.jpg","height":241,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmallsmalltn/3/af/4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3","haswebp":1,"name":"1.jpg","height":241,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmalltn/3/af/4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3","haswebp":1,"name":"1.jpg","height":241,"hasavif":0}, "smalltn", "jpg","tn") -> "//btn.hitomi.la/smalltn/3/af/4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53","haswebp":1,"name":"2.jpg","height":241,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//ctn.hitomi.la/webpsmallsmalltn/3/f5/f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53","haswebp":1,"name":"2.jpg","height":241,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//ctn.hitomi.la/webpsmalltn/3/f5/f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53","haswebp":1,"name":"2.jpg","height":241,"hasavif":0}, "smalltn", "jpg","tn") -> "//ctn.hitomi.la/smalltn/3/f5/f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858","haswebp":1,"name":"3.jpg","height":241,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmallsmalltn/8/85/692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858","haswebp":1,"name":"3.jpg","height":241,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmalltn/8/85/692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858","haswebp":1,"name":"3.jpg","height":241,"hasavif":0}, "smalltn", "jpg","tn") -> "//btn.hitomi.la/smalltn/8/85/692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5","haswebp":1,"name":"4.jpg","height":241,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmallsmalltn/5/cd/1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5","haswebp":1,"name":"4.jpg","height":241,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmalltn/5/cd/1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5","haswebp":1,"name":"4.jpg","height":241,"hasavif":0}, "smalltn", "jpg","tn") -> "//btn.hitomi.la/smalltn/5/cd/1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285","haswebp":1,"name":"5.jpg","height":226,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//atn.hitomi.la/webpsmallsmalltn/5/28/b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285","haswebp":1,"name":"5.jpg","height":226,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//atn.hitomi.la/webpsmalltn/5/28/b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":300,"hash":"b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285","haswebp":1,"name":"5.jpg","height":226,"hasavif":0}, "smalltn", "jpg","tn") -> "//atn.hitomi.la/smalltn/5/28/b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976","haswebp":1,"name":"6.jpg","height":300,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmallsmalltn/6/97/152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976","haswebp":1,"name":"6.jpg","height":300,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmalltn/6/97/152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976","haswebp":1,"name":"6.jpg","height":300,"hasavif":0}, "smalltn", "jpg","tn") -> "//btn.hitomi.la/smalltn/6/97/152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011","haswebp":1,"name":"7.jpg","height":300,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmallsmalltn/1/01/ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011","haswebp":1,"name":"7.jpg","height":300,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//btn.hitomi.la/webpsmalltn/1/01/ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011","haswebp":1,"name":"7.jpg","height":300,"hasavif":0}, "smalltn", "jpg","tn") -> "//btn.hitomi.la/smalltn/1/01/ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011.jpg" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745","haswebp":1,"name":"8.jpg","height":300,"hasavif":0}, "webpsmallsmalltn", "webp","tn") -> "//ctn.hitomi.la/webpsmallsmalltn/5/74/c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745","haswebp":1,"name":"8.jpg","height":300,"hasavif":0}, "webpsmalltn", "webp","tn") -> "//ctn.hitomi.la/webpsmalltn/5/74/c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745.webp" common.js:70:8
url_from_url_from_hash("1566712", {"width":202,"hash":"c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745","haswebp":1,"name":"8.jpg","height":300,"hasavif":0}, "smalltn", "jpg","tn") -> "//ctn.hitomi.la/smalltn/5/74/c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745.jpg" common.js:70:8
*/
@Test
public void test() {
Assert.assertEquals( "//btn.hitomi.la/webpsmallsmalltn/3/af/4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3.webp", url_from_url_from_hash("1566712", mapOf("4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3", "1.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmalltn/3/af/4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3.webp", url_from_url_from_hash("1566712", mapOf("4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3", "1.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/smalltn/3/af/4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3.jpg", url_from_url_from_hash("1566712", mapOf("4616e0234c44ca6748546a4eee701efe88d338e7809a72c81fc0576c9e3f9af3", "1.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//ctn.hitomi.la/webpsmallsmalltn/3/f5/f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53.webp", url_from_url_from_hash("1566712", mapOf("f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53", "2.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//ctn.hitomi.la/webpsmalltn/3/f5/f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53.webp", url_from_url_from_hash("1566712", mapOf("f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53", "2.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//ctn.hitomi.la/smalltn/3/f5/f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53.jpg", url_from_url_from_hash("1566712", mapOf("f88d8c37a29d7df775ab478c803970e208ea183049af5ece7b0abfd909f4ff53", "2.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmallsmalltn/8/85/692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858.webp", url_from_url_from_hash("1566712", mapOf("692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858", "3.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmalltn/8/85/692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858.webp", url_from_url_from_hash("1566712", mapOf("692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858", "3.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/smalltn/8/85/692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858.jpg", url_from_url_from_hash("1566712", mapOf("692e0ab1eae1184c0a34e5e801e5769c2e80ccd1ac9c62abfec1cc3b32d9d858", "3.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmallsmalltn/5/cd/1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5.webp", url_from_url_from_hash("1566712", mapOf("1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5", "4.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmalltn/5/cd/1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5.webp", url_from_url_from_hash("1566712", mapOf("1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5", "4.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/smalltn/5/cd/1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5.jpg", url_from_url_from_hash("1566712", mapOf("1070c2c2233886dc3ff0e38afd45ce6c66153118b995379e6f6e39f6410c2cd5", "4.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//atn.hitomi.la/webpsmallsmalltn/5/28/b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285.webp", url_from_url_from_hash("1566712", mapOf("b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285", "5.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//atn.hitomi.la/webpsmalltn/5/28/b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285.webp", url_from_url_from_hash("1566712", mapOf("b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285", "5.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//atn.hitomi.la/smalltn/5/28/b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285.jpg", url_from_url_from_hash("1566712", mapOf("b15aa86f9fb459ec60dd82f8ca142e80ec6d11fe87f8a2db1b2b8e8c47f0f285", "5.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmallsmalltn/6/97/152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976.webp", url_from_url_from_hash("1566712", mapOf("152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976", "6.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmalltn/6/97/152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976.webp", url_from_url_from_hash("1566712", mapOf("152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976", "6.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/smalltn/6/97/152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976.jpg", url_from_url_from_hash("1566712", mapOf("152d981622fe31781498da5b1e42963abafda46f7942760baa2e35b06b309976", "6.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmallsmalltn/1/01/ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011.webp", url_from_url_from_hash("1566712", mapOf("ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011", "7.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/webpsmalltn/1/01/ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011.webp", url_from_url_from_hash("1566712", mapOf("ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011", "7.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//btn.hitomi.la/smalltn/1/01/ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011.jpg", url_from_url_from_hash("1566712", mapOf("ba00573b20260b0ad87578d59ad273ec15f9e70dc13ac579066665b89e49f011", "7.jpg"), "smalltn", "jpg", "tn"));
Assert.assertEquals( "//ctn.hitomi.la/webpsmallsmalltn/5/74/c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745.webp", url_from_url_from_hash("1566712", mapOf("c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745", "8.jpg"), "webpsmallsmalltn", "webp", "tn"));
Assert.assertEquals( "//ctn.hitomi.la/webpsmalltn/5/74/c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745.webp", url_from_url_from_hash("1566712", mapOf("c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745", "8.jpg"), "webpsmalltn", "webp", "tn"));
Assert.assertEquals( "//ctn.hitomi.la/smalltn/5/74/c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745.jpg", url_from_url_from_hash("1566712", mapOf("c695e220937ea67f3ab73d947c1b3d6ddfd45f3009ef9f0ee59dbf40b457c745", "8.jpg"), "smalltn", "jpg", "tn"));
}
Map<String, String> mapOf(String hash, String name) {
HashMap<String, String> m = new HashMap<>();
m.put("hash", hash);
m.put("name", name);
return m;
}
///////////////////////////////////////////////////////////////////////
/////////////////////// Implementation Below /////////////////////
///////////////////////////////////////////////////////////////////////
public static final Pattern SUBDOMAIN_FROM_URL_PATTERN = Pattern.compile("/[0-9a-f]/([0-9a-f]{2})/");
public static final Pattern URL_FROM_URL_PATTERN = Pattern.compile("//..?\\.hitomi\\.la/");
public static final Pattern FULL_PATH_FROM_HASH_PATTERN = Pattern.compile("^.*(..)(.)$");
String subdomain_from_galleryid(int g, int number_of_frontends) {
int o = g % number_of_frontends;
return String.valueOf((char)(97 + o));
}
String subdomain_from_url(String url, String base) {
String retval = "a";
if (base != null) {
retval = base;
}
int number_of_frontends = 3;
Matcher m = SUBDOMAIN_FROM_URL_PATTERN.matcher(url);
if (!m.find()) {
return retval;
}
try {
int g = Integer.parseInt(m.group(1), 16);
if (g < 0x30) {
number_of_frontends = 2;
}
if (g < 0x09) {
g = 1;
}
retval = subdomain_from_galleryid(g, number_of_frontends) + retval;
} catch (NumberFormatException ignore) {}
return retval;
}
String url_from_url(String url, String base) {
return URL_FROM_URL_PATTERN.matcher(url).replaceAll("//" + subdomain_from_url(url, base) + ".hitomi.la/");
}
String full_path_from_hash(String hash) {
if (hash.length() < 3) {
return hash;
}
return FULL_PATH_FROM_HASH_PATTERN.matcher(hash).replaceAll("$2/$1/" + hash);
}
String url_from_hash(String galleryid, Map<String, String> image, String dir, String ext) {
ext = isNotBlank(ext) ? ext : (isNotBlank(dir) ? dir :
image.get("name").split("\\.")[1]);
dir = isNotBlank(dir) ? dir : "images";
return "//a.hitomi.la/" + dir + '/' + full_path_from_hash(image.get("hash")) + '.' + ext;
}
String url_from_url_from_hash(String galleryid, Map<String, String> image, String dir, String ext, String base) {
return url_from_url(url_from_hash(galleryid, image, dir, ext), base);
}
boolean isNotBlank(String str) {
return str != null && !str.isEmpty();
}
}