diff --git a/extension/src/manifest.json b/extension/src/manifest.json index a5adab9a..ac686c24 100755 --- a/extension/src/manifest.json +++ b/extension/src/manifest.json @@ -98,6 +98,7 @@ "pages/disney-plus-page.js", "pages/viki-page.js", "pages/unext-page.js", + "pages/emby-page.js", "anki-ui.js", "mp3-encoder-worker.js", "pgs-parser-worker.js", diff --git a/extension/src/pages.json b/extension/src/pages.json index 845d3acb..23312750 100644 --- a/extension/src/pages.json +++ b/extension/src/pages.json @@ -79,6 +79,14 @@ "autoSync": { "enabled": true } + }, + { + "host": "emby*|:8096*", + "script": "emby-page.js", + "hash": "#!/videoosd/videoosd.html", + "autoSync": { + "enabled": true + } } ] } diff --git a/extension/src/pages/emby-page.ts b/extension/src/pages/emby-page.ts new file mode 100644 index 00000000..8e6bc0c1 --- /dev/null +++ b/extension/src/pages/emby-page.ts @@ -0,0 +1,61 @@ +import { VideoDataSubtitleTrack } from '@project/common'; +import { VideoData } from '@project/common'; + +declare const ApiClient: any | undefined; + +document.addEventListener( + 'asbplayer-get-synced-data', + async () => { + const response: VideoData = { error: '', basename: '', subtitles: [] }; + if (!ApiClient) { + response.error = 'ApiClient is undefined'; + return document.dispatchEvent( + new CustomEvent('asbplayer-synced-data', { + detail: response, + }) + ); + } + const deviceID = ApiClient?._deviceId; + const apikey = ApiClient?._userAuthInfo.AccessToken; + await fetch('/Sessions?api_key=' + apikey + '&IsPlaying=True&DeviceId=' + deviceID) + .then((webResponse) => { + return webResponse.json(); + }) + .then((sessions) => { + var session = sessions[0]; + var mediaID = session.PlayState.MediaSourceId; + var nowPlayingItem = session.NowPlayingItem; + response.basename = nowPlayingItem.FileName; + const subtitles: VideoDataSubtitleTrack[] = []; + nowPlayingItem.MediaStreams.filter( + (stream: { IsTextSubtitleStream: any }) => stream.IsTextSubtitleStream + ).forEach((sub: { Codec: string; DisplayTitle: any; Language: any; Index: number }) => { + var url = + '/Videos/' + + nowPlayingItem.Id + + '/' + + mediaID + + '/Subtitles/' + + sub.Index + + '/Stream.' + + sub.Codec + + '?api_key=' + + apikey; + subtitles.push({ + label: sub.DisplayTitle, + language: sub.Language, + url: url, + extension: sub.Codec, + }); + }); + response.subtitles = subtitles; + + document.dispatchEvent( + new CustomEvent('asbplayer-synced-data', { + detail: response, + }) + ); + }); + }, + false +); diff --git a/extension/src/services/pages.ts b/extension/src/services/pages.ts index 1964a68a..a32fb309 100644 --- a/extension/src/services/pages.ts +++ b/extension/src/services/pages.ts @@ -3,7 +3,8 @@ import pagesConfig from '../pages.json'; interface PageConfig { host: string; script: string; - path: string; + path?: string; + hash?: string; autoSync: { enabled: boolean; videoSrc?: string; @@ -74,6 +75,14 @@ export class PageDelegate { } isVideoPage() { - return new RegExp(this.config.path).test(this.url.pathname); + var hashMatch = true; + var pathMatch = true; + if (this.config.hash) { + hashMatch = new RegExp(this.config.hash).test(this.url.hash); + } + if (this.config.path) { + pathMatch = new RegExp(this.config.path).test(this.url.pathname); + } + return hashMatch && pathMatch; } }