Backend:
- add download of episode media function - serving of episodes/seasons files - pulling seasons/episodes media on entry create - maintenance for seasons/episodes media
This commit is contained in:
1 parent
534572775f
commit
4e20c5320b
6 files changed
+58
-31
No files matched your search
@@ -120,10 +120,7 @@ class MediaManager {
|
||||
}
|
||||
|
||||
async getSeasonMedia(season) {
|
||||
// const season = await Season.findOne(seasonId);
|
||||
|
||||
// if (!season) return NotFoundError(`Season with id ${seasonId} not found.`);
|
||||
|
||||
if (!season.poster_path) return;
|
||||
const url = `https://image.tmdb.org/t/p/original${season.poster_path}`;
|
||||
const file = await _mediaDownloaderService.downloadFile(url);
|
||||
|
||||
@@ -135,7 +132,6 @@ class MediaManager {
|
||||
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,
|
||||
@@ -144,9 +140,32 @@ class MediaManager {
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
});
|
||||
console.log(`File created for season: ${filename}`);
|
||||
}).catch();
|
||||
}
|
||||
|
||||
// optimine file
|
||||
async getEpisodenMedia(episode) {
|
||||
if (!episode.still_path) return;
|
||||
const url = `https://image.tmdb.org/t/p/original${episode.still_path}`;
|
||||
const file = await _mediaDownloaderService.downloadFile(url);
|
||||
|
||||
const uniqueFilename = uuidv4();
|
||||
const extension = episode.still_path.split('.').pop();
|
||||
const filename = `${uniqueFilename}.${extension}`;
|
||||
|
||||
const dataPath = _configService.getSettings().userDataPath;
|
||||
const fullFilePath = path.join(dataPath, 'images', 'episodes', 'stills', filename)
|
||||
|
||||
_storageService.storeFile(file, fullFilePath).then(async () => {
|
||||
await Media.create({
|
||||
mediaable: 'episode',
|
||||
mediaableId: episode.id,
|
||||
type: 'still',
|
||||
path: filename,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
});
|
||||
console.log(`File created for episode: ${filename}`);
|
||||
}).catch();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user