mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
try to fix putio
This commit is contained in:
@@ -151,14 +151,10 @@ async function _unrestrictLink(Putio, torrent, encodedFileName, fileIndex) {
|
||||
}
|
||||
|
||||
async function _unrestrictVideo(Putio, videoId) {
|
||||
const publicToken = await _getPublicToken(Putio, videoId);
|
||||
const publicFile = await Putio.File.Public(publicToken).then(response => response.data.parent);
|
||||
|
||||
if (!publicFile?.stream_url?.length) {
|
||||
return Promise.reject(`No Putio links found for [${videoId}]`);
|
||||
}
|
||||
console.log(`Unrestricted Putio [${videoId}] to ${publicFile.stream_url}`);
|
||||
return publicFile.stream_url;
|
||||
const response = await Putio.File.GetStorageURL(videoId);
|
||||
const downloadUrl = response.data.url
|
||||
console.log(`Unrestricted Putio [${videoId}] to ${downloadUrl}`);
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
async function _getTargetFile(Putio, torrent, encodedFileName, fileIndex) {
|
||||
@@ -174,7 +170,7 @@ async function _getTargetFile(Putio, torrent, encodedFileName, fileIndex) {
|
||||
// when it's not defined find all videos and take the largest one
|
||||
targetFile = Number.isInteger(fileIndex)
|
||||
? videos.find(video => sameFilename(targetFileName, video.name))
|
||||
: !folders.length && videos.toSorted((a, b) => b.size - a.size)[0];
|
||||
: !folders.length && videos.sort((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), []))
|
||||
@@ -191,19 +187,6 @@ async function _getFiles(Putio, fileId) {
|
||||
: [response.data.parent];
|
||||
}
|
||||
|
||||
async function _getPublicToken(Putio, targetVideoId) {
|
||||
const publicLinks = await Putio.Files.PublicShares().then(response => response.data.links);
|
||||
const alreadySharedLink = publicLinks.find(link => link.user_file.id === targetVideoId);
|
||||
if (alreadySharedLink) {
|
||||
return alreadySharedLink.token;
|
||||
}
|
||||
if (publicLinks.length >= 10) {
|
||||
// maximum public shares reached, revoke last one;
|
||||
await Putio.File.RevokePublicLink(publicLinks[0].id);
|
||||
}
|
||||
return Putio.File.CreatePublicLink(targetVideoId).then(response => response.data.token);
|
||||
}
|
||||
|
||||
function createPutioAPI(apiKey) {
|
||||
const clientId = apiKey.replace(/@.*/, '');
|
||||
const token = apiKey.replace(/.*@/, '');
|
||||
|
||||
Reference in New Issue
Block a user