Skip to content

Commit

Permalink
Quick fix for unsupported marker types
Browse files Browse the repository at this point in the history
Turns out there's a 'commercial' marker type for DVR content, and
MarkerBreakdown's deltaFromType is too strict and throws when this
marker type is found. Instead, just ignore unsupported marker types, and
hopefully add better handling in the future.

Also bump for 2.1.2 for a quick release
  • Loading branch information
danrahn committed Mar 4, 2023
1 parent 1cefff2 commit f0ac577
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Server/Commands/QueryCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class QueryCommands {

const rawMarkers = await PlexQueries.getMarkersForItems(keys);
for (const rawMarker of rawMarkers) {
markers[rawMarker.parent_id].push(new MarkerData(rawMarker));
// TODO: better handing of non intros/credits (i.e. commercials)
if (MarkerType.supportedType(rawMarker.marker_type)) {
markers[rawMarker.parent_id].push(new MarkerData(rawMarker));
}
}

return markers;
Expand Down Expand Up @@ -196,7 +199,13 @@ class QueryCommands {
let countCur = 0;
// See MarkerBreakdown.js
const bucketDelta = (markerType) => markerType == MarkerType.Intro ? 1 : (1 << 16);

for (const row of rows) {
// TODO: better handing of non intros/credits (i.e. commercials)
if (!MarkerType.supportedType(row.marker_type)) {
continue;
}

if (row.parent_id == idCur) {
if (row.tag_id == PlexQueries.markerTagId()) {
// See MarkerBreakdown.js
Expand Down
7 changes: 7 additions & 0 deletions Server/MarkerCacheManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Log } from '../Shared/ConsoleLog.js';

import MarkerBreakdown from '../Shared/MarkerBreakdown.js';
import { MarkerType } from '../Shared/PlexTypes.js';

/** @typedef {!import('./DatabaseWrapper').default} DatabaseWrapper */
/** @typedef {!import('./PlexQueryManager').RawMarkerData} RawMarkerData */
Expand Down Expand Up @@ -101,6 +102,12 @@ class BaseItemNode extends MarkerNodeBase {
// TODO: temporary. Make sure that base items only have a single "active" bucket, it doesn't
// make sense for a single episode/movie to have multiple buckets.
Log.assert(this.markerBreakdown.buckets() == 1);
// Silently ignore unsupported marker types.
// TODO: better support for unsupported types (i.e. commercials)
if (!MarkerType.supportedType(markerData.marker_type)) {
return;
}

const deltaReal = MarkerBreakdown.deltaFromType(multiplier, markerData.marker_type);
this.markerBreakdown.delta(this.#currentKey, deltaReal);
this.#currentKey += deltaReal;
Expand Down
4 changes: 3 additions & 1 deletion Shared/MarkerBreakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class MarkerBreakdown {
case MarkerType.Credits:
return delta << CreditsShift;
default:
throw new Error(`Invalid marker type ${markerType}`);
// Unexpected, but just log an error and treat it as an intro.
Log.error(`Invalid marker type ${markerType}`);
return delta;
}
}

Expand Down
3 changes: 3 additions & 0 deletions Shared/PlexTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class MovieData extends TopLevelData {
}
}

const _supportedMarkerTypes = new Set(['intro', 'credits']);

/**
* Possible marker types
* @enum */
Expand All @@ -458,6 +460,7 @@ const MarkerType = {
Intro : 'intro',
/** @readonly */
Credits : 'credits',
supportedType : (markerType) => _supportedMarkerTypes.has(markerType)
};

/**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "marker-editor-for-plex",
"type": "module",
"version": "2.1.1",
"version": "2.1.2",
"description": "Add, edit, and delete Plex markers",
"main": "app.js",
"scripts": {
Expand Down

0 comments on commit f0ac577

Please sign in to comment.