feat(all): add initial Jellyfin/Emby support

This commit is contained in:
Aiden Vigue
2021-02-15 05:13:19 -05:00
parent 9ce88abcc8
commit a6ec2d5220
31 changed files with 2194 additions and 44 deletions

51
src/utils/jellyfin.ts Normal file
View File

@@ -0,0 +1,51 @@
/* eslint-disable no-async-promise-executor */
import axios, { AxiosError, AxiosResponse } from 'axios';
interface JellyfinAuthenticationResult {
Id: string;
AccessToken: string;
ServerId: string;
}
class JellyAPI {
public login(
Hostname?: string,
Username?: string,
Password?: string
): Promise<JellyfinAuthenticationResult> {
return new Promise(
(
resolve: (result: JellyfinAuthenticationResult) => void,
reject: (e: Error) => void
) => {
axios
.post(
Hostname + '/Users/AuthenticateByName',
{
Username: Username,
Pw: Password,
},
{
headers: {
'X-Emby-Authorization':
'MediaBrowser Client="Jellyfin Web", Device="Firefox", DeviceId="TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NDsgcnY6ODUuMCkgR2Vja28vMjAxMDAxMDEgRmlyZWZveC84NS4wfDE2MTI5MjcyMDM5NzM1", Version="10.8.0"',
},
}
)
.then((resp: AxiosResponse) => {
const response: JellyfinAuthenticationResult = {
Id: resp.data.User.Id,
AccessToken: resp.data.AccessToken,
ServerId: resp.data.ServerId,
};
resolve(response);
})
.catch((e: AxiosError) => {
reject(e);
});
}
);
}
}
export default JellyAPI;