-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathanimetosho.js
More file actions
81 lines (66 loc) · 2.65 KB
/
animetosho.js
File metadata and controls
81 lines (66 loc) · 2.65 KB
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
import AbstractSource from './abstract.js'
const QUALITIES = ['1080', '720', '540', '480']
export default new class Tosho extends AbstractSource {
url = atob('aHR0cHM6Ly9mZWVkLmFuaW1ldG9zaG8ub3JnL2pzb24=')
buildQuery ({ resolution, exclusions }) {
const base = `&qx=1&q=!("${exclusions.join('"|"')}")`
if (!resolution) return base
const excl = QUALITIES.filter(q => q !== resolution)
return base + `!(*${excl.join('*|*')}*)`
}
/**
* @param {import('./types').Tosho[]} entries
* @param {boolean} batch
* @returns {import('./').TorrentResult[]}
**/
map (entries, batch = false) {
return entries.map(entry => {
return {
title: entry.title || entry.torrent_name,
link: entry.magnet_uri,
seeders: (entry.seeders || 0) >= 30000 ? 0 : entry.seeders || 0,
leechers: (entry.leechers || 0) >= 30000 ? 0 : entry.leechers || 0,
downloads: entry.torrent_downloaded_count || 0,
hash: entry.info_hash,
size: entry.total_size,
accuracy: entry.anidb_fid ? 'high' : 'medium',
type: batch ? 'batch' : undefined,
date: new Date(entry.timestamp * 1000)
}
})
}
/** @type {import('./').SearchFunction} */
async single ({ anidbEid, resolution, exclusions }) {
if (!anidbEid) throw new Error('No anidbEid provided')
const query = this.buildQuery({ resolution, exclusions })
const res = await fetch(this.url + '?eid=' + anidbEid + query)
/** @type {import('./types').Tosho[]} */
const data = await res.json()
if (data.length) return this.map(data)
return []
}
/** @type {import('./').SearchFunction} */
async batch ({ anidbAid, resolution, episodeCount, exclusions }) {
if (!anidbAid) throw new Error('No anidbAid provided')
if (episodeCount == null) throw new Error('No episodeCount provided')
const query = this.buildQuery({ resolution, exclusions })
const res = await fetch(this.url + '?order=size-d&aid=' + anidbAid + query)
const data = /** @type {import('./types').Tosho[]} */(await res.json()).filter(entry => entry.num_files >= episodeCount)
if (data.length) return this.map(data, true)
return []
}
/** @type {import('./').SearchFunction} */
async movie ({ anidbAid, resolution, exclusions }) {
if (!anidbAid) throw new Error('No anidbAid provided')
const query = this.buildQuery({ resolution, exclusions })
const res = await fetch(this.url + '?aid=' + anidbAid + query)
/** @type {import('./types').Tosho[]} */
const data = await res.json()
if (data.length) return this.map(data)
return []
}
async test () {
const res = await fetch(this.url)
return res.ok
}
}()