mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
return streaming url when in browser for RD and PM
This commit is contained in:
@@ -89,17 +89,12 @@ async function getFolderContents(PM, itemId, ip, folderPrefix = '') {
|
|||||||
.concat(otherContents)));
|
.concat(otherContents)));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
async function resolve({ ip, isBrowser, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
||||||
console.log(`Unrestricting Premiumize ${infoHash} [${fileIndex}] for IP ${ip}`);
|
console.log(`Unrestricting Premiumize ${infoHash} [${fileIndex}] for IP ${ip}`);
|
||||||
const options = await getDefaultOptions();
|
const options = await getDefaultOptions();
|
||||||
const PM = new PremiumizeClient(apiKey, options);
|
const PM = new PremiumizeClient(apiKey, options);
|
||||||
|
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)
|
||||||
const cachedLink = await _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip).catch(() => undefined);
|
.catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser))
|
||||||
if (cachedLink) {
|
|
||||||
return cachedLink;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip)
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.message && error.message.includes('purchase')) {
|
if (error && error.message && error.message.includes('purchase')) {
|
||||||
console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`);
|
console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`);
|
||||||
@@ -109,10 +104,10 @@ async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip) {
|
async function _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser) {
|
||||||
const torrent = await _createOrFindTorrent(PM, infoHash);
|
const torrent = await _createOrFindTorrent(PM, infoHash);
|
||||||
if (torrent && statusReady(torrent.status)) {
|
if (torrent && statusReady(torrent.status)) {
|
||||||
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip);
|
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser);
|
||||||
} else if (torrent && statusDownloading(torrent.status)) {
|
} else if (torrent && statusDownloading(torrent.status)) {
|
||||||
console.log(`Downloading to Premiumize ${infoHash} [${fileIndex}]...`);
|
console.log(`Downloading to Premiumize ${infoHash} [${fileIndex}]...`);
|
||||||
return StaticResponse.DOWNLOADING;
|
return StaticResponse.DOWNLOADING;
|
||||||
@@ -123,7 +118,7 @@ async function _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip) {
|
|||||||
return Promise.reject(`Failed Premiumize adding torrent ${JSON.stringify(torrent)}`);
|
return Promise.reject(`Failed Premiumize adding torrent ${JSON.stringify(torrent)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getCachedLink(PM, infoHash, encodedFileName, fileIndex, ip) {
|
async function _getCachedLink(PM, infoHash, encodedFileName, fileIndex, ip, isBrowser) {
|
||||||
const cachedTorrent = await PM.transfer.directDownload(magnet.encode({ infoHash }), ip);
|
const cachedTorrent = await PM.transfer.directDownload(magnet.encode({ infoHash }), ip);
|
||||||
if (cachedTorrent && cachedTorrent.content && cachedTorrent.content.length) {
|
if (cachedTorrent && cachedTorrent.content && cachedTorrent.content.length) {
|
||||||
const targetFileName = decodeURIComponent(encodedFileName);
|
const targetFileName = decodeURIComponent(encodedFileName);
|
||||||
@@ -131,7 +126,7 @@ async function _getCachedLink(PM, infoHash, encodedFileName, fileIndex, ip) {
|
|||||||
const targetVideo = Number.isInteger(fileIndex)
|
const targetVideo = Number.isInteger(fileIndex)
|
||||||
? videos.find(video => video.path.includes(targetFileName))
|
? videos.find(video => video.path.includes(targetFileName))
|
||||||
: videos.sort((a, b) => b.size - a.size)[0];
|
: videos.sort((a, b) => b.size - a.size)[0];
|
||||||
const unrestrictedLink = targetVideo.link || targetVideo.stream_link;
|
const unrestrictedLink = isBrowser && targetVideo.stream_link || targetVideo.link;
|
||||||
console.log(`Unrestricted Premiumize ${infoHash} [${fileIndex}] to ${unrestrictedLink}`);
|
console.log(`Unrestricted Premiumize ${infoHash} [${fileIndex}] to ${unrestrictedLink}`);
|
||||||
return unrestrictedLink;
|
return unrestrictedLink;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,12 +142,12 @@ async function getItemMeta(itemId, apiKey, ip) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
async function resolve({ ip, isBrowser, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
||||||
console.log(`Unrestricting RealDebrid ${infoHash} [${fileIndex}]`);
|
console.log(`Unrestricting RealDebrid ${infoHash} [${fileIndex}]`);
|
||||||
const options = await getDefaultOptions(ip);
|
const options = await getDefaultOptions(ip);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
|
|
||||||
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex)
|
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex, isBrowser)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (accessDeniedError(error)) {
|
if (accessDeniedError(error)) {
|
||||||
console.log(`Access denied to RealDebrid ${infoHash} [${fileIndex}]`);
|
console.log(`Access denied to RealDebrid ${infoHash} [${fileIndex}]`);
|
||||||
@@ -157,11 +157,11 @@ async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _resolve(RD, infoHash, cachedEntryInfo, fileIndex) {
|
async function _resolve(RD, infoHash, cachedEntryInfo, fileIndex, isBrowser) {
|
||||||
const torrentId = await _createOrFindTorrentId(RD, infoHash, cachedEntryInfo, fileIndex);
|
const torrentId = await _createOrFindTorrentId(RD, infoHash, cachedEntryInfo, fileIndex);
|
||||||
const torrent = await _getTorrentInfo(RD, torrentId);
|
const torrent = await _getTorrentInfo(RD, torrentId);
|
||||||
if (torrent && statusReady(torrent.status)) {
|
if (torrent && statusReady(torrent.status)) {
|
||||||
return _unrestrictLink(RD, torrent, fileIndex);
|
return _unrestrictLink(RD, torrent, fileIndex, isBrowser);
|
||||||
} else if (torrent && statusDownloading(torrent.status)) {
|
} else if (torrent && statusDownloading(torrent.status)) {
|
||||||
console.log(`Downloading to RealDebrid ${infoHash} [${fileIndex}]...`);
|
console.log(`Downloading to RealDebrid ${infoHash} [${fileIndex}]...`);
|
||||||
return StaticResponse.DOWNLOADING;
|
return StaticResponse.DOWNLOADING;
|
||||||
@@ -261,7 +261,7 @@ async function _openTorrent(RD, torrentId, pollCounter = 0, pollRate = 2000, max
|
|||||||
: torrent);
|
: torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _unrestrictLink(RD, torrent, fileIndex) {
|
async function _unrestrictLink(RD, torrent, fileIndex, isBrowser) {
|
||||||
const targetFile = torrent.files.find(file => file.id === fileIndex + 1)
|
const targetFile = torrent.files.find(file => file.id === fileIndex + 1)
|
||||||
|| torrent.files.filter(file => file.selected).sort((a, b) => b.bytes - a.bytes)[0];
|
|| torrent.files.filter(file => file.selected).sort((a, b) => b.bytes - a.bytes)[0];
|
||||||
if (!targetFile.selected) {
|
if (!targetFile.selected) {
|
||||||
@@ -279,16 +279,22 @@ async function _unrestrictLink(RD, torrent, fileIndex) {
|
|||||||
return Promise.reject(`No RealDebrid links found for ${torrent.hash} [${fileIndex}]`);
|
return Promise.reject(`No RealDebrid links found for ${torrent.hash} [${fileIndex}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _unrestrictFileLink(RD, fileLink, torrent, fileIndex);
|
return _unrestrictFileLink(RD, fileLink, torrent, fileIndex, isBrowser);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _unrestrictFileLink(RD, fileLink, torrent, fileIndex) {
|
async function _unrestrictFileLink(RD, fileLink, torrent, fileIndex, isBrowser) {
|
||||||
return RD.unrestrict.link(fileLink)
|
return RD.unrestrict.link(fileLink)
|
||||||
.then(response => response.download)
|
.then(response => {
|
||||||
.then(unrestrictedLink => {
|
if (isArchive(response.download)) {
|
||||||
if (isArchive(unrestrictedLink)) {
|
|
||||||
return StaticResponse.FAILED_RAR;
|
return StaticResponse.FAILED_RAR;
|
||||||
}
|
}
|
||||||
|
if (isBrowser && response.streamable) {
|
||||||
|
return RD.streaming.transcode(response.id)
|
||||||
|
.then(streamResponse => streamResponse.apple.full)
|
||||||
|
}
|
||||||
|
return response.download;
|
||||||
|
})
|
||||||
|
.then(unrestrictedLink => {
|
||||||
console.log(`Unrestricted RealDebrid ${torrent.hash} [${fileIndex}] to ${unrestrictedLink}`);
|
console.log(`Unrestricted RealDebrid ${torrent.hash} [${fileIndex}] to ${unrestrictedLink}`);
|
||||||
return unrestrictedLink;
|
return unrestrictedLink;
|
||||||
})
|
})
|
||||||
|
|||||||
3463
addon/package-lock.json
generated
3463
addon/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
|||||||
"request-ip": "^2.1.3",
|
"request-ip": "^2.1.3",
|
||||||
"sequelize": "^4.43.0",
|
"sequelize": "^4.43.0",
|
||||||
"stremio-addon-sdk": "^1.6.1",
|
"stremio-addon-sdk": "^1.6.1",
|
||||||
|
"ua-parser-js": "^1.0.2",
|
||||||
"user-agents": "^1.0.559"
|
"user-agents": "^1.0.559"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const rateLimit = require('express-rate-limit');
|
const rateLimit = require('express-rate-limit');
|
||||||
const { getRouter } = require('stremio-addon-sdk');
|
const { getRouter } = require('stremio-addon-sdk');
|
||||||
const requestIp = require('request-ip');
|
const requestIp = require('request-ip');
|
||||||
|
const userAgentParser = require('ua-parser-js');
|
||||||
const addonInterface = require('./addon');
|
const addonInterface = require('./addon');
|
||||||
const qs = require('querystring')
|
const qs = require('querystring')
|
||||||
const { manifest } = require('./lib/manifest');
|
const { manifest } = require('./lib/manifest');
|
||||||
@@ -78,13 +79,15 @@ router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next)
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:moch/:apiKey/:infoHash/:cachedEntryInfo/:fileIndex/:filename?', (req, res) => {
|
router.get('/:moch/:apiKey/:infoHash/:cachedEntryInfo/:fileIndex/:filename?', (req, res) => {
|
||||||
|
const userAgent = req.headers['user-agent'] || '';
|
||||||
const parameters = {
|
const parameters = {
|
||||||
mochKey: req.params.moch,
|
mochKey: req.params.moch,
|
||||||
apiKey: req.params.apiKey,
|
apiKey: req.params.apiKey,
|
||||||
infoHash: req.params.infoHash.toLowerCase(),
|
infoHash: req.params.infoHash.toLowerCase(),
|
||||||
fileIndex: isNaN(req.params.fileIndex) ? undefined : parseInt(req.params.fileIndex),
|
fileIndex: isNaN(req.params.fileIndex) ? undefined : parseInt(req.params.fileIndex),
|
||||||
cachedEntryInfo: req.params.cachedEntryInfo,
|
cachedEntryInfo: req.params.cachedEntryInfo,
|
||||||
ip: requestIp.getClientIp(req)
|
ip: requestIp.getClientIp(req),
|
||||||
|
isBrowser: !userAgent.includes('Stremio') && !!userAgentParser(userAgent).browser.name
|
||||||
}
|
}
|
||||||
moch.resolve(parameters)
|
moch.resolve(parameters)
|
||||||
.then(url => {
|
.then(url => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const nameToImdb = require('name-to-imdb');
|
const nameToImdb = require('name-to-imdb');
|
||||||
const googleIt = require('google-it');
|
|
||||||
const googleSr = require('google-sr');
|
const googleSr = require('google-sr');
|
||||||
const he = require('he');
|
const he = require('he');
|
||||||
const { cacheWrapImdbId, cacheWrapKitsuId, cacheWrapMetadata } = require('./cache');
|
const { cacheWrapImdbId, cacheWrapKitsuId, cacheWrapMetadata } = require('./cache');
|
||||||
@@ -109,8 +108,6 @@ async function getImdbId(info, type) {
|
|||||||
reject(err || new Error('failed imdbId search'));
|
reject(err || new Error('failed imdbId search'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// }).catch(() => googleIt({ query, userAgent: getRandomUserAgent(), disableConsole: true })
|
|
||||||
// .then(results => results.length ? results : Promise.reject('No results'))
|
|
||||||
}).catch(() => googleSr(query)
|
}).catch(() => googleSr(query)
|
||||||
.then(response => response.searchResults.length ? response.searchResults : Promise.reject('No results'))
|
.then(response => response.searchResults.length ? response.searchResults : Promise.reject('No results'))
|
||||||
.then(results => results
|
.then(results => results
|
||||||
|
|||||||
Reference in New Issue
Block a user