Skip to content

Commit

Permalink
fix(chapters): removed duplicate chapters by id (#4810)
Browse files Browse the repository at this point in the history
fixes #4750

Solved by creating a `Set` for filtering out deplicate elements.

Need confirmation, Shouldn't we add an `assert` for `language` argument
passed to
https://github.com/shaka-project/shaka-player/blob/76f96b9fee2dc43b03f6803dd80c51fdc5b73a9e/lib/player.js#L4340-L4342
  • Loading branch information
WINOFFRG authored and joeyparrish committed Dec 14, 2022
1 parent 5590eed commit 992f9d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Prakash <[email protected]>
Robert Colantuoni <[email protected]>
Robert Galluccio <[email protected]>
Rodolphe Breton <[email protected]>
Rohan Gupta <[email protected]>
Roi Lipman <[email protected]>
Roksolana Ivanyshyn <[email protected]>
Rostislav Hejduk <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Robert Colantuoni <[email protected]>
Robert Galluccio <[email protected]>
Rodolphe Breton <[email protected]>
Rohit Makasana <[email protected]>
Rohan Gupta <[email protected]>
Roi Lipman <[email protected]>
Roksolana Ivanyshyn <[email protected]>
Rostislav Hejduk <[email protected]>
Expand Down
11 changes: 10 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3952,16 +3952,25 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return [];
}
const chapters = [];
const uniqueChapters = new Set();
for (const chaptersTrack of chaptersTracksWithLanguage) {
if (chaptersTrack && chaptersTrack.cues) {
for (const cue of chaptersTrack.cues) {
let id = cue.id;
if (!id || id == '') {
id = cue.startTime + '-' + cue.endTime + '-' + cue.text;
}
/** @type {shaka.extern.Chapter} */
const chapter = {
id: id,
title: cue.text,
startTime: cue.startTime,
endTime: cue.endTime,
};
chapters.push(chapter);
if (!uniqueChapters.has(id)) {
chapters.push(chapter);
uniqueChapters.add(id);
}
}
}
}
Expand Down

0 comments on commit 992f9d6

Please sign in to comment.