2021-09-20 18:25:35 +00:00
|
|
|
<h1 align="center">jellyfin-sdk-typescript</h1>
|
|
|
|
|
|
|
|
<p align="center">
|
|
|
|
<a href="https://github.com/thornbill/jellyfin-sdk-typescript/blob/master/LICENSE"><img alt="MPL-2.0 license" src="https://img.shields.io/github/license/thornbill/jellyfin-sdk-typescript"></a>
|
|
|
|
<a href="https://github.com/thornbill/jellyfin-sdk-typescript/releases"><img alt="Current Release" src="https://img.shields.io/github/release/thornbill/jellyfin-sdk-typescript.svg"/></a>
|
|
|
|
<a href="https://codecov.io/gh/thornbill/jellyfin-sdk-typescript">
|
|
|
|
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/thornbill/jellyfin-sdk-typescript?token=Wk8RS9tDnb">
|
|
|
|
</a>
|
|
|
|
</p>
|
2021-09-14 05:20:14 +00:00
|
|
|
|
2021-09-14 05:44:53 +00:00
|
|
|
A TypeScript SDK for Jellyfin.
|
|
|
|
|
|
|
|
> Warning: This project is under active development and is not ready for production use. API changes _will_ occur.
|
|
|
|
|
2021-09-20 18:29:00 +00:00
|
|
|
## Install
|
|
|
|
|
|
|
|
```sh
|
|
|
|
npm i --save @thornbill/jellyfin-sdk
|
|
|
|
```
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
```sh
|
|
|
|
yarn add @thornbill/jellyfin-sdk
|
|
|
|
```
|
|
|
|
|
2021-09-14 05:20:14 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
|
|
|
// Create a new instance of the SDK
|
2021-09-16 21:32:35 +00:00
|
|
|
const jellyfin = new Jellyfin({
|
|
|
|
clientInfo: {
|
|
|
|
name: 'My Client Application',
|
|
|
|
version: '1.0.0'
|
|
|
|
},
|
|
|
|
deviceInfo: {
|
|
|
|
name: 'Device Name',
|
|
|
|
id: 'unique-device-id'
|
|
|
|
}
|
|
|
|
});
|
2021-09-16 21:12:32 +00:00
|
|
|
const api = jellyfin.createApi('https://demo.jellyfin.org/stable');
|
2021-09-14 05:20:14 +00:00
|
|
|
|
|
|
|
// Each API endpoint is exposed via a getter on the SDK instance using
|
|
|
|
// a shared Configuration and Axios instance. For example the /System APIs
|
2021-09-15 05:30:55 +00:00
|
|
|
// are available as api.systemApi.
|
2021-09-14 05:20:14 +00:00
|
|
|
|
|
|
|
// Fetch the public system info
|
2021-09-15 05:30:55 +00:00
|
|
|
const info = await api.systemApi.getPublicSystemInfo();
|
2021-09-14 05:20:14 +00:00
|
|
|
console.log('Info =>', info.data);
|
|
|
|
|
|
|
|
// Fetch the list of public users
|
2021-09-15 05:30:55 +00:00
|
|
|
const users = await api.userApi.getPublicUsers();
|
2021-09-14 05:20:14 +00:00
|
|
|
console.log('Users =>', users.data);
|
|
|
|
|
|
|
|
// A helper method for authentication has been added to the SDK because
|
|
|
|
// the default method exposed in the generated Axios client is rather
|
|
|
|
// cumbersome to use.
|
2021-09-15 05:30:55 +00:00
|
|
|
const auth = await api.authenticateUserByName({ Username: 'demo', Pw: '' });
|
2021-09-14 05:20:14 +00:00
|
|
|
console.log('Auth =>', auth.data);
|
2021-09-16 21:41:17 +00:00
|
|
|
|
|
|
|
// Authentication state is stored internally in the Api class, so now
|
|
|
|
// requests that require authentication can be made normally
|
|
|
|
const libraries = await api.libraryApi.getMediaFolders();
|
|
|
|
console.log('Libraries =>', libraries.data);
|
2021-09-21 14:18:49 +00:00
|
|
|
|
|
|
|
// A helper method for logging out the current user has been added to the
|
|
|
|
// SDK so the internal state is updated correctly.
|
|
|
|
await api.logout();
|
2021-09-14 05:20:14 +00:00
|
|
|
```
|