Bug 1766273 - Add PiP subtitle support for Disney+. r=mhowell

Subtitle structure of disney+ seems to be the following.

```
<div class="dss-hls-subtitle-overlay">
  <div class="dss-subtitle-renderer-wrapper">
    <div class="dss-subtitle-renderer-cue-positioning-box">
      <div class="dss-subtitle-renderer-cue-window">
        <span class="dss-subtitle-renderer-cue">
          <span class="dss-subtitle-renderer-line">...</span>
          <span class="dss-subtitle-renderer-line">...</span>
```

Differential Revision: https://phabricator.services.mozilla.com/D149849
This commit is contained in:
Makoto Kato 2022-07-06 04:46:08 +00:00
parent c3aa2f7ca2
commit ddd50edc4b
3 changed files with 47 additions and 0 deletions

View File

@ -61,6 +61,12 @@ let AVAILABLE_PIP_OVERRIDES;
},
},
disneyplus: {
"https://*.disneyplus.com/*": {
videoWrapperScriptPath: "video-wrappers/disneyplus.js",
},
},
funimation: {
"https://*.funimation.com/*": {
videoWrapperScriptPath: "video-wrappers/funimation.js",

View File

@ -31,6 +31,7 @@ FINAL_TARGET_FILES.features["pictureinpicture@mozilla.org"]["video-wrappers"] +=
"video-wrappers/airmozilla.js",
"video-wrappers/bbc.js",
"video-wrappers/dailymotion.js",
"video-wrappers/disneyplus.js",
"video-wrappers/funimation.js",
"video-wrappers/hbomax.js",
"video-wrappers/hotstar.js",

View File

@ -0,0 +1,40 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
class PictureInPictureVideoWrapper {
setCaptionContainerObserver(video, updateCaptionsFunction) {
let container = document.querySelector(".dss-hls-subtitle-overlay");
if (container) {
const callback = () => {
let textNodeList = container.querySelectorAll(
".dss-subtitle-renderer-line"
);
if (!textNodeList.length) {
updateCaptionsFunction("");
return;
}
updateCaptionsFunction(
Array.from(textNodeList, x => x.textContent).join("\n")
);
};
// immediately invoke the callback function to add subtitles to the PiP window
callback();
let captionsObserver = new MutationObserver(callback);
captionsObserver.observe(container, {
attributes: false,
childList: true,
subtree: true,
});
}
}
}
this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;