mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] show rar error static response for alldebrid
This commit is contained in:
72
addon/lib/extension.js
Normal file
72
addon/lib/extension.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
const VIDEO_EXTENSIONS = [
|
||||||
|
"3g2",
|
||||||
|
"3gp",
|
||||||
|
"avi",
|
||||||
|
"flv",
|
||||||
|
"mkv",
|
||||||
|
"mk3d",
|
||||||
|
"mov",
|
||||||
|
"mp2",
|
||||||
|
"mp4",
|
||||||
|
"m4v",
|
||||||
|
"mpe",
|
||||||
|
"mpeg",
|
||||||
|
"mpg",
|
||||||
|
"mpv",
|
||||||
|
"webm",
|
||||||
|
"wmv",
|
||||||
|
"ogm"
|
||||||
|
];
|
||||||
|
const SUBTITLE_EXTENSIONS = [
|
||||||
|
"aqt",
|
||||||
|
"gsub",
|
||||||
|
"jss",
|
||||||
|
"sub",
|
||||||
|
"ttxt",
|
||||||
|
"pjs",
|
||||||
|
"psb",
|
||||||
|
"rt",
|
||||||
|
"smi",
|
||||||
|
"slt",
|
||||||
|
"ssf",
|
||||||
|
"srt",
|
||||||
|
"ssa",
|
||||||
|
"ass",
|
||||||
|
"usf",
|
||||||
|
"idx",
|
||||||
|
"vtt"
|
||||||
|
];
|
||||||
|
const DISK_EXTENSIONS = [
|
||||||
|
"iso",
|
||||||
|
"m2ts",
|
||||||
|
"ts",
|
||||||
|
"vob"
|
||||||
|
]
|
||||||
|
|
||||||
|
const ARCHIVE_EXTENSIONS = [
|
||||||
|
"rar",
|
||||||
|
"zip"
|
||||||
|
]
|
||||||
|
|
||||||
|
function isVideo(filename) {
|
||||||
|
return isExtension(filename, VIDEO_EXTENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSubtitle(filename) {
|
||||||
|
return isExtension(filename, SUBTITLE_EXTENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDisk(filename) {
|
||||||
|
return isExtension(filename, DISK_EXTENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isArchive(filename) {
|
||||||
|
return isExtension(filename, ARCHIVE_EXTENSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isExtension(filename, extensions) {
|
||||||
|
const extensionMatch = filename.match(/\.(\w{2,4})$/);
|
||||||
|
return extensionMatch && extensions.includes(extensionMatch[1].toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { isVideo, isSubtitle, isDisk, isArchive }
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const EXTENSIONS = [
|
|
||||||
"3g2",
|
|
||||||
"3gp",
|
|
||||||
"avi",
|
|
||||||
"flv",
|
|
||||||
"mkv",
|
|
||||||
"mov",
|
|
||||||
"mp2",
|
|
||||||
"mp4",
|
|
||||||
"m4v",
|
|
||||||
"mpe",
|
|
||||||
"mpeg",
|
|
||||||
"mpg",
|
|
||||||
"mpv",
|
|
||||||
"webm",
|
|
||||||
"wmv",
|
|
||||||
"ogm"
|
|
||||||
];
|
|
||||||
|
|
||||||
module.exports = (filename) => {
|
|
||||||
const extensionMatch = filename.match(/\.(\w{2,4})$/);
|
|
||||||
return extensionMatch && EXTENSIONS.includes(extensionMatch[1].toLowerCase());
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const AllDebridClient = require('all-debrid-api');
|
const AllDebridClient = require('all-debrid-api');
|
||||||
const isVideo = require('../lib/video');
|
const { isVideo, isArchive } = require('../lib/extension');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
||||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
||||||
@@ -86,6 +86,10 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
|
|||||||
? videos.find(video => targetFileName.includes(video.filename))
|
? videos.find(video => targetFileName.includes(video.filename))
|
||||||
: videos.sort((a, b) => b.size - a.size)[0];
|
: videos.sort((a, b) => b.size - a.size)[0];
|
||||||
|
|
||||||
|
if (!targetVideo && torrent.links.every(link => isArchive(link.filename))) {
|
||||||
|
console.log(`Only AllDebrid archive is available for [${torrent.hash}] ${encodedFileName}`)
|
||||||
|
return StaticResponse.FAILED_RAR;
|
||||||
|
}
|
||||||
if (!targetVideo || !targetVideo.link || !targetVideo.link.length) {
|
if (!targetVideo || !targetVideo.link || !targetVideo.link.length) {
|
||||||
return Promise.reject(`No AllDebrid links found for [${torrent.hash}] ${encodedFileName}`);
|
return Promise.reject(`No AllDebrid links found for [${torrent.hash}] ${encodedFileName}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const PremiumizeClient = require('premiumize-api');
|
const PremiumizeClient = require('premiumize-api');
|
||||||
const { encode } = require('magnet-uri');
|
const { encode } = require('magnet-uri');
|
||||||
const isVideo = require('../lib/video');
|
const { isVideo } = require('../lib/extension');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
||||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const PutioAPI = require('@putdotio/api-client').default
|
const PutioAPI = require('@putdotio/api-client').default
|
||||||
const { encode } = require('magnet-uri');
|
const { encode } = require('magnet-uri');
|
||||||
const isVideo = require('../lib/video');
|
const { isVideo } = require('../lib/extension');
|
||||||
const delay = require('./delay');
|
const delay = require('./delay');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const RealDebridClient = require('real-debrid-api');
|
const RealDebridClient = require('real-debrid-api');
|
||||||
const { encode } = require('magnet-uri');
|
const { encode } = require('magnet-uri');
|
||||||
const isVideo = require('../lib/video');
|
const { isVideo, isArchive } = require('../lib/extension');
|
||||||
const delay = require('./delay');
|
const delay = require('./delay');
|
||||||
const StaticResponse = require('./static');
|
const StaticResponse = require('./static');
|
||||||
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
|
||||||
@@ -146,7 +146,7 @@ async function _unrestrictLink(RD, torrent, fileIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const unrestrictedLink = await RD.unrestrict.link(fileLink).then(response => response.download);
|
const unrestrictedLink = await RD.unrestrict.link(fileLink).then(response => response.download);
|
||||||
if (!isVideo(unrestrictedLink)) {
|
if (isArchive(unrestrictedLink)) {
|
||||||
return StaticResponse.FAILED_RAR;
|
return StaticResponse.FAILED_RAR;
|
||||||
}
|
}
|
||||||
// const transcodedLink = await RD.streaming.transcode(unrestrictedLink.id);
|
// const transcodedLink = await RD.streaming.transcode(unrestrictedLink.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user