Emby Local Player

调用本地的播放器来播放 Emby Web 中的视频。

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Emby Local Player
// @namespace    https://greasyfork.org/zh-CN/scripts/419804-emby-local-player
// @version      0.1.2
// @description  调用本地的播放器来播放 Emby Web 中的视频。
// @author       Cybit
// @grant        none
// @match        none
// ==/UserScript==

/* jshint esversion:8 */
function init(pluginManager, dialog) {
  class PotPlayer {
    constructor() {
      this.id = 'potplayer'
      this.type = 'mediaplayer'
      this.name = 'Pot Player'

      function dummy() {}

      for (const k of ['volume', 'isMuted', 'paused', 'currentTime', 'currentSrc']) {
        this[k] = dummy;
      }
    }

    canPlayMediaType() {
      return true;
    }

    getPlayerUrl(url) {
      if (navigator.userAgent.includes('Macintosh')) {
        return `iina://open?url=${encodeURIComponent(url)}`;
      }

      return `potplayer://${encodeURI(url)}`;
    }

    async play(item, options) {
      console.log(item, options);

      const playerUrl = this.getPlayerUrl(item.url);
      window.open(playerUrl, '_self');

      if (item.textTracks.length === 0) {
        return;
      }

      const mediaStreams = item.mediaSource.MediaStreams;
      const html = item.textTracks.map(track => {
        return `<p><a href="${track.url}" target="_blank">${mediaStreams[track.index].DisplayTitle}</a></p>`
      }).join('\n');

      dialog({
        html,
        title: 'Subtitles',
        buttons: [
          {
            name: 'Close',
            type: 'cancel',
          },
        ],
      });
    }

    async stop() {}

    async getDeviceProfile(item, options) {
      const subFormats = ['ass', 'srt'];
      return {
        SubtitleProfiles: subFormats.map(type => (
          {
            "Format": type,
            "Method": "External"
          }
        )),
      };
    }
  }


  pluginManager.register(new PotPlayer());

  console.log('Pot Player plugin registered');
}

(async function() {
  'use strict';

  while (!window.require || !window.ConnectionManager) {
    await new Promise(resolve => setTimeout(resolve, 200));
  }

  window.require(['pluginManager', 'dialog'], init);
})();