updates horriblesubs api to filter entries based on title

This commit is contained in:
TheBeastLT
2020-02-17 14:26:27 +01:00
parent 683b58b4b6
commit 30421815d7
3 changed files with 52 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
const { Sequelize }= require('sequelize');
const { Sequelize } = require('sequelize');
const Op = Sequelize.Op;
const POSTGRES_URI = process.env.POSTGRES_URI || 'postgres://torrentio:postgres@localhost:5432/torrentio';
@@ -6,7 +6,7 @@ const POSTGRES_URI = process.env.POSTGRES_URI || 'postgres://torrentio:postgres@
const database = new Sequelize(POSTGRES_URI, { logging: false });
const Provider = database.define('provider', {
name: { type: Sequelize.STRING(32), primaryKey: true},
name: { type: Sequelize.STRING(32), primaryKey: true },
lastScraped: { type: Sequelize.DATE }
});
@@ -17,13 +17,19 @@ const Torrent = database.define('torrent', {
size: { type: Sequelize.BIGINT },
type: { type: Sequelize.STRING(16), allowNull: false },
uploadDate: { type: Sequelize.DATE, allowNull: false },
seeders: { type: Sequelize.SMALLINT }
seeders: { type: Sequelize.SMALLINT },
trackers: { type: Sequelize.STRING(4096) }
});
const File = database.define('file',
{
id: { type: Sequelize.BIGINT, autoIncrement: true, primaryKey: true },
infoHash: { type: Sequelize.STRING(64), allowNull: false, references: { model: Torrent, key: 'infoHash' }, onDelete: 'CASCADE' },
infoHash: {
type: Sequelize.STRING(64),
allowNull: false,
references: { model: Torrent, key: 'infoHash' },
onDelete: 'CASCADE'
},
fileIndex: { type: Sequelize.INTEGER },
title: { type: Sequelize.STRING(256), allowNull: false },
size: { type: Sequelize.BIGINT },
@@ -34,21 +40,21 @@ const File = database.define('file',
kitsuEpisode: { type: Sequelize.INTEGER }
},
{
indexes:[
{ unique: true, fields:['infoHash'], where: { fileIndex: { [Op.eq]: null } } },
{ unique: true, fields:['infoHash', 'fileIndex', 'imdbEpisode'] },
{ unique: false, fields:['imdbId', 'imdbSeason', 'imdbEpisode'] },
{ unique: false, fields:['kitsuId', 'kitsuEpisode'] }
]
}
indexes: [
{ unique: true, fields: ['infoHash'], where: { fileIndex: { [Op.eq]: null } } },
{ unique: true, fields: ['infoHash', 'fileIndex', 'imdbEpisode'] },
{ unique: false, fields: ['imdbId', 'imdbSeason', 'imdbEpisode'] },
{ unique: false, fields: ['kitsuId', 'kitsuEpisode'] }
]
}
);
const SkipTorrent = database.define('skip_torrent', {
infoHash: {type: Sequelize.STRING(64), primaryKey: true},
infoHash: { type: Sequelize.STRING(64), primaryKey: true },
});
const FailedImdbTorrent = database.define('failed_imdb_torrent', {
infoHash: {type: Sequelize.STRING(64), primaryKey: true},
infoHash: { type: Sequelize.STRING(64), primaryKey: true },
title: { type: Sequelize.STRING(256), allowNull: false }
});
@@ -57,7 +63,7 @@ function connect() {
}
function getProvider(provider) {
return Provider.findOrCreate({ where: { name: { [Op.eq]: provider.name }}, defaults: provider });
return Provider.findOrCreate({ where: { name: { [Op.eq]: provider.name } }, defaults: provider });
}
function updateProvider(provider) {
@@ -66,7 +72,7 @@ function updateProvider(provider) {
function getTorrent(torrent) {
return Torrent.findByPk(torrent.infoHash)
.then((result) =>{
.then((result) => {
if (!result) {
throw new Error(`torrent not found: ${torrent.infoHash}`);
}
@@ -88,7 +94,7 @@ function getFiles(torrent) {
function getSkipTorrent(torrent) {
return SkipTorrent.findByPk(torrent.infoHash)
.then((result) =>{
.then((result) => {
if (!result) {
return getFailedImdbTorrent(torrent);
}
@@ -102,7 +108,7 @@ function createSkipTorrent(torrent) {
function getFailedImdbTorrent(torrent) {
return FailedImdbTorrent.findByPk(torrent.infoHash)
.then((result) =>{
.then((result) => {
if (!result) {
throw new Error(`torrent not found: ${torrent.infoHash}`);
}
@@ -114,4 +120,15 @@ function createFailedImdbTorrent(torrent) {
return FailedImdbTorrent.upsert(torrent);
}
module.exports = { connect, getProvider, updateProvider, getTorrent, createTorrent, createFile, getFiles, getSkipTorrent, createSkipTorrent, createFailedImdbTorrent };
module.exports = {
connect,
getProvider,
updateProvider,
getTorrent,
createTorrent,
createFile,
getFiles,
getSkipTorrent,
createSkipTorrent,
createFailedImdbTorrent
};