Skip to content

Commit

Permalink
Migrate from coffee to es6
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Mar 18, 2016
1 parent 180ac2a commit 477d257
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

import rp from 'request-promise';
import cheerio from 'cheerio';

const searchAnime = (keyword) => {
const options = {
uri: `http://jkanime.net/buscar/${keyword}`,
transform: cheerio.load,
headers: {'User-Agent': 'anime-dl'}
};
return rp(options)
.then($ => {
return $('.listpage .titl').map(function() {
return {
url: $(this).attr('href'),
name: $(this).text()
};
}).get();
});
};

const getUrlVideo = (uri) => {
const validRegex = /http:\/\/jkanime\.net\/([\w\d-_]+)\/(\d+)/;
const options = {
uri: uri,
transform: cheerio.load,
headers: {'User-Agent': 'anime-dl'}
};
return rp(options)
.then($ => {
if (!validRegex.test(uri)) return null;
const title = $('.vervideo').text().split(' - ')[0];
const [codeName, chapter] = validRegex.exec(uri).slice(1, 3);
const regex = /https:\/\/jkanime\.net\/jk\.php\?u=stream\/jkmedia\/([0-9a-f]{32}\/[0-9a-f]{32}\/1\/[0-9a-f]{32})\//;
const urls = $('.player_conte').map(function() {
return $(this).attr('src');
}).get().filter(x => regex.test(x)).map(x => `http://jkanime.net/stream/jkmedia/${regex.exec(x)[1]}/`);
return {title: title, codeName: codeName, chapter: chapter, urls: urls};
});
};

module.exports = {
searchAnime: searchAnime,
getUrlVideo: getUrlVideo
};

0 comments on commit 477d257

Please sign in to comment.