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:
@@ -58,5 +58,8 @@ module.exports = {
|
||||
organize: {
|
||||
includePrivate: false,
|
||||
interval: 10000,
|
||||
},
|
||||
wanted: {
|
||||
interval: 21600000, // re-check the wishlist every 6h
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,4 +5,5 @@ module.exports = {
|
||||
pubsub: require('./pubsub'),
|
||||
torrent: require('./torrent'),
|
||||
organizeWatcher: require('./organizeWatcher'),
|
||||
wantedWatcher: require('./wantedWatcher'),
|
||||
}
|
||||
@@ -259,7 +259,7 @@ async function findReleases(tmdbId, mediaType){
|
||||
}
|
||||
|
||||
if(!candidates.length){
|
||||
return { title: meta.title, year: meta.year, options: [] };
|
||||
return { title: meta.title, year: meta.year, tmdbId, mediaType, options: [] };
|
||||
}
|
||||
|
||||
let today = new Date().toISOString().slice(0, 10);
|
||||
@@ -274,7 +274,7 @@ async function findReleases(tmdbId, mediaType){
|
||||
options = decorateOptions(options, candidates);
|
||||
if(!options.length) options = decorateOptions(fallbackReleases(candidates), candidates);
|
||||
|
||||
let result = { title: meta.title, year: meta.year, options };
|
||||
let result = { title: meta.title, year: meta.year, tmdbId, mediaType, options };
|
||||
|
||||
// Quality-aware dedup: flag options you already own at equal-or-better quality.
|
||||
if(mediaType !== 'tv'){
|
||||
|
||||
@@ -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 };
|
||||
+2
-1
@@ -3,5 +3,6 @@
|
||||
module.exports = {
|
||||
User: require('./ldap/user').User,
|
||||
AuthToken: require('./sql').AuthToken,
|
||||
Torrent: require('./sql').Torrent
|
||||
Torrent: require('./sql').Torrent,
|
||||
Wanted: require('./sql').Wanted
|
||||
};
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('Wanteds', {
|
||||
tmdbId: {
|
||||
type: Sequelize.STRING,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
mediaType: { type: Sequelize.STRING, allowNull: false, defaultValue: 'movie' },
|
||||
title: { type: Sequelize.STRING },
|
||||
year: { type: Sequelize.STRING },
|
||||
status: { type: Sequelize.STRING, allowNull: false, defaultValue: 'wanted' },
|
||||
requestedBy: { type: Sequelize.STRING },
|
||||
createdAt: { allowNull: false, type: Sequelize.DATE },
|
||||
updatedAt: { allowNull: false, type: Sequelize.DATE },
|
||||
});
|
||||
},
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.dropTable('Wanteds');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (sequelize, DataTypes, Model) => {
|
||||
class Wanted extends Model {
|
||||
static associate(models) {
|
||||
}
|
||||
}
|
||||
Wanted.init({
|
||||
tmdbId: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
mediaType: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: 'movie',
|
||||
},
|
||||
title: DataTypes.STRING,
|
||||
year: DataTypes.STRING,
|
||||
status: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: 'wanted', // wanted | fulfilled
|
||||
},
|
||||
requestedBy: DataTypes.STRING,
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Wanted',
|
||||
});
|
||||
return Wanted;
|
||||
};
|
||||
@@ -396,7 +396,12 @@
|
||||
|
||||
// Step 3: render the release cards; a tap feeds the existing add dialog.
|
||||
function tbpRenderReleases(data){
|
||||
if(!data.options.length){ tbpSearchBody('<p>No good-quality copy of <b>'+ tbpEsc(data.title) +'</b> found — it may not be released yet, or only low-quality (CAM) copies exist.</p>'); return; }
|
||||
if(!data.options.length){
|
||||
var msg = '<p>No good-quality copy of <b>'+ tbpEsc(data.title) +'</b> found — it may not be released yet, or only low-quality (CAM) copies exist.</p>';
|
||||
if(data.remembered) msg += '<p style="color:#2a2">✓ Added to your wishlist — we\'ll grab it automatically when a good copy appears.</p>';
|
||||
tbpSearchBody(msg);
|
||||
return;
|
||||
}
|
||||
var header = '<h3>'+ tbpEsc(data.title +' ('+ (data.year || '?') +')') +'</h3>';
|
||||
if(data.library && data.library.owned) header += '<p style="color:#2a2">✓ Already in your library ('+ tbpEsc(data.library.quality) +') — only upgrades are offered.</p>';
|
||||
tbpSearchBody(header);
|
||||
|
||||
+36
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
const router = require('express').Router();
|
||||
const search = require('>/controller/search');
|
||||
const { Torrent } = require('>/models');
|
||||
const { Torrent, Wanted } = require('>/models');
|
||||
|
||||
// Step 1: fuzzy query -> a few TMDB title candidates( with posters) to confirm.
|
||||
router.get('/title', async function(req, res, next){
|
||||
@@ -16,7 +16,41 @@ router.get('/title', async function(req, res, next){
|
||||
// Step 2: confirmed title -> TPB search + LLM-curated release options.
|
||||
router.post('/releases', async function(req, res, next){
|
||||
try{
|
||||
res.json(await search.findReleases(req.body.tmdbId, req.body.mediaType));
|
||||
let result = await search.findReleases(req.body.tmdbId, req.body.mediaType);
|
||||
|
||||
// Nothing good yet( e.g. unreleased) -> remember it and grab it later.
|
||||
if(!result.options.length && result.mediaType !== 'tv' && result.tmdbId){
|
||||
await Wanted.upsert({
|
||||
tmdbId: String(result.tmdbId),
|
||||
mediaType: result.mediaType,
|
||||
title: result.title,
|
||||
year: result.year,
|
||||
status: 'wanted',
|
||||
requestedBy: req.user.username,
|
||||
});
|
||||
result.remembered = true;
|
||||
}
|
||||
|
||||
res.json(result);
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// Wishlist: things we couldn't find yet and are watching for.
|
||||
router.get('/wanted', async function(req, res, next){
|
||||
try{
|
||||
res.json(await Wanted.findAll({ order: [['createdAt', 'DESC']] }));
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/wanted/:tmdbId', async function(req, res, next){
|
||||
try{
|
||||
let wanted = await Wanted.findByPk(req.params.tmdbId);
|
||||
if(wanted) await wanted.destroy();
|
||||
res.json({ deleted: true });
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user