-
Notifications
You must be signed in to change notification settings - Fork 1
/
url.js
101 lines (89 loc) · 2.84 KB
/
url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const cdn = require("./cdn");
/**
* Returns the base url of hitomi.la
*/
function getBaseUrl(cdn = null) {
if(cdn === null)
return "https://hitomi.la";
return `https://${cdn}.hitomi.la`;
}
/**
* Returns the url of Hitomi's search library js.
*/
function getSearchlibJsUrl() {
return `${getBaseUrl("ltn")}/searchlib.js`;
}
/**
* Returns the url of Hitomi's gallery data.
* @param {number} index
*/
function getGalleryJson(index) {
return `${getBaseUrl("ltn")}/galleries${index}.json`;
}
/**
* Returns the base stream url of hitomi.la
*/
function getStreamingUrl() {
return "https://streaming.hitomi.la";
}
/**
* Returns the url of a json file that contains tag metadata.
*/
function getTagsUrl() {
return `${getBaseUrl()}/tags.json`;
}
/**
* Returns the url of a javascript file that contains a gallery's page information.
*/
function getPageInfoUrl(galleryId) {
return `${getBaseUrl(cdn.getGalleryInfoPrefix())}/galleries/${galleryId}.js`;
}
/**
* Returns the url that links to original hitomi.la gallery.
*/
function getGalleryUrl(galleryId) {
return `${getBaseUrl()}/galleries/${galleryId}.html`;
}
/**
* Returns the url of an image file that represents a page in gallery with specified values.
*/
function getPageFileUrl(galleryId, fileName) {
return `${getBaseUrl(cdn.getFullPrefix(galleryId, false))}/galleries/${galleryId}/${fileName}`;
}
/**
* Returns the url of a video file that represents an anime in gallery with specified values.
* @param {string} galleryName
*/
function getAnimeFileUrl(galleryName) {
let fileName = galleryName.toLowerCase()
.replace(/ {0,}- {0,}/g, "-") // Hyphens (code 45) should not be surrounded by any space character.
.replace(/ {0,}– {0,}/g, "-") // Hyphens (code 8211) should not be surrounded by any space character.
.replace(/ +/g, "-") // Replace empty spaces with hyphens.
.replace(/[^A-Za-z0-9-]/g, ""); // Remove all non-alphanumeric characters.
return `${getStreamingUrl()}/videos/${fileName}.mp4`;
}
/**
* Returns the url of an image file that represents the big thumbnail of a page with specified values. The only valid parameter for "fileName" is the first page name retrieved from getPageInfoUrl.
*/
function getBigThumbUrl(galleryId, fileName) {
return `${getBaseUrl(cdn.getBasePrefix(true))}/bigtn/${galleryId}/${fileName}.jpg`;
}
/**
* Returns the url of an image file that represents the small thumbnail of a page with specified values.
*/
function getSmallThumbUrl(galleryId, fileName) {
return `${getBaseUrl(cdn.getFullPrefix(galleryId, true))}/smalltn/${galleryId}/${fileName}.jpg`;
}
module.exports = {
getBaseUrl,
getSearchlibJsUrl,
getGalleryJson,
getStreamingUrl,
getTagsUrl,
getPageInfoUrl,
getGalleryUrl,
getPageFileUrl,
getAnimeFileUrl,
getBigThumbUrl,
getSmallThumbUrl
};