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 5 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
8 changes: 8 additions & 0 deletions extension/src/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
"autoSync": {
"enabled": true
}
},
{
"host": "emby*|:8096*",
killergerbah marked this conversation as resolved.
Show resolved Hide resolved
"script": "emby-page.js",
"hash": "#!/videoosd/videoosd.html",
"autoSync": {
"enabled": true
}
}
]
}
48 changes: 48 additions & 0 deletions extension/src/pages/emby-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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;
killergerbah marked this conversation as resolved.
Show resolved Hide resolved
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
);

13 changes: 11 additions & 2 deletions extension/src/services/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
killergerbah marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}