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)));
|
||||
}
|
||||
|
||||
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}`);
|
||||
const options = await getDefaultOptions();
|
||||
const PM = new PremiumizeClient(apiKey, options);
|
||||
|
||||
const cachedLink = await _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip).catch(() => undefined);
|
||||
if (cachedLink) {
|
||||
return cachedLink;
|
||||
}
|
||||
|
||||
return _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip)
|
||||
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)
|
||||
.catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser))
|
||||
.catch(error => {
|
||||
if (error && error.message && error.message.includes('purchase')) {
|
||||
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);
|
||||
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)) {
|
||||
console.log(`Downloading to Premiumize ${infoHash} [${fileIndex}]...`);
|
||||
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)}`);
|
||||
}
|
||||
|
||||
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);
|
||||
if (cachedTorrent && cachedTorrent.content && cachedTorrent.content.length) {
|
||||
const targetFileName = decodeURIComponent(encodedFileName);
|
||||
@@ -131,7 +126,7 @@ async function _getCachedLink(PM, infoHash, encodedFileName, fileIndex, ip) {
|
||||
const targetVideo = Number.isInteger(fileIndex)
|
||||
? videos.find(video => video.path.includes(targetFileName))
|
||||
: 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}`);
|
||||
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}]`);
|
||||
const options = await getDefaultOptions(ip);
|
||||
const RD = new RealDebridClient(apiKey, options);
|
||||
|
||||
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex)
|
||||
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex, isBrowser)
|
||||
.catch(error => {
|
||||
if (accessDeniedError(error)) {
|
||||
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 torrent = await _getTorrentInfo(RD, torrentId);
|
||||
if (torrent && statusReady(torrent.status)) {
|
||||
return _unrestrictLink(RD, torrent, fileIndex);
|
||||
return _unrestrictLink(RD, torrent, fileIndex, isBrowser);
|
||||
} else if (torrent && statusDownloading(torrent.status)) {
|
||||
console.log(`Downloading to RealDebrid ${infoHash} [${fileIndex}]...`);
|
||||
return StaticResponse.DOWNLOADING;
|
||||
@@ -261,7 +261,7 @@ async function _openTorrent(RD, torrentId, pollCounter = 0, pollRate = 2000, max
|
||||
: torrent);
|
||||
}
|
||||
|
||||
async function _unrestrictLink(RD, torrent, fileIndex) {
|
||||
async function _unrestrictLink(RD, torrent, fileIndex, isBrowser) {
|
||||
const targetFile = torrent.files.find(file => file.id === fileIndex + 1)
|
||||
|| torrent.files.filter(file => file.selected).sort((a, b) => b.bytes - a.bytes)[0];
|
||||
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 _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)
|
||||
.then(response => response.download)
|
||||
.then(unrestrictedLink => {
|
||||
if (isArchive(unrestrictedLink)) {
|
||||
.then(response => {
|
||||
if (isArchive(response.download)) {
|
||||
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}`);
|
||||
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",
|
||||
"sequelize": "^4.43.0",
|
||||
"stremio-addon-sdk": "^1.6.1",
|
||||
"ua-parser-js": "^1.0.2",
|
||||
"user-agents": "^1.0.559"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const rateLimit = require('express-rate-limit');
|
||||
const { getRouter } = require('stremio-addon-sdk');
|
||||
const requestIp = require('request-ip');
|
||||
const userAgentParser = require('ua-parser-js');
|
||||
const addonInterface = require('./addon');
|
||||
const qs = require('querystring')
|
||||
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) => {
|
||||
const userAgent = req.headers['user-agent'] || '';
|
||||
const parameters = {
|
||||
mochKey: req.params.moch,
|
||||
apiKey: req.params.apiKey,
|
||||
infoHash: req.params.infoHash.toLowerCase(),
|
||||
fileIndex: isNaN(req.params.fileIndex) ? undefined : parseInt(req.params.fileIndex),
|
||||
cachedEntryInfo: req.params.cachedEntryInfo,
|
||||
ip: requestIp.getClientIp(req)
|
||||
ip: requestIp.getClientIp(req),
|
||||
isBrowser: !userAgent.includes('Stremio') && !!userAgentParser(userAgent).browser.name
|
||||
}
|
||||
moch.resolve(parameters)
|
||||
.then(url => {
|
||||
|
||||
Reference in New Issue
Block a user