Skip to main content

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
string
Emby or Jellyfin media server
plex
string
Plex Media Server
local
string
Local browser-based file access
folder
string
Folder streaming server

Configuration

ServerConfig

Configuration object for connecting to a media server.
interface ServerConfig {
  url: string;
  username: string;
  token: string;
  userId: string;
  serverType: ServerType;
}
url
string
Base URL of the media server (e.g., ‘https://emby.example.com’)
username
string
Authenticated username
token
string
Authentication token or API key
userId
string
User ID from the server (or MachineIdentifier for Plex)
serverType
ServerType
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.Id
string
User’s unique identifier
User.Name
string
User’s display name
User.Policy.IsAdministrator
boolean
Whether user has admin privileges (optional)
AccessToken
string
Token for authenticated API requests
ServerId
string
Unique server identifier

Library Types

EmbyLibrary

Represents a media library/collection.
interface EmbyLibrary {
  Id: string;
  Name: string;
  CollectionType?: string;
}
Id
string
Unique library identifier (section key for Plex)
Name
string
Display name of the library
CollectionType
string
Type of content (e.g., ‘movies’, ‘tvshows’, ‘music’)

Example

const library: EmbyLibrary = {
  Id: 'lib-123',
  Name: 'Movies',
  CollectionType: 'movies'
};

Media Items

MediaSource

Information about a video file’s source.
interface MediaSource {
  Id: string;
  Container: string;
  Path: string;
  Protocol: string;
}
Id
string
Unique identifier for this media source
Container
string
File container format (e.g., ‘mp4’, ‘mkv’)
Path
string
File path on the server
Protocol
string
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;
  };
}
Id
string
Unique item identifier (ratingKey for Plex)
Name
string
Title of the video
Type
string
Item type (e.g., ‘Movie’, ‘Episode’, ‘Video’)
MediaType
string
Media type (e.g., ‘Video’)
Overview
string
Description or plot summary (optional)
ProductionYear
number
Year of production (optional)
Width
number
Video width in pixels (optional, used for orientation filtering)
Height
number
Video height in pixels (optional, used for orientation filtering)
RunTimeTicks
number
Duration in ticks (1 tick = 100 nanoseconds) (optional)
MediaSources
MediaSource[]
Array of available media sources (optional)
ImageTags.Primary
string
Tag for primary image (optional)
Tag for logo image (optional)
ImageTags.Thumb
string
Tag for thumbnail image (optional)
UserData.IsFavorite
boolean
Whether user has favorited this item (optional)
UserData.PlaybackPositionTicks
number
Last playback position in ticks (optional)
UserData.PlayCount
number
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';
latest
string
Videos sorted by date added (newest first)
random
string
Randomly shuffled videos
favorites
string
User’s favorited videos from playlist

OrientationMode

Defines video orientation filtering mode.
type OrientationMode = 'vertical' | 'horizontal' | 'both';
vertical
string
Only show vertical or near-vertical videos (height >= width * 0.8)
horizontal
string
Only show horizontal videos (width > height)
both
string
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;
}
items
EmbyItem[]
Array of video items for the current page
nextStartIndex
number
Starting index for the next page of results
totalCount
number
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

Build docs developers (and LLMs) love