1 Commits

Author SHA1 Message Date
purple_emily
6181207513 Fix incorrect file index stored (#197)
* Fix incorrect file index stored

* Update `rank-torrent-name` to latest version

* Knight Crawler version update
2024-04-01 23:08:32 +01:00
13 changed files with 1133 additions and 1131 deletions

View File

@@ -94,7 +94,7 @@ services:
condition: service_healthy condition: service_healthy
env_file: stack.env env_file: stack.env
hostname: knightcrawler-addon hostname: knightcrawler-addon
image: gabisonfire/knightcrawler-addon:2.0.18 image: gabisonfire/knightcrawler-addon:2.0.19
labels: labels:
logging: promtail logging: promtail
networks: networks:
@@ -117,7 +117,7 @@ services:
redis: redis:
condition: service_healthy condition: service_healthy
env_file: stack.env env_file: stack.env
image: gabisonfire/knightcrawler-consumer:2.0.18 image: gabisonfire/knightcrawler-consumer:2.0.19
labels: labels:
logging: promtail logging: promtail
networks: networks:
@@ -138,7 +138,7 @@ services:
redis: redis:
condition: service_healthy condition: service_healthy
env_file: stack.env env_file: stack.env
image: gabisonfire/knightcrawler-debrid-collector:2.0.18 image: gabisonfire/knightcrawler-debrid-collector:2.0.19
labels: labels:
logging: promtail logging: promtail
networks: networks:
@@ -152,7 +152,7 @@ services:
migrator: migrator:
condition: service_completed_successfully condition: service_completed_successfully
env_file: stack.env env_file: stack.env
image: gabisonfire/knightcrawler-metadata:2.0.18 image: gabisonfire/knightcrawler-metadata:2.0.19
networks: networks:
- knightcrawler-network - knightcrawler-network
restart: "no" restart: "no"
@@ -163,7 +163,7 @@ services:
postgres: postgres:
condition: service_healthy condition: service_healthy
env_file: stack.env env_file: stack.env
image: gabisonfire/knightcrawler-migrator:2.0.18 image: gabisonfire/knightcrawler-migrator:2.0.19
networks: networks:
- knightcrawler-network - knightcrawler-network
restart: "no" restart: "no"
@@ -182,7 +182,7 @@ services:
redis: redis:
condition: service_healthy condition: service_healthy
env_file: stack.env env_file: stack.env
image: gabisonfire/knightcrawler-producer:2.0.18 image: gabisonfire/knightcrawler-producer:2.0.19
labels: labels:
logging: promtail logging: promtail
networks: networks:
@@ -207,7 +207,7 @@ services:
deploy: deploy:
replicas: ${QBIT_REPLICAS:-0} replicas: ${QBIT_REPLICAS:-0}
env_file: stack.env env_file: stack.env
image: gabisonfire/knightcrawler-qbit-collector:2.0.18 image: gabisonfire/knightcrawler-qbit-collector:2.0.19
labels: labels:
logging: promtail logging: promtail
networks: networks:

View File

@@ -27,7 +27,7 @@ export async function getCachedStreams(streams, apiKey) {
const fileName = streamTitleParts[streamTitleParts.length - 1]; const fileName = streamTitleParts[streamTitleParts.length - 1];
const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null; const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null;
const encodedFileName = encodeURIComponent(fileName); const encodedFileName = encodeURIComponent(fileName);
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = { mochStreams[stream.infoHash] = {
url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`, url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`,
cached: cachedEntry?.instant cached: cachedEntry?.instant
} }
@@ -142,10 +142,10 @@ async function _createTorrent(AD, infoHash) {
async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) { async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
const targetFileName = decodeURIComponent(encodedFileName); const targetFileName = decodeURIComponent(encodedFileName);
const videos = torrent.links.filter(link => isVideo(link.filename)).sort((a, b) => b.size - a.size); const videos = torrent.links.filter(link => isVideo(link.filename));
const targetVideo = Number.isInteger(fileIndex) const targetVideo = Number.isInteger(fileIndex)
? videos.find(video => sameFilename(targetFileName, video.filename)) ? videos.find(video => sameFilename(targetFileName, video.filename))
: videos[0]; : videos.sort((a, b) => b.size - a.size)[0];
if (!targetVideo && torrent.links.every(link => isArchive(link.filename))) { if (!targetVideo && torrent.links.every(link => isArchive(link.filename))) {
console.log(`Only AllDebrid archive is available for [${torrent.hash}] ${encodedFileName}`) console.log(`Only AllDebrid archive is available for [${torrent.hash}] ${encodedFileName}`)

View File

@@ -25,7 +25,7 @@ export async function getCachedStreams(streams, apiKey) {
return available && streams return available && streams
.reduce((mochStreams, stream) => { .reduce((mochStreams, stream) => {
const cachedEntry = available[stream.infoHash]; const cachedEntry = available[stream.infoHash];
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = { mochStreams[stream.infoHash] = {
url: `${apiKey}/${stream.infoHash}/null/${stream.fileIdx}`, url: `${apiKey}/${stream.infoHash}/null/${stream.fileIdx}`,
cached: !!cachedEntry cached: !!cachedEntry
}; };

View File

@@ -173,7 +173,7 @@ function processMochResults(streams, config, results) {
function populateCachedLinks(streams, mochResult, config) { function populateCachedLinks(streams, mochResult, config) {
return streams.map(stream => { return streams.map(stream => {
const cachedEntry = stream.infoHash && mochResult.mochStreams[`${stream.infoHash}@${stream.fileIdx}`]; const cachedEntry = stream.infoHash && mochResult.mochStreams[stream.infoHash];
if (cachedEntry?.cached) { if (cachedEntry?.cached) {
return { return {
name: `[${mochResult.moch.shortName}+] ${stream.name}`, name: `[${mochResult.moch.shortName}+] ${stream.name}`,
@@ -190,7 +190,7 @@ function populateDownloadLinks(streams, mochResults, config) {
const torrentStreams = streams.filter(stream => stream.infoHash); const torrentStreams = streams.filter(stream => stream.infoHash);
const seededStreams = streams.filter(stream => !stream.title.includes('👤 0')); const seededStreams = streams.filter(stream => !stream.title.includes('👤 0'));
torrentStreams.forEach(stream => mochResults.forEach(mochResult => { torrentStreams.forEach(stream => mochResults.forEach(mochResult => {
const cachedEntry = mochResult.mochStreams[`${stream.infoHash}@${stream.fileIdx}`]; const cachedEntry = mochResult.mochStreams[stream.infoHash];
const isCached = cachedEntry?.cached; const isCached = cachedEntry?.cached;
if (!isCached && isHealthyStreamForDebrid(seededStreams, stream)) { if (!isCached && isHealthyStreamForDebrid(seededStreams, stream)) {
streams.push({ streams.push({

View File

@@ -27,9 +27,10 @@ export async function getCachedStreams(streams, apiKey) {
const isCached = available.includes(stream.infoHash); const isCached = available.includes(stream.infoHash);
const streamTitleParts = stream.title.replace(/\n👤.*/s, '').split('\n'); const streamTitleParts = stream.title.replace(/\n👤.*/s, '').split('\n');
const fileName = streamTitleParts[streamTitleParts.length - 1]; const fileName = streamTitleParts[streamTitleParts.length - 1];
const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null;
const encodedFileName = encodeURIComponent(fileName); const encodedFileName = encodeURIComponent(fileName);
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = { mochStreams[stream.infoHash] = {
url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${stream.fileIdx}`, url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`,
cached: isCached cached: isCached
}; };
return mochStreams; return mochStreams;
@@ -136,8 +137,7 @@ async function _retryCreateTorrent(OC, infoHash, cachedEntryInfo, fileIndex) {
async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex) { async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex) {
const targetFileName = decodeURIComponent(cachedEntryInfo); const targetFileName = decodeURIComponent(cachedEntryInfo);
const files = await _getFileUrls(OC, torrent) const files = await _getFileUrls(OC, torrent)
const targetFile = files.find(file => file.includes(`/${torrent.requestId}/${fileIndex}/`)) const targetFile = files.find(file => sameFilename(targetFileName, file.split('/').pop()))
|| files.find(file => sameFilename(targetFileName, file.split('/').pop()))
|| files.find(file => isVideo(file)) || files.find(file => isVideo(file))
|| files.pop(); || files.pop();

View File

@@ -124,10 +124,10 @@ async function _getCachedLink(PM, infoHash, encodedFileName, fileIndex, ip, isBr
const cachedTorrent = await PM.transfer.directDownload(magnet.encode({ infoHash }), ip); const cachedTorrent = await PM.transfer.directDownload(magnet.encode({ infoHash }), ip);
if (cachedTorrent?.content?.length) { if (cachedTorrent?.content?.length) {
const targetFileName = decodeURIComponent(encodedFileName); const targetFileName = decodeURIComponent(encodedFileName);
const videos = cachedTorrent.content.filter(file => isVideo(file.path)).sort((a, b) => b.size - a.size); const videos = cachedTorrent.content.filter(file => isVideo(file.path));
const targetVideo = Number.isInteger(fileIndex) const targetVideo = Number.isInteger(fileIndex)
? videos.find(video => sameFilename(video.path, targetFileName)) ? videos.find(video => sameFilename(video.path, targetFileName))
: videos[0]; : videos.sort((a, b) => b.size - a.size)[0];
if (!targetVideo && videos.every(video => isArchive(video.path))) { if (!targetVideo && videos.every(video => isArchive(video.path))) {
console.log(`Only Premiumize archive is available for [${infoHash}] ${fileIndex}`) console.log(`Only Premiumize archive is available for [${infoHash}] ${fileIndex}`)
return StaticResponse.FAILED_RAR; return StaticResponse.FAILED_RAR;

View File

@@ -17,7 +17,7 @@ export async function getCachedStreams(streams, apiKey) {
const fileName = streamTitleParts[streamTitleParts.length - 1]; const fileName = streamTitleParts[streamTitleParts.length - 1];
const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null; const fileIndex = streamTitleParts.length === 2 ? stream.fileIdx : null;
const encodedFileName = encodeURIComponent(fileName); const encodedFileName = encodeURIComponent(fileName);
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = { mochStreams[stream.infoHash] = {
url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`, url: `${apiKey}/${stream.infoHash}/${encodedFileName}/${fileIndex}`,
cached: false cached: false
}; };
@@ -168,12 +168,12 @@ async function _getTargetFile(Putio, torrent, encodedFileName, fileIndex) {
while (!targetFile && files.length) { while (!targetFile && files.length) {
const folders = files.filter(file => file.file_type === 'FOLDER'); const folders = files.filter(file => file.file_type === 'FOLDER');
videos = videos.concat(files.filter(file => isVideo(file.name))).sort((a, b) => b.size - a.size); videos = videos.concat(files.filter(file => isVideo(file.name)));
// when specific file index is defined search by filename // when specific file index is defined search by filename
// when it's not defined find all videos and take the largest one // when it's not defined find all videos and take the largest one
targetFile = Number.isInteger(fileIndex) targetFile = Number.isInteger(fileIndex)
? videos.find(video => sameFilename(targetFileName, video.name)) ? videos.find(video => sameFilename(targetFileName, video.name))
: !folders.length && videos[0]; : !folders.length && videos.sort((a, b) => b.size - a.size)[0];
files = !targetFile files = !targetFile
? await Promise.all(folders.map(folder => _getFiles(Putio, folder.id))) ? await Promise.all(folders.map(folder => _getFiles(Putio, folder.id)))
.then(results => results.reduce((a, b) => a.concat(b), [])) .then(results => results.reduce((a, b) => a.concat(b), []))

View File

@@ -21,7 +21,7 @@ export async function getCachedStreams(streams, apiKey) {
.reduce((mochStreams, stream) => { .reduce((mochStreams, stream) => {
const cachedEntry = available[stream.infoHash]; const cachedEntry = available[stream.infoHash];
const cachedIds = _getCachedFileIds(stream.fileIdx, cachedEntry); const cachedIds = _getCachedFileIds(stream.fileIdx, cachedEntry);
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = { mochStreams[stream.infoHash] = {
url: `${apiKey}/${stream.infoHash}/null/${stream.fileIdx}`, url: `${apiKey}/${stream.infoHash}/null/${stream.fileIdx}`,
cached: !!cachedIds.length cached: !!cachedIds.length
}; };
@@ -395,5 +395,5 @@ function infringingFile(error) {
} }
async function getDefaultOptions(ip) { async function getDefaultOptions(ip) {
return { ip, timeout: 15000 }; return { ip, timeout: 10000 };
} }

View File

@@ -16,13 +16,14 @@ public static class DebridMetaToTorrentMeta
foreach (var metadataEntry in Metadata.Where(m => Filetypes.VideoFileExtensions.Any(ext => m.Value.Filename.EndsWith(ext)))) foreach (var metadataEntry in Metadata.Where(m => Filetypes.VideoFileExtensions.Any(ext => m.Value.Filename.EndsWith(ext))))
{ {
var validFileIndex = int.TryParse(metadataEntry.Key, out var fileIndex); var validFileIndex = int.TryParse(metadataEntry.Key, out var fileIndex);
var fileIndexMinusOne = Math.Max(0, fileIndex - 1);
var file = new TorrentFile var file = new TorrentFile
{ {
ImdbId = ImdbId, ImdbId = ImdbId,
KitsuId = 0, KitsuId = 0,
InfoHash = torrent.InfoHash, InfoHash = torrent.InfoHash,
FileIndex = validFileIndex ? fileIndex : 0, FileIndex = validFileIndex ? fileIndexMinusOne : 0,
Title = metadataEntry.Value.Filename, Title = metadataEntry.Value.Filename,
Size = metadataEntry.Value.Filesize.GetValueOrDefault(), Size = metadataEntry.Value.Filesize.GetValueOrDefault(),
}; };
@@ -66,13 +67,14 @@ public static class DebridMetaToTorrentMeta
foreach (var metadataEntry in Metadata.Where(m => Filetypes.SubtitleFileExtensions.Any(ext => m.Value.Filename.EndsWith(ext)))) foreach (var metadataEntry in Metadata.Where(m => Filetypes.SubtitleFileExtensions.Any(ext => m.Value.Filename.EndsWith(ext))))
{ {
var validFileIndex = int.TryParse(metadataEntry.Key, out var fileIndex); var validFileIndex = int.TryParse(metadataEntry.Key, out var fileIndex);
var fileIndexMinusOne = Math.Max(0, fileIndex - 1);
var fileId = torrentFiles.FirstOrDefault( var fileId = torrentFiles.FirstOrDefault(
t => Path.GetFileNameWithoutExtension(t.Title) == Path.GetFileNameWithoutExtension(metadataEntry.Value.Filename))?.Id ?? 0; t => Path.GetFileNameWithoutExtension(t.Title) == Path.GetFileNameWithoutExtension(metadataEntry.Value.Filename))?.Id ?? 0;
var file = new SubtitleFile var file = new SubtitleFile
{ {
InfoHash = InfoHash, InfoHash = InfoHash,
FileIndex = validFileIndex ? fileIndex : 0, FileIndex = validFileIndex ? fileIndexMinusOne : 0,
FileId = fileId, FileId = fileId,
Title = metadataEntry.Value.Filename, Title = metadataEntry.Value.Filename,
}; };

View File

@@ -1 +1 @@
rank-torrent-name==0.2.5 rank-torrent-name==0.2.11

View File

@@ -1 +1 @@
rank-torrent-name==0.2.5 rank-torrent-name==0.2.11

View File

@@ -1 +1 @@
rank-torrent-name==0.2.5 rank-torrent-name==0.2.11