use custom fn to detect same filename in debrids

This commit is contained in:
TheBeastLT
2023-12-16 19:04:53 +02:00
parent 2c4da0679f
commit afa1458144
5 changed files with 13 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import StaticResponse from './static.js';
import { getMagnetLink } from '../lib/magnetHelper.js';
import { Type } from "../lib/types.js";
import { decode } from "magnet-uri";
import { sameFilename } from "./mochHelper.js";
const PutioAPI = PutioClient.default;
const KEY = 'putio';
@@ -172,14 +173,14 @@ async function _getTargetFile(Putio, torrent, encodedFileName, fileIndex) {
// when specific file index is defined search by filename
// when it's not defined find all videos and take the largest one
targetFile = Number.isInteger(fileIndex)
? videos.find(video => targetFileName.includes(video.name))
: !folders.length && videos.sort((a, b) => b.size - a.size)[0];
? videos.find(video => sameFilename(targetFileName, video.name))
: !folders.length && videos.toSorted((a, b) => b.size - a.size)[0];
files = !targetFile
? await Promise.all(folders.map(folder => _getFiles(Putio, folder.id)))
.then(results => results.reduce((a, b) => a.concat(b), []))
: [];
}
return targetFile ? targetFile : Promise.reject(`No target file found for Putio [${torrent.hash}] ${targetFileName}`);
return targetFile || Promise.reject(`No target file found for Putio [${torrent.hash}] ${targetFileName}`);
}
async function _getFiles(Putio, fileId) {