B: add download of season media + maintenance
This commit is contained in:
1 parent
d799ef2368
commit
534572775f
6 files changed
+76
-16
No files matched your search
@@ -1,4 +1,5 @@
|
||||
const path = require('path');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
const Entry = require("../models/Entry");
|
||||
|
||||
@@ -10,12 +11,16 @@ const tmdbService = require("./tmdbService");
|
||||
const mediaService = require("./mediaService");
|
||||
const mediaDownloaderService = require("./mediaDownloaderService");
|
||||
const mediaOptimizerService = require("./mediaOptimizerService");
|
||||
const Season = require('../models/Season');
|
||||
const storageService = require('./storageService');
|
||||
const Media = require('../models/Media');
|
||||
|
||||
const _configService = configService;
|
||||
const _mediaService = mediaService;
|
||||
const _tmdbService = tmdbService;
|
||||
const _mediaOptimizerService = mediaOptimizerService;
|
||||
const _mediaDownloaderService = mediaDownloaderService;
|
||||
const _storageService = storageService;
|
||||
|
||||
class MediaManager {
|
||||
|
||||
@@ -113,6 +118,38 @@ class MediaManager {
|
||||
|
||||
return downloadedImages;
|
||||
}
|
||||
|
||||
async getSeasonMedia(season) {
|
||||
// const season = await Season.findOne(seasonId);
|
||||
|
||||
// if (!season) return NotFoundError(`Season with id ${seasonId} not found.`);
|
||||
|
||||
const url = `https://image.tmdb.org/t/p/original${season.poster_path}`;
|
||||
const file = await _mediaDownloaderService.downloadFile(url);
|
||||
|
||||
const uniqueFilename = uuidv4();
|
||||
const extension = season.poster_path.split('.').pop();
|
||||
const filename = `${uniqueFilename}.${extension}`;
|
||||
|
||||
const dataPath = _configService.getSettings().userDataPath;
|
||||
const fullFilePath = path.join(dataPath, 'images', 'seasons', 'posters', filename)
|
||||
|
||||
_storageService.storeFile(file, fullFilePath).then(async () => {
|
||||
// create media object
|
||||
await Media.create({
|
||||
mediaable: 'season',
|
||||
mediaableId: season.id,
|
||||
type: 'poster',
|
||||
path: filename,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
});
|
||||
|
||||
// optimine file
|
||||
|
||||
}).catch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new MediaManager();
|
||||
Reference in new issue
Block a user