Skip to content

Commit 56fe50b

Browse files
author
Mindless999
committed
Fix metadata so plex understands it for release date
1 parent 738f929 commit 56fe50b

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/lib/Video.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ export class Video extends Attachment {
242242
season = match[1];
243243
episode = match[2];
244244
}
245+
// Determine the unique episode number based on releaseDate
246+
const releaseDate = this.releaseDate;
245247
const nfo = builder
246248
.create()
247249
.ele("episodedetails")
@@ -258,7 +260,10 @@ export class Video extends Attachment {
258260
.txt(htmlToText(this.description))
259261
.up()
260262
.ele("aired") // format: yyyy-mm-dd required for Kodi/Plex
261-
.txt(this.releaseDate.getFullYear().toString() + "-" + nPad(this.releaseDate.getMonth() + 1) + "-" + nPad(this.releaseDate.getDate()))
263+
.txt(`${releaseDate.getUTCFullYear()}-${nPad(releaseDate.getUTCMonth() + 1)}-${nPad(releaseDate.getUTCDate())}`)
264+
.up()
265+
.ele("originallyavailable") // plesk NFO uses Original vailable for actual air dates, if it uses NFO
266+
.txt(`${releaseDate.getUTCFullYear()}-${nPad(releaseDate.getUTCMonth() + 1)}-${nPad(releaseDate.getUTCDate())}`)
262267
.up()
263268
.ele("season")
264269
.txt(season)
@@ -367,14 +372,26 @@ export class Video extends Attachment {
367372
await unlink(this.muxedPath).catch(nll);
368373

369374
const description = htmlToText(this.description);
375+
const releaseDate = this.releaseDate;
376+
const year = releaseDate.getUTCFullYear();
377+
const yearStart = new Date(Date.UTC(year, 0, 1));
378+
const episode = Math.floor((releaseDate.getTime() - yearStart.getTime()) / 1000);
379+
const airedDate = new Date(releaseDate);
380+
const creationTime = airedDate.toISOString().replace(/\.\d{3}Z$/, "Z");
381+
const airedDateStr = `${airedDate.getUTCFullYear()}-${nPad(airedDate.getUTCMonth() + 1)}-${nPad(airedDate.getUTCDate())}`; // format: yyyy-mm-dd required for Kodi/Plex
370382
const metadata = {
371-
title: this.videoTitle,
372-
AUTHOR: this.channelTitle,
373-
YEAR: this.releaseDate.getFullYear().toString(),
374-
date: `${this.releaseDate.getFullYear().toString()}${nPad(this.releaseDate.getMonth() + 1)}${nPad(this.releaseDate.getDate())}`,
375-
description: description,
376-
synopsis: description,
377-
};
383+
title: this.videoTitle,
384+
AUTHOR: this.channelTitle,
385+
YEAR: year.toString(),
386+
date: airedDateStr,
387+
description: description,
388+
synopsis: description,
389+
show: this.channelTitle,
390+
season_number: year.toString(),
391+
episode_id: episode.toString(),
392+
creation_time: creationTime,
393+
};
394+
const metadataArgs = Object.entries(metadata).flatMap(([key, value]) => ["-metadata", `${key}=${value}`]);
378395
const metadataFilePath = `${this.folderPath}/${Math.random()}.ffmeta`;
379396
const metadataContent = Object.entries(metadata)
380397
.map(([key, value]) => `${key}=${value.replaceAll(/\n/g, "\\\n")}`)
@@ -394,6 +411,7 @@ export class Video extends Attachment {
394411
"0",
395412
"-map_metadata",
396413
"1",
414+
...metadataArgs,
397415
"-c",
398416
"copy",
399417
this.muxedPath,
@@ -410,7 +428,7 @@ export class Video extends Attachment {
410428
// Remove the partial file when done
411429
await unlink(this.partialPath);
412430
// Set the files update time to when the video was released
413-
await utimes(this.muxedPath, new Date(), this.releaseDate);
431+
await utimes(this.muxedPath, new Date(), releaseDate);
414432

415433
(await this.attachmentInfo()).muxedBytes = await Video.pathBytes(this.muxedPath);
416434
} finally {

0 commit comments

Comments
 (0)