PageSourceSearch

https://laziar.com/assets/videojs/plugins/cjs/youtube.js

js laziar.com collected 2026-09-28 08:59:08 UTC 15,628 bytes, 471 lines download raw bytes

1/**
2 * Copyright (c) 2024 The Nuevodevel Team. All rights reserved.
3 * Youtube plugin for video.js
4 * Version 1.7.0
5 */
6/* eslint-disable */ /* eslint-env node */ function _interopDefault(e) {
7  return e && 'object' === typeof e && 'default' in e ? e.default : e;
8}
9var videojs = _interopDefault(require('video.js'));
10'undefined' !== typeof window && (window.videojs = videojs);
11var _isOnMobile = videojs.browser.IS_IOS || videojs.browser.IS_NATIVE_ANDROID,
12  Tech = videojs.getTech('Tech');
13class Youtube extends Tech {
14  constructor(e, t) {
15    super(e, t);
16    this.setPoster(e.poster);
17    this.setSrc(this.options_.source, !0);
18    this.setTimeout(
19      function () {
20        if (this.el_) {
21          this.el_.parentNode.className += ' vjs-youtube';
22          _isOnMobile && (this.el_.parentNode.className += ' vjs-youtube-mobile');
23          Youtube.isApiReady ? this.initYTPlayer() : Youtube.apiReadyQueue.push(this);
24        }
25      }.bind(this)
26    );
27  }
28  dispose() {
29    if (this.ytPlayer) {
30      this.ytPlayer.stopVideo && this.ytPlayer.stopVideo();
31      this.ytPlayer.destroy && this.ytPlayer.destroy();
32    } else {
33      var e = Youtube.apiReadyQueue.indexOf(this);
34      -1 !== e && Youtube.apiReadyQueue.splice(e, 1);
35    }
36    this.ytPlayer = null;
37    this.el_.parentNode.className = this.el_.parentNode.className
38      .replace(' vjs-youtube', '')
39      .replace(' vjs-youtube-mobile', '');
40    this.el_.parentNode.removeChild(this.el_);
41    Tech.prototype.dispose.call(this);
42  }
43  createEl() {
44    var e = document.createElement('div');
45    e.setAttribute('id', this.options_.techId);
46    e.setAttribute('style', 'width:100%;height:100%;top:0;left:0;position:absolute');
47    e.setAttribute('class', 'vjs-tech');
48    var t = document.createElement('div');
49    t.appendChild(e);
50    if (!_isOnMobile && !this.options_.ytControls) {
51      e = document.createElement('div');
52      e.setAttribute('class', 'vjs-iframe-blocker');
53      e.setAttribute('style', 'position:absolute;top:0;left:0;width:100%;height:100%');
54      e.onclick = function () {
55        this.pause();
56      }.bind(this);
57      t.appendChild(e);
58    }
59    return t;
60  }
61  initYTPlayer() {
62    var t = {
63      controls: 0,
64      modestbranding: 1,
65      rel: 0,
66      showinfo: 0,
67      loop: this.options_.loop ? 1 : 0,
68    };
69    _isOnMobile && (this.options_.ytControls = 1);
70    'undefined' !== typeof this.options_.autohide && (t.autohide = this.options_.autohide);
71    'undefined' !== typeof this.options_.cc_load_policy &&
72      (t.cc_load_policy = this.options_.cc_load_policy);
73    'undefined' !== typeof this.options_.ytControls && (t.controls = this.options_.ytControls);
74    'undefined' !== typeof this.options_.disablekb && (t.disablekb = this.options_.disablekb);
75    'undefined' !== typeof this.options_.color && (t.color = this.options_.color);
76    t.controls ? 'undefined' !== typeof this.options_.fs && (t.fs = this.options_.fs) : (t.fs = 0);
77    if (-1 !== this.options_.source.src.indexOf('end=')) {
78      var e = this.options_.source.src.match(/end=([0-9]*)/);
79      this.options_.end = parseInt(e[1]);
80    }
81    'undefined' !== typeof this.options_.end && (t.end = this.options_.end);
82    'undefined' !== typeof this.options_.hl
83      ? (t.hl = this.options_.hl)
84      : 'undefined' !== typeof this.options_.language &&
85        (t.hl = this.options_.language.substr(0, 2));
86    'undefined' !== typeof this.options_.iv_load_policy &&
87      (t.iv_load_policy = this.options_.iv_load_policy);
88    'undefined' !== typeof this.options_.list
89      ? (t.list = this.options_.list)
90      : this.url && 'undefined' !== typeof this.url.listId && (t.list = this.url.listId);
91    'undefined' !== typeof this.options_.listType && (t.listType = this.options_.listType);
92    'undefined' !== typeof this.options_.modestbranding &&
93      (t.modestbranding = this.options_.modestbranding);
94    'undefined' !== typeof this.options_.playlist && (t.playlist = this.options_.playlist);
95    'undefined' !== typeof this.options_.playsinline && (t.playsinline = this.options_.playsinline);
96    'undefined' !== typeof this.options_.rel && (t.rel = this.options_.rel);
97    'undefined' !== typeof this.options_.showinfo && (t.showinfo = this.options_.showinfo);
98    if (-1 !== this.options_.source.src.indexOf('start=')) {
99      e = this.options_.source.src.match(/start=([0-9]*)/);
100      this.options_.start = parseInt(e[1]);
101    }
102    'undefined' !== typeof this.options_.start && (t.start = this.options_.start);
103    'undefined' !== typeof this.options_.theme && (t.theme = this.options_.theme);
104    if ('undefined' !== typeof this.options_.customVars) {
105      var i = this.options_.customVars;
106      Object.keys(i).forEach(function (e) {
107        t[e] = i[e];
108      });
109    }
110    this.activeVideoId = this.url ? this.url.videoId : null;
111    this.activeList = t.list;
112    e = {
113      videoId: this.activeVideoId,
114      playerVars: t,
115      events: {
116        onReady: this.onPlayerReady.bind(this),
117        onPlaybackQualityChange: this.onPlayerPlaybackQualityChange.bind(this),
118        onPlaybackRateChange: this.onPlayerPlaybackRateChange.bind(this),
119        onStateChange: this.onPlayerStateChange.bind(this),
120        onVolumeChange: this.onPlayerVolumeChange.bind(this),
121        onError: this.onPlayerError.bind(this),
122      },
123    };
124    'undefined' !== typeof this.options_.enablePrivacyEnhancedMode &&
125      this.options_.enablePrivacyEnhancedMode &&
126      (e.host = 'https://www.youtube-nocookie.com');
127    this.ytPlayer = new YT.Player(this.options_.techId, e);
128  }
129  onPlayerReady() {
130    this.options_.muted && this.ytPlayer.mute();
131    this.ytPlayer.getAvailablePlaybackRates().length > 1 && (this.featuresPlaybackRate = !0);
132    this.playerReady_ = !0;
133    this.triggerReady();
134    if (this.playOnReady) this.play();
135    else if (this.cueOnReady) {
136      this.cueVideoById_(this.url.videoId);
137      this.activeVideoId = this.url.videoId;
138    }
139  }
140  onPlayerPlaybackQualityChange() {}
141  onPlayerPlaybackRateChange() {
142    this.trigger('ratechange');
143  }
144  onPlayerStateChange(e) {
145    e = e.data;
146    if (e !== this.lastState && !this.errorNumber)
147      switch ((this.lastState = e)) {
148        case -1:
149          this.trigger('loadstart');
150          this.trigger('loadedmetadata');
151          this.trigger('durationchange');
152          this.trigger('ratechange');
153          break;
154        case YT.PlayerState.ENDED:
155          this.trigger('ended');
156          break;
157        case YT.PlayerState.PLAYING:
158          this.trigger('timeupdate');
159          this.trigger('durationchange');
160          this.trigger('playing');
161          this.trigger('play');
162          this.isSeeking && this.onSeeked();
163          break;
164        case YT.PlayerState.PAUSED:
165          this.trigger('canplay');
166          this.isSeeking ? this.onSeeked() : this.trigger('pause');
167          break;
168        case YT.PlayerState.BUFFERING:
169          this.player_.trigger('timeupdate');
170          this.player_.trigger('waiting');
171      }
172  }
173  onPlayerVolumeChange() {
174    this.trigger('volumechange');
175  }
176  onPlayerError(e) {
177    this.errorNumber = e.data;
178    this.trigger('pause');
179    this.trigger('error');
180  }
181  error() {
182    var e = 1e3 + this.errorNumber;
183    switch (this.errorNumber) {
184      case 5:
185        return { code: e, message: 'Error while trying to play the video' };
186      case 2:
187      case 100:
188        return { code: e, message: 'Unable to find the video' };
189      case 101:
190      case 150:
191        return {
192          code: e,
193          message: 'Playback on other Websites has been disabled by the video owner.',
194        };
195    }
196    return { code: e, message: 'YouTube unknown error (' + this.errorNumber + ')' };
197  }
198  loadVideoById_(e) {
199    e = { videoId: e };
200    this.options_.start && (e.startSeconds = this.options_.start);
201    this.options_.end && (e.endSeconds = this.options_.end);
202    this.ytPlayer.loadVideoById(e);
203  }
204  cueVideoById_(e) {
205    e = { videoId: e };
206    this.options_.start && (e.startSeconds = this.options_.start);
207    this.options_.end && (e.endSeconds = this.options_.end);
208    this.ytPlayer.cueVideoById(e);
209  }
210  src(e) {
211    e && this.setSrc({ src: e });
212    return this.source;
213  }
214  poster() {
215    return _isOnMobile ? null : this.poster_;
216  }
217  setPoster(e) {
218    this.poster_ = e;
219  }
220  setSrc(e) {
221    if (e && e.src) {
222      delete this.errorNumber;
223      this.source = e;
224      this.url = Youtube.parseUrl(e.src);
225      if (!this.options_.poster && this.url.videoId) {
226        this.poster_ = 'https://img.youtube.com/vi/' + this.url.videoId + '/0.jpg';
227        this.trigger('posterchange');
228        this.checkHighResPoster();
229      }
230      if (this.options_.autoplay && !_isOnMobile)
231        this.isReady_ ? this.play() : (this.playOnReady = !0);
232      else if (this.activeVideoId !== this.url.videoId)
233        if (this.isReady_) {
234          this.cueVideoById_(this.url.videoId);
235          this.activeVideoId = this.url.videoId;
236        } else this.cueOnReady = !0;
237    }
238  }
239  autoplay() {
240    return this.options_.autoplay;
241  }
242  setAutoplay(e) {
243    this.options_.autoplay = e;
244  }
245  loop() {
246    return this.options_.loop;
247  }
248  setLoop(e) {
249    this.options_.loop = e;
250  }
251  play() {
252    if (this.url && this.url.videoId) {
253      this.wasPausedBeforeSeek = !1;
254      if (this.isReady_) {
255        if (this.url.listId)
256          if (this.activeList === this.url.listId) this.ytPlayer.playVideo();
257          else {
258            this.ytPlayer.loadPlaylist(this.url.listId);
259            this.activeList = this.url.listId;
260          }
261        if (this.activeVideoId === this.url.videoId) this.ytPlayer.playVideo();
262        else {
263          this.loadVideoById_(this.url.videoId);
264          this.activeVideoId = this.url.videoId;
265        }
266      } else {
267        this.trigger('waiting');
268        this.playOnReady = !0;
269      }
270    }
271  }
272  pause() {
273    this.ytPlayer && this.ytPlayer.pauseVideo();
274  }
275  paused() {
276    return (
277      !this.ytPlayer ||
278      (this.lastState !== YT.PlayerState.PLAYING && this.lastState !== YT.PlayerState.BUFFERING)
279    );
280  }
281  currentTime() {
282    return this.ytPlayer ? this.ytPlayer.getCurrentTime() : 0;
283  }
284  setCurrentTime(e) {
285    this.lastState === YT.PlayerState.PAUSED && (this.timeBeforeSeek = this.currentTime());
286    this.isSeeking || (this.wasPausedBeforeSeek = this.paused());
287    this.ytPlayer.seekTo(e, !0);
288    this.trigger('timeupdate');
289    this.trigger('seeking');
290    this.isSeeking = !0;
291    if (this.lastState === YT.PlayerState.PAUSED && this.timeBeforeSeek !== e) {
292      clearInterval(this.checkSeekedInPauseInterval);
293      this.checkSeekedInPauseInterval = setInterval(
294        function () {
295          if (this.lastState === YT.PlayerState.PAUSED && this.isSeeking) {
296            if (this.currentTime() !== this.timeBeforeSeek) {
297              this.trigger('timeupdate');
298              this.onSeeked();
299            }
300          } else clearInterval(this.checkSeekedInPauseInterval);
301        }.bind(this),
302        250
303      );
304    }
305  }
306  seeking() {
307    return this.isSeeking;
308  }
309  seekable() {
310    return this.ytPlayer
311      ? videojs.createTimeRange(0, this.ytPlayer.getDuration())
312      : videojs.createTimeRange();
313  }
314  onSeeked() {
315    clearInterval(this.checkSeekedInPauseInterval);
316    this.isSeeking = !1;
317    this.wasPausedBeforeSeek && this.pause();
318    this.trigger('seeked');
319  }
320  playbackRate() {
321    return this.ytPlayer ? this.ytPlayer.getPlaybackRate() : 1;
322  }
323  setPlaybackRate(e) {
324    this.ytPlayer && this.ytPlayer.setPlaybackRate(e);
325  }
326  duration() {
327    return this.ytPlayer ? this.ytPlayer.getDuration() : 0;
328  }
329  currentSrc() {
330    return this.source && this.source.src;
331  }
332  ended() {
333    return !!this.ytPlayer && this.lastState === YT.PlayerState.ENDED;
334  }
335  volume() {
336    return this.ytPlayer ? this.ytPlayer.getVolume() / 100 : 1;
337  }
338  setVolume(e) {
339    this.ytPlayer && this.ytPlayer.setVolume(100 * e);
340  }
341  muted() {
342    return !!this.ytPlayer && this.ytPlayer.isMuted();
343  }
344  setMuted(e) {
345    if (this.ytPlayer) {
346      this.muted(!0);
347      e ? this.ytPlayer.mute() : this.ytPlayer.unMute();
348      this.setTimeout(function () {
349        this.trigger('volumechange');
350      }, 50);
351    }
352  }
353  buffered() {
354    var e;
355    return this.ytPlayer && this.ytPlayer.getVideoLoadedFraction
356      ? ((e = this.ytPlayer.getVideoLoadedFraction() * this.ytPlayer.getDuration()),
357        videojs.createTimeRange(0, e))
358      : videojs.createTimeRange();
359  }
360  preload() {}
361  load() {}
362  reset() {}
363  networkState() {
364    if (!this.ytPlayer) return 0;
365    switch (this.ytPlayer.getPlayerState()) {
366      case -1:
367        return 0;
368      case 3:
369        return 2;
370      default:
371        return 1;
372    }
373  }
374  readyState() {
375    if (!this.ytPlayer) return 0;
376    switch (this.ytPlayer.getPlayerState()) {
377      case -1:
378        return 0;
379      case 5:
380        return 1;
381      case 3:
382        return 2;
383      default:
384        return 4;
385    }
386  }
387  supportsFullScreen() {
388    return (
389      document.fullscreenEnabled ||
390      document.webkitFullscreenEnabled ||
391      document.mozFullScreenEnabled ||
392      document.msFullscreenEnabled
393    );
394  }
395  checkHighResPoster() {
396    var e = 'https://img.youtube.com/vi/' + this.url.videoId + '/maxresdefault.jpg';
397    try {
398      var t = new Image();
399      t.onload = function () {
400        if ('naturalHeight' in t) {
401          if (t.naturalHeight <= 90 || t.naturalWidth <= 120) return;
402        } else if (t.height <= 90 || t.width <= 120) return;
403        this.poster_ = e;
404        this.trigger('posterchange');
405      }.bind(this);
406      t.onerror = function () {};
407      t.src = e;
408    } catch (e) {}
409  }
410}
411Youtube.isSupported = function () {
412  return !0;
413};
414Youtube.canPlaySource = function (e) {
415  return Youtube.canPlayType(e.type);
416};
417Youtube.canPlayType = function (e) {
418  return 'video/youtube' === e;
419};
420Youtube.parseUrl = function (e) {
421  var t = { videoId: null },
422    i = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,
423    i = e.match(i),
424    s = (i && 11 === i[2].length && (t.videoId = i[2]), /[?&]list=([^#\&\?]+)/);
425  (i = e.match(s)) && i[1] && (t.listId = i[1]);
426  return t;
427};
428function apiLoaded() {
429  YT.ready(function () {
430    Youtube.isApiReady = !0;
431    for (var e = 0; e < Youtube.apiReadyQueue.length; ++e) Youtube.apiReadyQueue[e].initYTPlayer();
432  });
433}
434function loadScript(e, t) {
435  var i = !1,
436    s = document.createElement('script'),
437    o = document.getElementsByTagName('script')[0];
438  if (o) {
439    o.parentNode.insertBefore(s, o);
440    s.onload = function () {
441      if (!i) {
442        i = !0;
443        t();
444      }
445    };
446    s.onreadystatechange = function () {
447      if (!i && ('complete' === this.readyState || 'loaded' === this.readyState)) {
448        i = !0;
449        t();
450      }
451    };
452    s.src = e;
453  }
454}
455function injectCss() {
456  var e =
457      '.vjs-youtube .vjs-iframe-blocker { display: none; }.vjs-youtube.vjs-user-inactive .vjs-iframe-blocker { display: block; }.vjs-youtube .vjs-poster { background-size: cover; }.vjs-youtube-mobile .vjs-big-play-button { display: none; }',
458    t = document.head || document.getElementsByTagName('head')[0],
459    i = document.createElement('style');
460  i.type = 'text/css';
461  i.styleSheet ? (i.styleSheet.cssText = e) : i.appendChild(document.createTextNode(e));
462  t.appendChild(i);
463}
464Youtube.apiReadyQueue = [];
465if ('undefined' !== typeof document) {
466  loadScript('https://www.youtube.com/iframe_api', apiLoaded);
467  injectCss();
468}
469'undefined' !== typeof videojs.registerTech
470  ? videojs.registerTech('Youtube', Youtube)
471  : videojs.registerComponent('Youtube', Youtube);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.