mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
updates horriblesubs api to filter entries based on title
This commit is contained in:
@@ -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
|
||||
};
|
||||
Reference in New Issue
Block a user