[addon] propagate ip to debrid catalog/meta requests

This commit is contained in:
TheBeastLT
2021-01-31 22:55:37 +01:00
parent d7313ecb91
commit 0a68bec37a
5 changed files with 12 additions and 14 deletions

View File

@@ -98,7 +98,7 @@ async function getMochCatalog(mochKey, config) {
return Promise.reject(`Invalid API key for moch provider: ${mochKey}`); return Promise.reject(`Invalid API key for moch provider: ${mochKey}`);
} }
return moch.instance.getCatalog(config[moch.key], config.skip); return moch.instance.getCatalog(config[moch.key], config.skip, config.ip);
} }
async function getMochItemMeta(mochKey, itemId, config) { async function getMochItemMeta(mochKey, itemId, config) {
@@ -107,7 +107,7 @@ async function getMochItemMeta(mochKey, itemId, config) {
return Promise.reject(`Not a valid moch provider: ${mochKey}`); return Promise.reject(`Not a valid moch provider: ${mochKey}`);
} }
return moch.instance.getItemMeta(itemId, config[moch.key]) return moch.instance.getItemMeta(itemId, config[moch.key], config.ip)
.then(meta => { .then(meta => {
meta.videos meta.videos
.map(video => video.streams) .map(video => video.streams)

View File

@@ -49,11 +49,11 @@ async function getCatalog(apiKey, offset = 0) {
}))); })));
} }
async function getItemMeta(itemId, apiKey) { async function getItemMeta(itemId, apiKey, ip) {
const options = await getDefaultOptions(apiKey); const options = await getDefaultOptions(apiKey);
const PM = new PremiumizeClient(apiKey, options); const PM = new PremiumizeClient(apiKey, options);
const rootFolder = await PM.folder.list(itemId, null); const rootFolder = await PM.folder.list(itemId, null);
return getFolderContents(PM, itemId) return getFolderContents(PM, itemId, ip)
.then(contents => ({ .then(contents => ({
id: `${KEY}:${itemId}`, id: `${KEY}:${itemId}`,
type: Type.OTHER, type: Type.OTHER,
@@ -85,7 +85,7 @@ async function getFolderContents(PM, itemId, ip, folderPrefix = '') {
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) { async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
console.log(`Unrestricting ${infoHash} [${fileIndex}] for IP ${ip}`); console.log(`Unrestricting ${infoHash} [${fileIndex}] for IP ${ip}`);
const options = await getDefaultOptions(apiKey, ip); const options = await getDefaultOptions(apiKey);
const PM = new PremiumizeClient(apiKey, options); const PM = new PremiumizeClient(apiKey, options);
const cachedLink = await _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip).catch(() => undefined); const cachedLink = await _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip).catch(() => undefined);
@@ -160,12 +160,10 @@ function statusReady(status) {
return ['finished', 'seeding'].includes(status); return ['finished', 'seeding'].includes(status);
} }
async function getDefaultOptions(id, ip) { async function getDefaultOptions(id) {
const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent()); const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent());
const proxy = await cacheWrapProxy('moch', () => getRandomProxy()).catch(() => getRandomProxy());
const agent = getProxyAgent(proxy);
return { timeout: 30000, agent: agent, headers: { 'User-Agent': userAgent } }; return { timeout: 30000, headers: { 'User-Agent': userAgent } };
} }
module.exports = { getCachedStreams, resolve, getCatalog, getItemMeta }; module.exports = { getCachedStreams, resolve, getCatalog, getItemMeta };

View File

@@ -1918,9 +1918,9 @@
"dev": true "dev": true
}, },
"premiumize-api": { "premiumize-api": {
"version": "1.0.2", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/premiumize-api/-/premiumize-api-1.0.2.tgz", "resolved": "https://registry.npmjs.org/premiumize-api/-/premiumize-api-1.0.3.tgz",
"integrity": "sha512-lp5AJ+0dP3wWH/UhciNvUW6OVXKJAj3uNXjN5TWlKIS62aEynlPaYWms7DnacwwZ1cFfJXY8RblBsUUja6p97w==", "integrity": "sha512-WwJhgmwrKrFFtfjU2EMAaYv602xbe52oaGEwVJXO3z0LZQZ8Cogk9MBADcT0hrFf8MuI7zn5cPMxcJRJPr9cMQ==",
"requires": { "requires": {
"request": "^2.83.0" "request": "^2.83.0"
} }

View File

@@ -21,7 +21,7 @@
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#3e3932737604f4a9215a6800f6c263bb2f92f1ce", "parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#3e3932737604f4a9215a6800f6c263bb2f92f1ce",
"pg": "^7.8.2", "pg": "^7.8.2",
"pg-hstore": "^2.3.2", "pg-hstore": "^2.3.2",
"premiumize-api": "^1.0.2", "premiumize-api": "^1.0.3",
"real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d", "real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d",
"request-ip": "^2.1.3", "request-ip": "^2.1.3",
"sequelize": "^4.43.0", "sequelize": "^4.43.0",

View File

@@ -39,7 +39,7 @@ router.get('/:configuration?/manifest.json', (req, res) => {
router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next) => { router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next) => {
const { configuration, resource, type, id } = req.params; const { configuration, resource, type, id } = req.params;
const extra = req.params.extra ? qs.parse(req.url.split('/').pop().slice(0, -5)) : {} const extra = req.params.extra ? qs.parse(req.url.split('/').pop().slice(0, -5)) : {}
const configValues = { ...extra, ...parseConfiguration(configuration) }; const configValues = { ...extra, ...parseConfiguration(configuration), ip: requestIp.getClientIp(req) };
addonInterface.get(resource, type, id, configValues) addonInterface.get(resource, type, id, configValues)
.then(resp => { .then(resp => {
const cacheHeaders = { const cacheHeaders = {