yifysubtitles
Advanced tools
Comparing version
41
index.js
@@ -8,5 +8,8 @@ const fs = require('fs'); | ||
const srt2vtt = require('srt-to-vtt'); | ||
const cheerio = require('cheerio'); | ||
const langsFormat = require('./langs'); | ||
const apiUri = 'http://api.yifysubtitles.com/subs'; | ||
const uri = 'http://www.yifysubtitles.com/movie-imdb'; | ||
const downloadUri = 'http://yifysubtitles.com'; | ||
@@ -19,18 +22,27 @@ const langK = Object.keys(langsFormat); | ||
const apiCall = imdbId => { | ||
return got(`${apiUri}/${imdbId}`, {json: true}) | ||
.then(res => ( | ||
(res.body.subtitles === 0) ? | ||
Promise.resolve({}) : | ||
res.body | ||
)); | ||
// Since yifysubtitle api is not working anymore we scrape the site instead | ||
const scrape = imdbId => { | ||
return got(`${uri}/${imdbId}`) | ||
.then(res => cheerio.load(res.body)) | ||
.then($ => { | ||
return $('tbody tr').map((i, el) => { | ||
const $el = $(el); | ||
return { | ||
rating: $el.find('.rating-cell').text(), | ||
language: $el.find('.flag-cell .sub-lang').text().toLowerCase(), | ||
url: $el.find('.download-cell a').attr('href').replace('subtitles/', 'subtitle/') + '.zip' | ||
}; | ||
}).get(); | ||
}) | ||
}; | ||
const langFilter = (subs, langs) => { | ||
return Object.keys(subs).reduce((acc, apiLang) => { | ||
if (langs.some(userLang => userLang === apiLang)) { | ||
acc[apiLang] = subs[apiLang].sort((a, b) => b.rating - a.rating)[0]; | ||
const data = langs.reduce((acc, l) => { | ||
const lang = subs.filter(s => s.language === l).sort((a, b) => b.rating - a.rating); | ||
if (lang.length) { | ||
acc[l] = lang[0]; | ||
} | ||
return acc; | ||
}, {}); | ||
return data | ||
}; | ||
@@ -66,6 +78,3 @@ | ||
const runConditional = (imdbId, opts, res) => { | ||
if (!res.success) { | ||
return Promise.reject(res.message); | ||
} | ||
return Promise.resolve(langFilter(res.subs[imdbId], opts.langs.map(formatLangLong))) | ||
return Promise.resolve(langFilter(res, opts.langs.map(formatLangLong))) | ||
.then(res => downloads(res, opts)); | ||
@@ -87,6 +96,6 @@ }; | ||
return apiCall(imdbId) | ||
.then(res => Object.keys(res).length ? runConditional(imdbId, opts, res) : []); | ||
return scrape(imdbId) | ||
.then(res => res.length ? runConditional(imdbId, opts, res) : []); | ||
}; | ||
module.exports = yifysubtitles; |
{ | ||
"name": "yifysubtitles", | ||
"version": "2.0.1", | ||
"description": "A simple wrapper to download subtitles from yifysubtitles api.", | ||
"version": "2.0.2", | ||
"description": "A simple wrapper to download subtitles from the yifysubtitles website.", | ||
"license": "MIT", | ||
@@ -23,8 +23,9 @@ "repository": { | ||
"dependencies": { | ||
"cheerio": "^0.22.0", | ||
"global": "^4.3.1", | ||
"got": "^6.6.3", | ||
"p-map": "^1.1.0", | ||
"srt-to-vtt": "^1.1.1", | ||
"streamz": "^1.6.2", | ||
"unzipper": "^0.7.2", | ||
"p-map": "^1.1.0" | ||
"unzipper": "^0.7.2" | ||
}, | ||
@@ -31,0 +32,0 @@ "devDependencies": { |
@@ -5,3 +5,3 @@ [](https://github.com/sindresorhus/xo) | ||
# yifysubtitles | ||
> Search, download and convert subtitles in [VTT format](https://developer.mozilla.org/en/docs/Web/API/Web_Video_Text_Tracks_Format) for [YTS movies](https://yts.ag/) | ||
> Download and convert subtitles in [VTT format](https://developer.mozilla.org/en/docs/Web/API/Web_Video_Text_Tracks_Format) for [YTS movies](https://yts.ag/) | ||
@@ -8,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
123647
4.21%167
5.03%7
16.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added