-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
主要功能:在参数配置页添加媒体服务器(Emby)之后,可以在搜索页面的电影卡片下方显示服务器中已存在的媒体信息。 PS:给2024年画上圆满的句号,2025诸事顺意!
- Loading branch information
Showing
18 changed files
with
1,091 additions
and
26 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { EMediaServerType, IMediaServer } from "@/interface/common"; | ||
import { Emby } from "./plugins/Emby"; | ||
|
||
export class MediaServerManager { | ||
private servers: any = {}; | ||
|
||
|
||
private getServer(options: IMediaServer) { | ||
let server = this.servers[options.id]; | ||
|
||
if (server) { | ||
return server; | ||
} | ||
|
||
switch (options.type) { | ||
case EMediaServerType.Emby: | ||
server = new Emby(options); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
if (server) { | ||
this.servers[options.id] = server; | ||
} | ||
|
||
return server; | ||
} | ||
|
||
public reset() { | ||
for (const item of this.servers) { | ||
this.servers[item] = undefined; | ||
delete this.servers[item]; | ||
} | ||
this.servers = {}; | ||
} | ||
|
||
public async ping(options: IMediaServer) { | ||
let server = this.getServer(options); | ||
|
||
if (server) { | ||
return server.ping(); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public async getMediaFromMediaServer(options: IMediaServer, imdbId: string) { | ||
let server = this.getServer(options); | ||
|
||
if (server) { | ||
return server.getMediaFromMediaServer(imdbId); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { IMediaServer } from "@/interface/common"; | ||
export type Dictionary<T> = { [key: string]: T }; | ||
|
||
export class Emby { | ||
public serverURL: string = ""; | ||
|
||
private API: any = { | ||
methods: { | ||
findFromIMDb: 'Items?Recursive=true&Fields=Path,Size,OfficialRating,MediaSources&AnyProviderIdEquals=imdb.$imdbId$', | ||
getSystemInfo: 'System/Info' | ||
} | ||
} | ||
|
||
constructor(public options: IMediaServer) { | ||
this.serverURL = this.options.address; | ||
if (this.serverURL.substr(-1) !== "/") { | ||
this.serverURL += "/"; | ||
} | ||
} | ||
|
||
/** | ||
* 替换指定的字符串列表 | ||
* @param source | ||
* @param maps | ||
*/ | ||
public replaceKeys( | ||
source: string, | ||
maps: Dictionary<any>, | ||
prefix: string = "" | ||
): string { | ||
if (!source) { | ||
return source; | ||
} | ||
let result: string = source; | ||
|
||
for (const key in maps) { | ||
if (maps.hasOwnProperty(key)) { | ||
const value = maps[key]; | ||
let search = "$" + key + "$"; | ||
if (prefix) { | ||
search = `$${prefix}.${key}$`; | ||
} | ||
result = result.replace(search, value); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* 指定指定的API | ||
* @param method | ||
* @param data | ||
* @returns | ||
*/ | ||
public async execAPI(method = '', data: any = {}) { | ||
let m: any; | ||
let methods = method.split("."); | ||
|
||
if (methods.length == 1) { | ||
m = this.API.methods[method] | ||
} else { | ||
m = this.API.methods[methods[0]][methods[1]] | ||
} | ||
|
||
let url = ''; | ||
let mode = 'GET'; | ||
if (typeof (m) == 'string') { | ||
url = m; | ||
} else { | ||
url = m.url; | ||
mode = m.mode || 'GET'; | ||
} | ||
|
||
url = this.serverURL + this.replaceKeys(url, data); | ||
|
||
const options = { | ||
method: mode, | ||
headers: { | ||
accept: 'application/json', | ||
'X-Emby-Token': `${this.options.apiKey}` | ||
} | ||
}; | ||
|
||
|
||
try { | ||
const response = await fetch(url, options); | ||
if (response.ok) { | ||
const result = await response.json(); | ||
return result; | ||
} else { | ||
throw new Error(`HTTP 错误!状态码:${response.status}`); | ||
} | ||
} catch (error) { | ||
|
||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* 验证服务器可用性 | ||
*/ | ||
public async ping() { | ||
const result = await this.execAPI('getSystemInfo'); | ||
if (result && result.Id) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* 根据imdbId 获取媒体信息 | ||
* @param imdbId | ||
* @returns | ||
*/ | ||
public async getMediaFromMediaServer(imdbId: string) { | ||
const result = await this.execAPI('findFromIMDb', { | ||
imdbId | ||
}); | ||
if (result && result.Items) { | ||
return result; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.