Skip to content

Commit 477d257

Browse files
committed
Migrate from coffee to es6
1 parent 180ac2a commit 477d257

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/index.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
import rp from 'request-promise';
4+
import cheerio from 'cheerio';
5+
6+
const searchAnime = (keyword) => {
7+
const options = {
8+
uri: `http://jkanime.net/buscar/${keyword}`,
9+
transform: cheerio.load,
10+
headers: {'User-Agent': 'anime-dl'}
11+
};
12+
return rp(options)
13+
.then($ => {
14+
return $('.listpage .titl').map(function() {
15+
return {
16+
url: $(this).attr('href'),
17+
name: $(this).text()
18+
};
19+
}).get();
20+
});
21+
};
22+
23+
const getUrlVideo = (uri) => {
24+
const validRegex = /http:\/\/jkanime\.net\/([\w\d-_]+)\/(\d+)/;
25+
const options = {
26+
uri: uri,
27+
transform: cheerio.load,
28+
headers: {'User-Agent': 'anime-dl'}
29+
};
30+
return rp(options)
31+
.then($ => {
32+
if (!validRegex.test(uri)) return null;
33+
const title = $('.vervideo').text().split(' - ')[0];
34+
const [codeName, chapter] = validRegex.exec(uri).slice(1, 3);
35+
const regex = /https:\/\/jkanime\.net\/jk\.php\?u=stream\/jkmedia\/([0-9a-f]{32}\/[0-9a-f]{32}\/1\/[0-9a-f]{32})\//;
36+
const urls = $('.player_conte').map(function() {
37+
return $(this).attr('src');
38+
}).get().filter(x => regex.test(x)).map(x => `http://jkanime.net/stream/jkmedia/${regex.exec(x)[1]}/`);
39+
return {title: title, codeName: codeName, chapter: chapter, urls: urls};
40+
});
41+
};
42+
43+
module.exports = {
44+
searchAnime: searchAnime,
45+
getUrlVideo: getUrlVideo
46+
};

0 commit comments

Comments
 (0)