Skip to content
This repository was archived by the owner on Jun 14, 2021. It is now read-only.

Commit 6a41d92

Browse files
author
XiaoLin
committed
feat: support OneJAV
1 parent adac4d8 commit 6a41d92

File tree

5 files changed

+120
-4
lines changed

5 files changed

+120
-4
lines changed

config/dev.example.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"driver": "RSS",
88
"type": "MT",
99
"url": "https://pt.m-team.cc/torrentrss.php?https=1&rows=50&cat410=1&isize=1&search=-&search_mode=1&linktype=dl&passkey=yourkeyhere"
10+
},
11+
{
12+
"driver": "Onejav",
13+
"url": "https://onejav.com/popular/"
1014
}
1115
],
1216
"qbittorrent": {

package-lock.json

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"object-hash": "^2.0.3",
1616
"p-retry": "^4.2.0",
1717
"parse-torrent": "^7.0.1",
18-
"rss-parser": "^3.7.6"
18+
"rss-parser": "^3.7.6",
19+
"sha256": "^0.2.0"
1920
},
2021
"devDependencies": {},
2122
"scripts": {

src/pull/driver/onejav.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const logger = require('./../../module/logger')('Module: OneJAV')
2+
const domParser = require('dom-parser')
3+
const parser = new domParser()
4+
const fetch = require('node-fetch')
5+
const pRetry = require('p-retry')
6+
const sha256 = require('sha256')
7+
8+
class Onejav {
9+
constructor (url) {
10+
this._url = url
11+
}
12+
13+
async run () {
14+
const content = await this.fetchContent()
15+
16+
return await this.parseContent(content)
17+
}
18+
19+
async fetchContent () {
20+
logger.debug('Fetching', this._url)
21+
const content = await pRetry(async () => {
22+
const response = await fetch(this._url, {
23+
timeout: 10000
24+
})
25+
logger.debug('Status code:', response.status)
26+
if (response.status === 404 || response.status === 403) {
27+
throw new pRetry.AbortError(response.statusText)
28+
}
29+
30+
return response.text()
31+
}, {
32+
onFailedAttempt: error => {
33+
logger.warn(`Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`);
34+
},
35+
retries: 5
36+
})
37+
38+
const dom = await parser.parseFromString(content)
39+
if (!dom) throw new Error('Invalid HTML')
40+
41+
return dom
42+
}
43+
44+
parseContent (dom) {
45+
const cards = dom.getElementsByClassName('card-content')
46+
console.log(cards)
47+
const processed = []
48+
49+
for (const i in cards) {
50+
const card = cards[i]
51+
let JAVID = card.getElementsByTagName('a')[0]
52+
if (!JAVID) continue
53+
JAVID = JAVID.textContent
54+
JAVID = `${JAVID}`.replace(' ', '').replace('\n','').trim()
55+
JAVID = JAVID.replace(/([a-zA-Z]+)(\d+)/, '$1-$2')
56+
logger.debug('Get JAVID', JAVID)
57+
58+
let size = card.getElementsByClassName('is-size-6')[0]
59+
size = parseFloat(`${size.textContent}`.replace('GB', '').trim())
60+
logger.debug('Get size', size)
61+
62+
let torrentURL = card.getElementsByClassName('is-fullwidth')[0]
63+
torrentURL = 'https://onejav.com' + `${torrentURL.getAttribute('href')}`.trim()
64+
logger.debug('Get torrent URL', torrentURL)
65+
66+
const hash = sha256(torrentURL + size + JAVID)
67+
logger.debug('Get hash', hash)
68+
69+
processed.push({
70+
hash,
71+
JAVID: JAVID,
72+
size,
73+
torrentURL
74+
})
75+
}
76+
77+
logger.debug('Processed', processed)
78+
return processed
79+
}
80+
}
81+
82+
module.exports = Onejav

src/pull/init.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const contentHandler = async () => {
5656
logger.info(`Handling ${JAVID}, hash ${hash}`)
5757

5858
if (size > 10) {
59-
logger.info(`[${JAVID}] File oversize, skipped`)
59+
logger.info(`[${JAVID}] File oversized, skipped`)
6060
continue
6161
}
6262

@@ -143,6 +143,7 @@ runAndSetInterval(async () => {
143143
}, 60, 'Download queue', false)
144144

145145
const driverRSS = require('./driver/rss')
146+
const driverOnejav = require('./driver/onejav')
146147
const driverStack = []
147148

148149
const remoteList = config.get('remote')
@@ -160,5 +161,14 @@ for (const i in remoteList) {
160161
return res
161162
}, item.interval, 'RSS: ' + i)
162163
break
164+
165+
case 'OneJAV':
166+
logger.info(`[${i}] Creating OneJAV driver stack`)
167+
driverStack[i] = new driverOnejav(item.url)
168+
runAndSetInterval(async () => {
169+
const res = await driverStack[i].run()
170+
return res
171+
}, item.interval, 'OneJAV: ' + i)
172+
break
163173
}
164174
}

0 commit comments

Comments
 (0)