mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] cleans up repository methods
This commit is contained in:
@@ -77,11 +77,6 @@ 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 },
|
|
||||||
title: { type: Sequelize.STRING(256), allowNull: false }
|
|
||||||
});
|
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
if (process.env.ENABLE_SYNC) {
|
if (process.env.ENABLE_SYNC) {
|
||||||
return database.sync({ alter: true })
|
return database.sync({ alter: true })
|
||||||
@@ -99,10 +94,6 @@ function getProvider(provider) {
|
|||||||
.catch(() => provider);
|
.catch(() => provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProvider(provider) {
|
|
||||||
return Provider.update(provider, { where: { name: { [Op.eq]: provider.name } } });
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTorrent(torrent) {
|
function getTorrent(torrent) {
|
||||||
return Torrent.findByPk(torrent.infoHash)
|
return Torrent.findByPk(torrent.infoHash)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
@@ -135,10 +126,6 @@ function getUpdateSeedersTorrents() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTorrentsUpdatedBetween(provider, startDate, endDate) {
|
|
||||||
return Torrent.findAll({ where: { provider: provider, updatedAt: { [Op.gte]: startDate, [Op.lte]: endDate } } });
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTorrent(torrent) {
|
function createTorrent(torrent) {
|
||||||
return Torrent.upsert(torrent);
|
return Torrent.upsert(torrent);
|
||||||
}
|
}
|
||||||
@@ -163,7 +150,7 @@ function getSkipTorrent(torrent) {
|
|||||||
return SkipTorrent.findByPk(torrent.infoHash)
|
return SkipTorrent.findByPk(torrent.infoHash)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return getFailedImdbTorrent(torrent);
|
throw new Error(`torrent not found: ${torrent.infoHash}`);
|
||||||
}
|
}
|
||||||
return result.dataValues;
|
return result.dataValues;
|
||||||
})
|
})
|
||||||
@@ -173,24 +160,9 @@ function createSkipTorrent(torrent) {
|
|||||||
return SkipTorrent.upsert({ infoHash: torrent.infoHash });
|
return SkipTorrent.upsert({ infoHash: torrent.infoHash });
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFailedImdbTorrent(torrent) {
|
|
||||||
return FailedImdbTorrent.findByPk(torrent.infoHash)
|
|
||||||
.then((result) => {
|
|
||||||
if (!result) {
|
|
||||||
throw new Error(`torrent not found: ${torrent.infoHash}`);
|
|
||||||
}
|
|
||||||
return result.dataValues;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function createFailedImdbTorrent(torrent) {
|
|
||||||
return FailedImdbTorrent.upsert(torrent);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
connect,
|
connect,
|
||||||
getProvider,
|
getProvider,
|
||||||
updateProvider,
|
|
||||||
createTorrent,
|
createTorrent,
|
||||||
getTorrent,
|
getTorrent,
|
||||||
getTorrentsBasedOnTitle,
|
getTorrentsBasedOnTitle,
|
||||||
@@ -201,7 +173,5 @@ module.exports = {
|
|||||||
deleteFile,
|
deleteFile,
|
||||||
getSkipTorrent,
|
getSkipTorrent,
|
||||||
createSkipTorrent,
|
createSkipTorrent,
|
||||||
createFailedImdbTorrent,
|
getTorrentsWithoutSize
|
||||||
getTorrentsWithoutSize,
|
|
||||||
getTorrentsUpdatedBetween
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user