Emby Local Player

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
})();