Skip to content

Commit

Permalink
downloadLinksByEpsId(:[epsId]) function implemented as part of the an…
Browse files Browse the repository at this point in the history
…imeflv api.
  • Loading branch information
ChrisMichaelPerezSantiago committed Feb 8, 2020
1 parent 12d47f7 commit 659494d
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/api/api.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
const cheerio = require('cheerio');
const cheerioTableparser = require('cheerio-tableparser');
const cloudscraper = require('cloudscraper');
const {MergeRecursive} = require('../utils/index');
const {MergeRecursive , urlify} = require('../utils/index');
const {
BASE_URL , SEARCH_URL , BROWSE_URL ,
ANIME_VIDEO_URL , BASE_EPISODE_IMG_URL ,
BASE_JIKA_URL , BASE_MYANIME_LIST_URL
} = require('./urls');


const downloadLinksByEpsId = async(id) =>{
const res = await cloudscraper.get(`${ANIME_VIDEO_URL}${id}`);
const body = await res;
const $ = cheerio.load(body);
cheerioTableparser($);
let tempServerNames = $('table.RTbl').parsetable(true , true , true)[0];
let serverNames = tempServerNames.filter(x => x !== 'SERVIDOR');
let urls = [];

try{
const table = $('table.RTbl').html();
const data = await urlify(table).then(res => { return res; });
const tempUrls = [];
data.map(baseUrl =>{
let url = baseUrl.split('"')[0];
tempUrls.push(url)
});

Array.from({length: tempUrls.length} , (v , k) =>{
urls.push({
server: serverNames[k],
url: tempUrls[k],
});
});

}catch(err){
console.log(err);
}

return Promise.all(urls);
};

const getAnimeChapterTitlesHelper = async(title) =>{
const res = await cloudscraper.get(`${BASE_JIKA_URL}${title}`);
const matchAnime = JSON.parse(res).results.filter(x => x.title === title);
Expand Down Expand Up @@ -557,5 +590,6 @@ module.exports = {
special,
ova,
tv,
getAnimeInfo
getAnimeInfo,
downloadLinksByEpsId
};

0 comments on commit 659494d

Please sign in to comment.