Random changes
This commit is contained in:
1 parent
7160669468
commit
0b1a1d989f
17 files changed
+205
-159
No files matched your search
@@ -1,8 +1,31 @@
|
||||
const { Sequelize } = require("sequelize");
|
||||
const Collection = require("../models/Collection");
|
||||
const Genre = require("../models/Genre");
|
||||
const Media = require("../models/Media");
|
||||
|
||||
|
||||
async function initializeData() {
|
||||
initializeGenres();
|
||||
|
||||
|
||||
// const collections = await Collection.findAll({
|
||||
// where: {
|
||||
// posterPath: { [Sequelize.Op.notLike]: '/%' }
|
||||
// }
|
||||
// });
|
||||
|
||||
// collections.forEach(collection => {
|
||||
// Media.create({
|
||||
// mediaable: 'collection',
|
||||
// mediaableId: collection.id,
|
||||
// type: 'poster',
|
||||
// path: collection.posterPath,
|
||||
// isLocal: true,
|
||||
// isSelected: true
|
||||
// })
|
||||
// });
|
||||
|
||||
// console.log(collections);
|
||||
}
|
||||
|
||||
async function initializeGenres() {
|
||||
|
||||
@@ -17,8 +17,8 @@ const Episode = sequelize.define("episode",
|
||||
}
|
||||
},
|
||||
|
||||
name: { type: DataTypes.STRING(200) },
|
||||
overview: { type: DataTypes.STRING(2000) },
|
||||
name: { type: DataTypes.STRING(500) },
|
||||
overview: { type: DataTypes.STRING(3000) },
|
||||
episode_number: { type: DataTypes.INTEGER },
|
||||
episode_type: { type: DataTypes.STRING(60) },
|
||||
runtime: { type: DataTypes.INTEGER },
|
||||
|
||||
@@ -5,23 +5,16 @@ const Media = sequelize.define("media",
|
||||
{
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
|
||||
// entryId: {
|
||||
// type: DataTypes.INTEGER,
|
||||
// references: {
|
||||
// model: 'Entries',
|
||||
// key: 'id'
|
||||
// },
|
||||
// field: 'entry_id'
|
||||
// },
|
||||
|
||||
mediaable: { type: Sequelize.STRING },
|
||||
mediaableId: { type: Sequelize.INTEGER, field: 'mediaable_id' },
|
||||
|
||||
type: { type: DataTypes.STRING(50) },
|
||||
path: { type: DataTypes.STRING(200) },
|
||||
|
||||
isLocal: { type: DataTypes.BOOLEAN, field: 'is_local' },
|
||||
isSelected: { type: DataTypes.BOOLEAN, field: 'is_selected', defaultValue: false },
|
||||
isCustom: { type: DataTypes.BOOLEAN, field: 'is_custom', defaultValue: false },
|
||||
isFavorit: { type: DataTypes.BOOLEAN, field: 'is_favorit', defaultValue: false },
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ const Season = sequelize.define("season",
|
||||
}
|
||||
},
|
||||
|
||||
name: { type: DataTypes.STRING(30) },
|
||||
overview: { type: DataTypes.STRING(1000) },
|
||||
name: { type: DataTypes.STRING(500) },
|
||||
overview: { type: DataTypes.STRING(3000) },
|
||||
season_number: { type: DataTypes.INTEGER },
|
||||
episode_count: { type: DataTypes.INTEGER },
|
||||
air_date: { type: DataTypes.DATE },
|
||||
|
||||
@@ -3,7 +3,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const { getSettings } = require('../services/settingsService');
|
||||
const { generatePreview, doGeneratePreview } = require('../services/mediaService');
|
||||
const { doGeneratePreview } = require('../services/mediaService');
|
||||
const { logToFile } = require('../services/logService');
|
||||
|
||||
const mediaRouter = express.Router();
|
||||
@@ -32,7 +32,7 @@ mediaRouter.get('/:category/:type/:size/:fileName', (req, res, next) => {
|
||||
// ? if so I make sure to change the extention to '_preview.jpg' (bcs all previews are jpg)
|
||||
let filePath = path.join(mediaPath, fileName);
|
||||
if (size == 'preview') {
|
||||
const previewFileName = fileName.split('.')[0] + '_preview.jpg'
|
||||
const previewFileName = fileName.split('.')[0] + (type == 'logos' ? '_preview.png' : '_preview.jpg')
|
||||
filePath = path.join(mediaPath, previewFileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ function doGeneratePreview(fileCategory, fileType, originalFileName, previewWidt
|
||||
const originalPath = path.join(mediaPath, originalFileName);
|
||||
|
||||
const fileNameWithoutExt = originalFileName.split('.')[0];
|
||||
const previewFileName = fileNameWithoutExt + '_preview.jpg'
|
||||
const previewFileName = fileNameWithoutExt + '_preview.jpg';
|
||||
const previewPath = path.join(mediaPath, previewFileName);
|
||||
|
||||
if (previewWidth == 0) {
|
||||
@@ -154,10 +154,16 @@ function doGeneratePreview(fileCategory, fileType, originalFileName, previewWidt
|
||||
if (fileType == 'logos') previewWidth = 300;
|
||||
}
|
||||
|
||||
return sharp(originalPath)
|
||||
.resize({ width: previewWidth })
|
||||
.jpeg({ quality: previewQuality })
|
||||
.toFile(previewPath);
|
||||
if (fileType == 'logos') {
|
||||
return sharp(originalPath)
|
||||
.resize({ width: previewWidth })
|
||||
.toFile(previewPath.replace('.jpg', '.png'));
|
||||
} else {
|
||||
return sharp(originalPath)
|
||||
.resize({ width: previewWidth })
|
||||
.jpeg({ quality: previewQuality })
|
||||
.toFile(previewPath);
|
||||
}
|
||||
}
|
||||
|
||||
function getMediaFolder() {
|
||||
|
||||
@@ -336,14 +336,19 @@ async function refrechEntry(entryId) {
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['id'],
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
});
|
||||
|
||||
@@ -437,7 +442,7 @@ async function refrechEntry(entryId) {
|
||||
await existingSeason.save();
|
||||
} else {
|
||||
// Create a new season
|
||||
await Season.create({
|
||||
existingSeason = await Season.create({
|
||||
tmdb_id: seasonData.id,
|
||||
entry_id: oldEntry.id,
|
||||
name: seasonData.name,
|
||||
@@ -547,26 +552,46 @@ async function refrechEntry(entryId) {
|
||||
// + end of: refrech logic
|
||||
|
||||
// ! returning the refreshed entry
|
||||
let includes = [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: Collection, as: 'collections' },
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name'],
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
}
|
||||
];
|
||||
if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' });
|
||||
// let includes = [
|
||||
// { model: EntryId, as: 'entryId' },
|
||||
// { model: EntryRating, as: 'entryRating' },
|
||||
// { model: EntrySeen, as: 'entrySeen' },
|
||||
// { model: Season, as: 'seasons' },
|
||||
// { model: Media, as: 'medias' },
|
||||
// { model: Collection, as: 'collections' },
|
||||
// {
|
||||
// model: Genre,
|
||||
// as: 'genres',
|
||||
// attributes: ['name'],
|
||||
// through: {
|
||||
// attributes: []
|
||||
// }
|
||||
// }
|
||||
// ];
|
||||
// if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' });
|
||||
|
||||
const updatedEntry = await Entry.findByPk(entryId, {
|
||||
include: includes,
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name'], // Only fetch the genre ID
|
||||
through: {
|
||||
attributes: [] // Do not fetch any attributes from the join table
|
||||
}
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
@@ -575,7 +600,7 @@ async function refrechEntry(entryId) {
|
||||
const plainEntry = updatedEntry.get({ plain: true });
|
||||
plainEntry.genres = plainEntry.genres.map(genre => genre.name);
|
||||
|
||||
return entryData;
|
||||
return plainEntry;
|
||||
}
|
||||
|
||||
/** This function will refresh data of series that have the status not 'ended/canceled' and have not been refreshed today
|
||||
@@ -585,6 +610,7 @@ async function SyncSeriesData() {
|
||||
const entries = await Entry.findAll({
|
||||
where: {
|
||||
is_tvseries: true,
|
||||
autoSync: true,
|
||||
last_fetch: {
|
||||
[Op.ne]: today
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user