Fixed Plex media production year parsing.

This commit is contained in:
Abdulmhsen B. A. A
2022-06-16 21:11:37 +03:00
parent fbdf97b431
commit b52efd522f
3 changed files with 61 additions and 18 deletions

View File

@@ -139,6 +139,11 @@ final class ParseWebhook
$obj = ag($this->getItemDetails(context: $context, id: $id), 'MediaContainer.Metadata.0', []);
$year = (int)ag($obj, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($obj, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
$guids = $guid->get(ag($item, 'Guid', []), context: [
'item' => [
'id' => ag($item, 'ratingKey'),
@@ -147,7 +152,7 @@ final class ParseWebhook
iFace::TYPE_MOVIE => sprintf(
'%s (%s)',
ag($item, ['title', 'originalTitle'], '??'),
ag($item, 'year', '0000')
0 === $year ? '0000' : $year,
),
iFace::TYPE_EPISODE => sprintf(
'%s - (%sx%s)',
@@ -156,7 +161,7 @@ final class ParseWebhook
str_pad((string)ag($item, 'index', 0), 3, '0', STR_PAD_LEFT),
),
},
'year' => ag($item, ['grandParentYear', 'parentYear', 'year']),
'year' => 0 === $year ? '0000' : $year,
'plex_id' => str_starts_with(ag($item, 'guid', ''), 'plex://') ? ag($item, 'guid') : 'none',
],
]);

View File

@@ -46,6 +46,11 @@ trait PlexActionTrait
throw new RuntimeException('No date was set on object.');
}
$year = (int)ag($item, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($item, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
if (null === ag($item, 'Guid')) {
$item['Guid'] = [['id' => ag($item, 'guid')]];
} else {
@@ -62,7 +67,7 @@ trait PlexActionTrait
PlexClient::TYPE_MOVIE => sprintf(
'%s (%s)',
ag($item, ['title', 'originalTitle'], '??'),
ag($item, 'year', '0000')
0 === $year ? '0000' : $year,
),
PlexClient::TYPE_EPISODE => sprintf(
'%s - (%sx%s)',
@@ -71,7 +76,7 @@ trait PlexActionTrait
str_pad((string)ag($item, 'index', 0), 3, '0', STR_PAD_LEFT),
),
},
'year' => ag($item, ['grandParentYear', 'parentYear', 'year']),
'year' => 0 === $year ? '0000' : $year,
'plex_id' => str_starts_with(ag($item, 'guid', ''), 'plex://') ? ag($item, 'guid') : 'none',
],
]);
@@ -129,9 +134,9 @@ trait PlexActionTrait
}
}
if (null !== ($mediaYear = ag($item, ['grandParentYear', 'parentYear', 'year'])) && !empty($mediaYear)) {
$builder[iState::COLUMN_YEAR] = (int)$mediaYear;
$metadata[iState::COLUMN_YEAR] = (string)$mediaYear;
if (0 !== $year) {
$builder[iState::COLUMN_YEAR] = (int)$year;
$metadata[iState::COLUMN_YEAR] = (string)$year;
}
if (null !== ($mediaPath = ag($item, 'Media.0.Part.0.file')) && !empty($mediaPath)) {
@@ -194,14 +199,19 @@ trait PlexActionTrait
$json = ag($this->getItemDetails(context: $context, id: $id), 'MediaContainer.Metadata.0', []);
$year = (int)ag($json, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($json, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
$logContext['item'] = [
'id' => ag($json, 'ratingKey'),
'title' => sprintf(
'%s (%s)',
ag($json, ['title', 'originalTitle'], '??'),
ag($json, 'year', '0000')
0 === $year ? '0000' : $year,
),
'year' => ag($json, ['grandParentYear', 'parentYear', 'year'], '0000'),
'year' => 0 === $year ? '0000' : $year,
'type' => ag($json, 'type', 'unknown'),
];

View File

@@ -295,8 +295,8 @@ class PlexServer implements ServerInterface
foreach (ag($leaf, 'Metadata', []) as $item) {
$watchedAt = ag($item, 'lastViewedAt');
$year = (int)ag($item, 'year', 0);
$year = (int)ag($item, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($item, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
@@ -338,10 +338,9 @@ class PlexServer implements ServerInterface
$metadata = ag($item, 'MediaContainer.Metadata.0', []);
$type = ag($metadata, 'type');
$watchedAt = ag($metadata, 'lastViewedAt');
$year = (int)ag($metadata, ['year', 'parentYear', 'grandparentYear'], 0);
$year = (int)ag($metadata, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($metadata, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
@@ -482,6 +481,11 @@ class PlexServer implements ServerInterface
...$context,
];
$year = (int)ag($item, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($item, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
if (true === ag($this->options, Options::DEBUG_TRACE)) {
$data['trace'] = $item;
}
@@ -493,7 +497,7 @@ class PlexServer implements ServerInterface
'type' => ucfirst(ag($item, 'type', 'unknown')),
'url' => (string)$url,
'title' => ag($item, $possibleTitlesList, '??'),
'year' => ag($item, 'year'),
'year' => $year,
'guids' => [],
'match' => [
'titles' => [],
@@ -602,10 +606,15 @@ class PlexServer implements ServerInterface
continue;
}
$year = (int)ag($entity, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($entity, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
$context['item'] = [
'id' => ag($entity, 'ratingKey'),
'title' => ag($entity, ['title', 'originalTitle'], '??'),
'year' => ag($entity, 'year', '0000'),
'year' => $year,
'type' => ag($entity, 'type'),
'url' => (string)$url,
];
@@ -1545,13 +1554,18 @@ class PlexServer implements ServerInterface
Data::increment($this->getName(), $library . '_total');
Data::increment($this->getName(), $type . '_total');
$year = (int)ag($item, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($item, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
$context['item'] = [
'id' => ag($item, 'ratingKey'),
'title' => match ($type) {
iFace::TYPE_MOVIE => sprintf(
'%s (%s)',
ag($item, ['title', 'originalTitle'], '??'),
ag($item, 'year', '0000')
0 === $year ? '0000' : $year,
),
iFace::TYPE_EPISODE => sprintf(
'%s - (%sx%s)',
@@ -1683,13 +1697,18 @@ class PlexServer implements ServerInterface
Data::increment($this->getName(), $library . '_total');
Data::increment($this->getName(), $type . '_total');
$year = (int)ag($item, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($item, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
$context['item'] = [
'id' => ag($item, 'ratingKey'),
'title' => match ($type) {
iFace::TYPE_MOVIE => sprintf(
'%s (%s)',
ag($item, ['title', 'originalTitle'], '??'),
ag($item, 'year', '0000')
0 === $year ? '0000' : $year,
),
iFace::TYPE_EPISODE => sprintf(
'%s - (%sx%s)',
@@ -1882,10 +1901,19 @@ class PlexServer implements ServerInterface
$item['Guid'][] = ['id' => $item['guid']];
}
$year = (int)ag($item, ['grandParentYear', 'parentYear', 'year'], 0);
if (0 === $year && null !== ($airDate = ag($item, 'originallyAvailableAt'))) {
$year = (int)makeDate($airDate)->format('Y');
}
$context['item'] = [
'id' => ag($item, 'ratingKey'),
'title' => sprintf('%s (%s)', ag($item, ['title', 'originalTitle'], '??'), ag($item, 'year', '0000')),
'year' => ag($item, 'year', '0000'),
'title' => sprintf(
'%s (%s)',
ag($item, ['title', 'originalTitle'], '??'),
0 === $year ? '0000' : $year,
),
'year' => 0 === $year ? '0000' : $year,
'type' => ag($item, 'type', 'unknown'),
];