Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Emby Support #365

Merged
merged 6 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extension/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions extension/src/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
"autoSync": {
"enabled": true
}
},
{
"host": "emby*|:8096*",
killergerbah marked this conversation as resolved.
Show resolved Hide resolved
"script": "emby-page.js",
"path": ".*",
"hash": "#!/videoosd/videoosd.html",
"autoSync": {
"enabled": true
}
}
]
}
40 changes: 40 additions & 0 deletions extension/src/pages/emby-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { VideoDataSubtitleTrack } from '@project/common';
import { VideoData } from '@project/common';

declare const ApiClient: any | undefined;

document.addEventListener(
'asbplayer-get-synced-data',
async () => {
const deviceID = ApiClient?._deviceId;
const apikey = ApiClient?._userAuthInfo.AccessToken;
killergerbah marked this conversation as resolved.
Show resolved Hide resolved
const response: VideoData = { error: '', basename: '', subtitles: [] };
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
);

4 changes: 4 additions & 0 deletions extension/src/services/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface PageConfig {
host: string;
script: string;
path: string;
hash?: string;
autoSync: {
enabled: boolean;
videoSrc?: string;
Expand Down Expand Up @@ -74,6 +75,9 @@ export class PageDelegate {
}

isVideoPage() {
if (this.config.hash) {
killergerbah marked this conversation as resolved.
Show resolved Hide resolved
return new RegExp(this.config.hash).test(this.url.hash);
}
return new RegExp(this.config.path).test(this.url.pathname);
}
}