emby增加自定义ua和图片代理

This commit is contained in:
mtvpls
2026-03-03 11:23:25 +08:00
parent fe1f79b273
commit 4f87e99f52
13 changed files with 246 additions and 15 deletions
+26 -1
View File
@@ -12,6 +12,7 @@ interface EmbyConfig {
appendMediaSourceId?: boolean;
transcodeMp4?: boolean;
proxyPlay?: boolean; // 视频播放代理开关
customUserAgent?: string; // 自定义User-Agent
key?: string; // Emby源的唯一标识
}
@@ -75,6 +76,7 @@ export class EmbyClient {
private transcodeMp4: boolean;
private proxyPlay: boolean;
private embyKey?: string;
private customUserAgent: string;
constructor(config: EmbyConfig) {
let serverUrl = config.ServerURL.replace(/\/$/, '');
@@ -85,6 +87,8 @@ export class EmbyClient {
this.transcodeMp4 = config.transcodeMp4 || false;
this.proxyPlay = config.proxyPlay || false;
this.embyKey = config.key;
// 设置自定义UA,如果没有设置则使用默认浏览器UA
this.customUserAgent = config.customUserAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
// 如果 URL 不包含 /emby 路径,自动添加(除非启用了 removeEmbyPrefix
if (!serverUrl.endsWith('/emby') && !this.removeEmbyPrefix) {
@@ -122,6 +126,7 @@ export class EmbyClient {
private getHeaders(): Record<string, string> {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'User-Agent': this.customUserAgent,
};
if (this.apiKey) {
@@ -146,6 +151,7 @@ export class EmbyClient {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Emby-Authorization': 'MediaBrowser Client="LunaTV", Device="Web", DeviceId="lunatv-web", Version="1.0.0"',
'User-Agent': this.customUserAgent,
},
body: params.toString(),
});
@@ -420,7 +426,18 @@ export class EmbyClient {
}
}
getImageUrl(itemId: string, imageType: 'Primary' | 'Backdrop' | 'Logo' = 'Primary', maxWidth?: number): string {
getImageUrl(itemId: string, imageType: 'Primary' | 'Backdrop' | 'Logo' = 'Primary', maxWidth?: number, proxyToken?: string): string {
// 如果启用了代理播放且提供了 token,返回代理 URL
if (this.proxyPlay && proxyToken) {
const params = new URLSearchParams();
params.set('imageType', imageType);
if (maxWidth) params.set('maxWidth', maxWidth.toString());
if (this.embyKey) params.set('embyKey', this.embyKey);
return `/api/emby/image/${proxyToken}/${itemId}?${params.toString()}`;
}
// 否则返回直连 URL
const params = new URLSearchParams();
const token = this.apiKey || this.authToken;
@@ -551,4 +568,12 @@ export class EmbyClient {
return subtitles;
}
getUserAgent(): string {
return this.customUserAgent;
}
isProxyEnabled(): boolean {
return this.proxyPlay;
}
}