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)));
|
||||
}
|
||||
|
||||
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;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user