summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorRafael Marçalo <rafael.marcalo@cast.pt>2022-10-21 02:00:10 +0100
committerRafael Marçalo <rafael.marcalo@cast.pt>2022-10-21 02:00:10 +0100
commitdad891f9d7f060c5d2f4c9f47c410730aa48d5df (patch)
tree8d9bca113b426bb2dd6d5b9884a3ed6e84202f79 /server
Added initially developed files
Diffstat (limited to 'server')
-rw-r--r--server/js/apibay.js16
-rw-r--r--server/js/template.js124
2 files changed, 140 insertions, 0 deletions
diff --git a/server/js/apibay.js b/server/js/apibay.js
new file mode 100644
index 0000000..74fcfb3
--- /dev/null
+++ b/server/js/apibay.js
@@ -0,0 +1,16 @@
+"use strict";
+
+const axios = require('axios');
+const server = 'https://apibay.org';
+
+async function getRequest(url)
+{
+ return await axios.get(url);
+}
+
+async function hit(query)
+{
+ return await getRequest(server + '/q.php?q=' + encodeURI(query));
+}
+
+module.exports = {hit}; \ No newline at end of file
diff --git a/server/js/template.js b/server/js/template.js
new file mode 100644
index 0000000..9316dd7
--- /dev/null
+++ b/server/js/template.js
@@ -0,0 +1,124 @@
+"use strict";
+
+function getTrackers()
+{
+ let tr = '&tr=' + encodeURIComponent('udp://tracker.coppersurfer.tk:6969/announce');
+ tr += '&tr=' + encodeURIComponent('udp://tracker.openbittorrent.com:6969/announce');
+ tr += '&tr=' + encodeURIComponent('udp://9.rarbg.to:2710/announce');
+ tr += '&tr=' + encodeURIComponent('udp://9.rarbg.me:2780/announce');
+ tr += '&tr=' + encodeURIComponent('udp://9.rarbg.to:2730/announce');
+ tr += '&tr=' + encodeURIComponent('udp://tracker.opentrackr.org:1337');
+ tr += '&tr=' + encodeURIComponent('http://p4p.arenabg.com:1337/announce');
+ tr += '&tr=' + encodeURIComponent('udp://tracker.torrent.eu.org:451/announce');
+ tr += '&tr=' + encodeURIComponent('udp://tracker.tiny-vps.com:6969/announce');
+ tr += '&tr=' + encodeURIComponent('udp://open.stealth.si:80/announce');
+ return tr;
+}
+
+function makeMagnet(info_hash, name)
+{
+ return 'magnet:?xt=urn:btih:' + info_hash + '&dn=' + encodeURIComponent(name) + getTrackers();
+}
+
+function round_to_precision(x, precision)
+{
+ let y = +x + (precision === undefined ? 0.5 : precision / 2);
+ let sz = y - (y % (precision === undefined ? 1 : +precision)) + '';
+ if (sz.indexOf('.') == -1) return sz;
+ else return sz.substring(0, sz.indexOf('.') + 3);
+}
+
+function bytesToSize(size)
+{
+ if (size >= 1125899906842624) return round_to_precision(size / 1125899906842624, 0.01) + ' PiB';
+ if (size >= 1099511627776) return round_to_precision(size / 1099511627776, 0.01) + ' TiB';
+ if (size >= 1073741824) return round_to_precision(size / 1073741824, 0.01) + ' GiB';
+ if (size >= 1048576) return round_to_precision(size / 1048576, 0.01) + ' MiB';
+ if (size >= 1024) return round_to_precision(size / 1024, 0.01) + ' KiB';
+ return size + ' B';
+}
+
+function getDate(date)
+{
+ let dateObj = new Date(date * 1000);
+ let m = dateObj.getUTCMonth() + 1;
+ let d = dateObj.getUTCDate();
+ let mm;
+ let dd;
+ if (m < 10) mm = '0' + m
+ else mm = m;
+ if (d < 10) dd = '0' + d
+ else dd = d;
+ return dateObj.getUTCFullYear() + '-' + mm + '-' + dd;
+}
+
+function getCategory(cat)
+{
+ let category = "";
+
+ if (cat > 100 && cat < 200)
+ {
+ category = "audio";
+ } else if (cat > 200 && cat < 300) {
+ category = "video";
+ } else if (cat > 300 && cat < 400) {
+ category = "apps";
+ } else if (cat > 400 && cat < 500) {
+ category = "games";
+ } else if (cat > 500 && cat < 600) {
+ category = "porn";
+ } else {
+ category = "other";
+ }
+
+ let subcategory = {
+ 101: 'music',
+ 102: 'audio books',
+ 103: 'sound clips',
+ 104: 'flac',
+ 199: 'other',
+ 201: 'movies',
+ 202: 'movies dvdr',
+ 203: 'music videos',
+ 204: 'movie clips',
+ 205: 'tv-shows',
+ 206: 'handheld',
+ 207: 'hd movies',
+ 208: 'hd tv-shows',
+ 209: '3d',
+ 299: 'other',
+ 301: 'windows',
+ 302: 'mac/apple',
+ 303: 'unix',
+ 304: 'handheld',
+ 305: 'ios(ipad/iphone)',
+ 306: 'android',
+ 399: 'other os',
+ 401: 'pc',
+ 402: 'mac/apple',
+ 403: 'psx',
+ 404: 'xbox360',
+ 405: 'wii',
+ 406: 'handheld',
+ 407: 'ios(ipad/iphone)',
+ 408: 'android',
+ 499: 'other os',
+ 501: 'movies',
+ 502: 'movies dvdr',
+ 503: 'pictures',
+ 504: 'games',
+ 505: 'hd movies',
+ 506: 'movie clips',
+ 599: 'other',
+ 601: 'e-books',
+ 602: 'comics',
+ 603: 'pictures',
+ 604: 'covers',
+ 605: 'physibles',
+ 699: 'other'
+ }[cat];
+
+ return category + " / " + ((subcategory) ? subcategory : "unavailable");
+}
+
+module.exports = {makeMagnet, bytesToSize, getDate, getCategory}; \ No newline at end of file