Overview
This page documents all TypeScript interfaces and types used across EmbyTok’s client libraries.
Server Types
ServerType
Defines the type of media server.
type ServerType = 'emby' | 'plex' | 'local' | 'folder';
Emby or Jellyfin media server
Local browser-based file access
Configuration
ServerConfig
Configuration object for connecting to a media server.
interface ServerConfig {
url: string;
username: string;
token: string;
userId: string;
serverType: ServerType;
}
Authentication token or API key
User ID from the server (or MachineIdentifier for Plex)
Type of server being connected to
Example
const config: ServerConfig = {
url: 'https://emby.example.com',
username: 'johndoe',
token: 'abc123xyz',
userId: 'user-id-456',
serverType: 'emby'
};
Authentication
EmbyAuthResponse
Response from Emby/Jellyfin authentication endpoint.
interface EmbyAuthResponse {
User: {
Id: string;
Name: string;
Policy?: {
IsAdministrator: boolean;
};
};
AccessToken: string;
ServerId: string;
}
User.Policy.IsAdministrator
Whether user has admin privileges (optional)
Token for authenticated API requests
Library Types
EmbyLibrary
Represents a media library/collection.
interface EmbyLibrary {
Id: string;
Name: string;
CollectionType?: string;
}
Unique library identifier (section key for Plex)
Display name of the library
Type of content (e.g., ‘movies’, ‘tvshows’, ‘music’)
Example
const library: EmbyLibrary = {
Id: 'lib-123',
Name: 'Movies',
CollectionType: 'movies'
};
Information about a video file’s source.
interface MediaSource {
Id: string;
Container: string;
Path: string;
Protocol: string;
}
Unique identifier for this media source
File container format (e.g., ‘mp4’, ‘mkv’)
Streaming protocol (e.g., ‘File’, ‘Http’)
EmbyItem
Represents a video item from any media server.
interface EmbyItem {
Id: string;
Name: string;
Type: string;
MediaType: string;
Overview?: string;
ProductionYear?: number;
Width?: number;
Height?: number;
RunTimeTicks?: number;
MediaSources?: MediaSource[];
ImageTags?: {
Primary?: string;
Logo?: string;
Thumb?: string;
};
UserData?: {
IsFavorite: boolean;
PlaybackPositionTicks: number;
PlayCount: number;
};
}
Unique item identifier (ratingKey for Plex)
Item type (e.g., ‘Movie’, ‘Episode’, ‘Video’)
Media type (e.g., ‘Video’)
Description or plot summary (optional)
Year of production (optional)
Video width in pixels (optional, used for orientation filtering)
Video height in pixels (optional, used for orientation filtering)
Duration in ticks (1 tick = 100 nanoseconds) (optional)
Array of available media sources (optional)
Tag for primary image (optional)
Tag for logo image (optional)
Tag for thumbnail image (optional)
Whether user has favorited this item (optional)
UserData.PlaybackPositionTicks
Last playback position in ticks (optional)
Number of times user has played this item (optional)
Example
const video: EmbyItem = {
Id: 'video-123',
Name: 'Sample Video',
Type: 'Movie',
MediaType: 'Video',
Overview: 'An amazing video',
ProductionYear: 2024,
Width: 1080,
Height: 1920,
RunTimeTicks: 6000000000,
ImageTags: {
Primary: 'image-tag-abc'
},
UserData: {
IsFavorite: false,
PlaybackPositionTicks: 0,
PlayCount: 0
}
};
Feed Types
FeedType
Defines the type of video feed to fetch.
type FeedType = 'latest' | 'random' | 'favorites';
Videos sorted by date added (newest first)
User’s favorited videos from playlist
OrientationMode
Defines video orientation filtering mode.
type OrientationMode = 'vertical' | 'horizontal' | 'both';
Only show vertical or near-vertical videos (height >= width * 0.8)
Only show horizontal videos (width > height)
Show all videos regardless of orientation
Example
// Fetch random vertical videos
const response = await client.getVideos(
libraryId,
'Movies',
'random' as FeedType,
0,
15,
'vertical' as OrientationMode
);
Response Types
VideoResponse
Response from getVideos method with pagination info.
interface VideoResponse {
items: EmbyItem[];
nextStartIndex: number;
totalCount: number;
}
Array of video items for the current page
Starting index for the next page of results
Total number of items available (may be estimated for filtered results)
Example
const response: VideoResponse = await client.getVideos(
'lib-123',
'Movies',
'latest',
0,
15,
'both'
);
console.log(`Page: ${response.items.length} items`);
console.log(`Next page starts at: ${response.nextStartIndex}`);
console.log(`Total available: ${response.totalCount}`);
if (response.nextStartIndex < response.totalCount) {
console.log('More items available');
}
Usage Example
Combining multiple types in a real-world scenario:
import {
ServerConfig,
ServerType,
EmbyLibrary,
EmbyItem,
FeedType,
OrientationMode,
VideoResponse
} from './types';
import { ClientFactory } from './services/clientFactory';
async function loadVideos() {
// Create server config
const serverType: ServerType = 'emby';
const config: ServerConfig = await ClientFactory.authenticate(
serverType,
'https://emby.example.com',
'username',
'password'
);
// Create client
const client = ClientFactory.create(config);
// Get libraries
const libraries: EmbyLibrary[] = await client.getLibraries();
const moviesLib = libraries.find(l => l.CollectionType === 'movies');
if (!moviesLib) return;
// Fetch videos
const feedType: FeedType = 'random';
const orientation: OrientationMode = 'vertical';
const response: VideoResponse = await client.getVideos(
moviesLib.Id,
moviesLib.Name,
feedType,
0,
15,
orientation
);
// Process items
response.items.forEach((video: EmbyItem) => {
const url = client.getVideoUrl(video);
const thumb = client.getImageUrl(
video.Id,
video.ImageTags?.Primary,
'Primary'
);
console.log(`${video.Name} (${video.ProductionYear})`);
console.log(`Dimensions: ${video.Width}x${video.Height}`);
console.log(`Stream: ${url}`);
});
}
See Also