mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
updates tpb dump scrapper
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { Sequelize }= require('sequelize');
|
||||
const Op = Sequelize.Op;
|
||||
|
||||
const POSTGRES_URI = process.env.POSTGRES_URI || 'postgres://torrentio:postgres@localhost:5432/torrentio';
|
||||
|
||||
@@ -13,20 +14,42 @@ const Torrent = database.define('torrent', {
|
||||
infoHash: { type: Sequelize.STRING(64), primaryKey: true },
|
||||
provider: { type: Sequelize.STRING(32), allowNull: false },
|
||||
title: { type: Sequelize.STRING(128), allowNull: false },
|
||||
size: { type: Sequelize.BIGINT },
|
||||
type: { type: Sequelize.STRING(16), allowNull: false },
|
||||
imdbId: { type: Sequelize.STRING(12) },
|
||||
kitsuId: { type: Sequelize.INTEGER },
|
||||
uploadDate: { type: Sequelize.DATE, allowNull: false },
|
||||
seeders: { type: Sequelize.SMALLINT },
|
||||
files: { type: Sequelize.JSONB }
|
||||
seeders: { type: Sequelize.SMALLINT }
|
||||
});
|
||||
|
||||
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' },
|
||||
fileIndex: { type: Sequelize.INTEGER },
|
||||
title: { type: Sequelize.STRING(128), allowNull: false },
|
||||
size: { type: Sequelize.BIGINT },
|
||||
imdbId: { type: Sequelize.STRING(12) },
|
||||
imdbSeason: { type: Sequelize.INTEGER },
|
||||
imdbEpisode: { type: Sequelize.INTEGER },
|
||||
kitsuId: { type: Sequelize.INTEGER },
|
||||
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'] }
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
const SkipTorrent = database.define('skip_torrent', {
|
||||
infoHash: {type: Sequelize.STRING(64), primaryKey: true},
|
||||
});
|
||||
|
||||
const FailedImdbTorrent = database.define('failed_imdb_torrent', {
|
||||
infoHash: {type: Sequelize.STRING(64), primaryKey: true},
|
||||
title: { type: Sequelize.STRING(128), allowNull: false }
|
||||
});
|
||||
|
||||
function connect() {
|
||||
@@ -34,7 +57,7 @@ function connect() {
|
||||
}
|
||||
|
||||
function getProvider(provider) {
|
||||
return Provider.findOrCreate({ where: { name: provider.name }, defaults: provider });
|
||||
return Provider.findOrCreate({ where: { name: { [Op.eq]: provider.name }}, defaults: provider });
|
||||
}
|
||||
|
||||
function updateProvider(provider) {
|
||||
@@ -51,10 +74,14 @@ function getTorrent(torrent) {
|
||||
})
|
||||
}
|
||||
|
||||
function updateTorrent(torrent) {
|
||||
function createTorrent(torrent) {
|
||||
return Torrent.upsert(torrent);
|
||||
}
|
||||
|
||||
function createFile(file) {
|
||||
return File.upsert(file);
|
||||
}
|
||||
|
||||
function getSkipTorrent(torrent) {
|
||||
return SkipTorrent.findByPk(torrent.infoHash)
|
||||
.then((result) =>{
|
||||
@@ -80,7 +107,7 @@ function getFailedImdbTorrent(torrent) {
|
||||
}
|
||||
|
||||
function createFailedImdbTorrent(torrent) {
|
||||
return FailedImdbTorrent.upsert({ infoHash: torrent.infoHash });
|
||||
return FailedImdbTorrent.upsert(torrent);
|
||||
}
|
||||
|
||||
module.exports = { connect, getProvider, updateProvider, getTorrent, updateTorrent, getSkipTorrent, createSkipTorrent, createFailedImdbTorrent };
|
||||
module.exports = { connect, getProvider, updateProvider, getTorrent, createTorrent, createFile, getSkipTorrent, createSkipTorrent, createFailedImdbTorrent };
|
||||
Reference in New Issue
Block a user