Remember unavailable movies and auto-grab them later (wishlist)
When Smart Search finds no good copy of a movie (unreleased / only CAMs), we now record it instead of dropping it: - New Wanted model + migration (dedup by tmdbId, status wanted|fulfilled). - POST /__api/search/releases remembers a movie when it returns no options, and the UI confirms it was added to the wishlist. - controller/wantedWatcher re-runs Smart Search for wishlisted items every 6h (and on boot); when a good copy appears it queues the recommended release, which then flows through the normal download + organize pipeline, and marks the item fulfilled. - GET/DELETE /__api/search/wanted to view/remove the wishlist. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const conf = require('>/conf');
|
||||
const search = require('>/controller/search');
|
||||
|
||||
let lock = false;
|
||||
|
||||
// Periodically re-run Smart Search for wishlisted movies; when a good copy finally
|
||||
// appears, queue it( which then flows through the normal download + organize pipeline).
|
||||
async function tick(){
|
||||
if(lock) return;
|
||||
lock = true;
|
||||
try{
|
||||
const { Wanted, Torrent } = require('>/models');
|
||||
|
||||
let wanted = await Wanted.findAll({ where: { status: 'wanted' } });
|
||||
for(let w of wanted){
|
||||
if(!w.requestedBy) continue;
|
||||
try{
|
||||
let result = await search.findReleases(w.tmdbId, w.mediaType);
|
||||
let pick = result.options.find(o => o.role === 'recommended' && !o.alreadyOwned)
|
||||
|| result.options.find(o => !o.alreadyOwned);
|
||||
if(!pick) continue;
|
||||
|
||||
await Torrent.create({
|
||||
magnetLink: pick.magnetLink,
|
||||
isPrivate: false,
|
||||
added_by: w.requestedBy,
|
||||
category: pick.category,
|
||||
});
|
||||
w.status = 'fulfilled';
|
||||
await w.save();
|
||||
}catch(error){
|
||||
// leave it wanted; try again next tick
|
||||
}
|
||||
}
|
||||
}catch(error){
|
||||
// DB/Transmission transient — retry next tick
|
||||
}finally{
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(tick, conf.wanted.interval || 6 * 60 * 60 * 1000);
|
||||
tick(); // check once on boot
|
||||
|
||||
module.exports = { tick };
|
||||
Reference in New Issue
Block a user