jellyfin-sdk-typescript/README.md
2021-09-21 10:18:49 -04:00

2.3 KiB

jellyfin-sdk-typescript

MPL-2.0 license Current Release Codecov

A TypeScript SDK for Jellyfin.

Warning: This project is under active development and is not ready for production use. API changes will occur.

Install

npm i --save @thornbill/jellyfin-sdk

or

yarn add @thornbill/jellyfin-sdk

Usage

// Create a new instance of the SDK
const jellyfin = new Jellyfin({
    clientInfo: {
        name: 'My Client Application',
        version: '1.0.0'
    },
    deviceInfo: {
        name: 'Device Name',
        id: 'unique-device-id'
    }
});
const api = jellyfin.createApi('https://demo.jellyfin.org/stable');

// Each API endpoint is exposed via a getter on the SDK instance using
// a shared Configuration and Axios instance. For example the /System APIs
// are available as api.systemApi.

// Fetch the public system info
const info = await api.systemApi.getPublicSystemInfo();
console.log('Info =>', info.data);

// Fetch the list of public users
const users = await api.userApi.getPublicUsers();
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.
const auth = await api.authenticateUserByName({ Username: 'demo', Pw: '' });
console.log('Auth =>', auth.data);

// 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);

// 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();