@meuuhdia/video-player 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/modules/player.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { MeuuhdiaControls } from "./controls.js";
2
- import { locale } from "../locale/fr.js";
2
+ import { locale as locale_en } from "../locale/en.js";
3
+ import { locale as locale_fr } from "../locale/fr.js";
4
+ import { locale as locale_it } from "../locale/it.js";
3
5
 
4
6
  class MeuuhdiaPlayer {
5
7
  /**
@@ -43,8 +45,21 @@ class MeuuhdiaPlayer {
43
45
  * @param {Node} meuuhdia
44
46
  */
45
47
  constructor(meuuhdia) {
48
+ let inherit_locale = meuuhdia.closest("[lang]") ? meuuhdia.closest("[lang]").getAttribute("lang").split("-")[0] : "en";
49
+ let current_locale = meuuhdia.dataset.locale ?? inherit_locale;
50
+
51
+ switch(current_locale) {
52
+ case "fr":
53
+ this.locale = locale_fr;
54
+ break;
55
+ case "it":
56
+ this.locale = locale_it;
57
+ break;
58
+ default:
59
+ this.locale = locale_en;
60
+ }
61
+
46
62
  this.meuuhdia = meuuhdia;
47
- this.locale = locale;
48
63
  }
49
64
 
50
65
  /**
@@ -72,7 +87,15 @@ class MeuuhdiaPlayer {
72
87
  this.wrapper.setAttribute("lang", this.locale.code);
73
88
 
74
89
  this.video = this.meuuhdia.querySelector("video");
75
- this.video.querySelectorAll("track").forEach(track => track.id = track.getAttribute("kind") + "_" + track.getAttribute("srclang"));
90
+ this.video.querySelectorAll("track").forEach(track => {
91
+ const allowed_types = ["captions", "subtitles", "descriptions"];
92
+ var current_type = track.getAttribute("kind");
93
+ var extension = track.getAttribute("src")?.split(".").pop();
94
+
95
+ if(allowed_types.includes(current_type) && ("descriptions" != current_type || "json" == extension)) {
96
+ track.id = current_type + "_" + track.getAttribute("srclang");
97
+ } else track.remove();
98
+ });
76
99
 
77
100
  let Controls = new MeuuhdiaControls(this.locale, this.wrapper, this.video);
78
101
  this.controls = Controls.controls;
@@ -105,14 +105,18 @@ class MeuuhdiaTranscription {
105
105
  for(let line in transcription_lines) {
106
106
  let paragraph = document.createElement("li");
107
107
 
108
- let infos_data = line.split(" ");
108
+ // ? "mm:ss Speaker": only the first space separates time from speaker (multi-word names allowed)
109
+ let separator = line.indexOf(" ");
110
+ let time = -1 === separator ? line : line.slice(0, separator);
111
+ let speaker = -1 === separator ? "" : line.slice(separator + 1).trim();
112
+
109
113
  let infos = document.createElement("button");
110
- infos.dataset.time = MeuuhdiaTime.convertTextToSeconds(infos_data[0]);
114
+ infos.dataset.time = MeuuhdiaTime.convertTextToSeconds(time);
111
115
  infos.classList.add("meuuhdia_transcription_info");
112
116
  infos.addEventListener("click", (evt) => video.currentTime = evt.currentTarget.dataset.time);
113
- MeuuhdiaTime.populateTimeNode(locale, infos, null, infos_data[0]);
117
+ MeuuhdiaTime.populateTimeNode(locale, infos, null, time);
114
118
  let infos_voice = document.createElement("span");
115
- infos_voice.textContent = (2 === infos_data.length) ? (" " + infos_data[1] + ":") : ":";
119
+ infos_voice.textContent = speaker ? (" " + speaker + ":") : ":";
116
120
  infos.appendChild(infos_voice);
117
121
  paragraph.appendChild(infos);
118
122
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@meuuhdia/video-player",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "inclusive video player",
5
5
  "type": "module",
6
6
  "main": "meuuhdia.js",
7
7
  "author": "Séverine Féret",
8
- "license": "AGPL-3.0-or-later",
8
+ "license": "GPL-2.0-or-later",
9
9
  "exports": {
10
10
  ".": "./meuuhdia.js"
11
11
  },