
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
@iptv/xtream-api
Advanced tools
To install this library, use the following command:
# pnpm
pnpm add @iptv/xtream-api
# npm
npm install @iptv/xtream-api
# yarn
yarn add @iptv/xtream-api
import { Xtream } from '@iptv/xtream-api';
const xtream = new Xtream({
url: 'http://example.com:8080',
username: 'username',
password: 'password',
preferredFormat: 'm3u8', // optional preferred format for channel URLs
});
const categories = await xtream.getChannelCategories();
console.log(categories);
/* outputs
[
{
category_id: 1,
category_name: 'Category 1',
parent_id: 0,
},
{
category_id: 2,
category_name: 'Category 2',
parent_id: 0,
},
]
*/
| Method | Serialized Response |
|---|---|
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| View Standardized View JSON:API |
| N/A |
Xtream has an unpredictable API format, there are duplicate keys, keys change depending on what type of content is requested, dates come as date strings and timestamp strings with no reason, things that should be arrays are sometimes objects with numbered keys, some data is base64 encoded etc.
For this reason, this library can use serializers to convert the API response to a more usable format. We provide a default set of serializers for the most common API responses.
The simplest serializer just converts the keys of the response object to camel case.
import { Xtream } from '@iptv/xtream-api';
import { camelCaseSerializer } from '@iptv/xtream-api/camelcase';
const xtream = new Xtream({
url: 'http://example.com:8080',
username: 'username',
password: 'password',
serializer: camelCaseSerializer,
});
const categories = await xtream.getChannelCategories();
console.log(categories);
/* outputs
[
{
categoryId: 1,
categoryName: 'Category 1',
parentId: 0,
},
{
categoryId: 2,
categoryName: 'Category 2',
parentId: 1
},
]
*/
Converts the shape of the response object to a standardized format similar to Active Record, also decodes base64 strings.
import { Xtream } from '@iptv/xtream-api';
import { standardizedSerializer } from '@iptv/xtream-api/standardized';
const xtream = new Xtream({
url: 'http://example.com:8080',
username: 'username',
password: 'password',
serializer: standardizedSerializer,
});
const categories = await xtream.getChannelCategories();
console.log(categories);
/* outputs
[
{
id: '1',
name: 'Category 1',
parentId: '0',
},
{
id: '2',
name: 'Category 2',
parentId: '1',
},
]
*/
Converts the response object to JSON:API format, also decodes base64 strings.
import { Xtream } from '@iptv/xtream-api';
import { JSONAPISerializer } from '@iptv/xtream-api/jsonapi';
const xtream = new Xtream({
url: 'http://example.com:8080',
username: 'username',
password: 'password',
serializer: JSONAPISerializer,
});
const categories = await xtream.getChannelCategories();
console.log(categories);
/* outputs
{
data: [
{
type: 'channel-category',
id: '1',
attributes: {
name: 'Category 1',
},
},
{
type: 'channel-category',
id: '2',
attributes: {
name: 'Category 2',
},
relationships: {
parent: {
data: {
type: 'channel-category',
id: '1',
},
},
},
},
],
}
*/
You can create your own serializer by passing an object of serializer methods to the Xtream class.
You can define serializers for each of these methods, all are optional.
type Serializers = {
profile: (input: XtreamUserProfile) => any;
serverInfo: (input: XtreamServerInfo) => any;
channelCategories: (input: XtreamCategory[]) => any;
movieCategories: (input: XtreamCategory[]) => any;
showCategories: (input: XtreamCategory[]) => any;
channels: (input: XtreamChannel[]) => any;
movies: (input: XtreamMoviesListing[]) => any;
movie: (input: XtreamMovie) => any;
shows: (input: XtreamShowListing[]) => any;
show: (input: XtreamShow) => any;
shortEPG: (input: XtreamShortEPG) => any;
fullEPG: (input: XtreamFullEPG) => any;
};
import { Xtream } from '@iptv/xtream-api';
const xtream = new Xtream({
url: 'http://example.com:8080',
username: 'username',
password: 'password',
serializer: {
type: 'MyCustomSerializer',
serializers: {
channelCategories: (input) => {
return input.map((category) => ({
id: category.category_id,
name: category.category_name,
}));
},
},
},
});
const categories = await xtream.getChannelCategories();
console.log(categories);
/* outputs
[
{
id: 1,
name: 'Category 1'
},
{
id: 2,
name: 'Category 2'
}
]
If you want to create your serializer as a separate file or outside of the class instantiation, a helper function is provided to ensure the correct type information is preserved.
import { defineSerializers } from '@iptv/xtream-api';
export const serializers = defineSerializers('MyCustomSerializer', {
channelCategories: (input) => {
return input.map((category) => ({
id: category.category_id,
name: category.category_name,
}));
},
});
In this example input will have the type of XtreamCategory[] which is the type of the response from the getChannelCategories method.
After supplying the serializers to the Xtream class, the types of the responses will be updated to reflect the changes made by the serializers.
import { Xtream, defineSerializers } from '@iptv/xtream-api';
const mySerializer = defineSerializers('MyCustomSerializer', {
channelCategories: (input) => {
return input.map((category) => ({
id: Number(category.category_id),
name: category.category_name,
}));
},
});
const xtream = new Xtream({
url: 'http://example.com:8080',
username: 'username',
password: 'password',
serializer: mySerializer,
});
const categories = await xtream.getChannelCategories();
// ^---------
// const categories = { id: number, name: string }[]
This library is licensed under the MIT License and is free to use in both open source and commercial projects.
FAQs
Standardized access to Xtream compatible player API
We found that @iptv/xtream-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.