Emby Local Player

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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