Initial commit: Xtream Codes API Documentation

Comprehensive API documentation for Xtream Codes IPTV Panel v2.9.2

Includes:
- Complete endpoint reference for all 8 APIs
- Request/response examples with curl commands
- Authentication methods documentation
- IPTV-specific patterns and integrations
- Data models and error codes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
worldofiptvcom
2025-12-24 10:08:26 +00:00
co-authored by Claude Opus 4.5
commit 28cdada37f
4 changed files with 2502 additions and 0 deletions
+197
View File
@@ -0,0 +1,197 @@
# Xtream Codes API - Quick Endpoint Reference
## Player API (`/player_api.php`)
| Action | Method | Required Params | Description |
|--------|--------|-----------------|-------------|
| (default) | GET | username, password | Get user info & server info |
| get_live_categories | GET | username, password | List live TV categories |
| get_live_streams | GET | username, password, [category_id] | List live channels |
| get_vod_categories | GET | username, password | List VOD/movie categories |
| get_vod_streams | GET | username, password, [category_id] | List movies |
| get_vod_info | GET | username, password, vod_id | Get movie details |
| get_series_categories | GET | username, password | List series categories |
| get_series | GET | username, password, [category_id] | List TV series |
| get_series_info | GET | username, password, series_id | Get series details & episodes |
| get_short_epg | GET | username, password, stream_id, [limit] | Get current EPG for channel |
| get_simple_data_table | GET | username, password, stream_id | Get EPG in table format |
---
## Panel API (`/panel_api.php`)
| Action | Method | Required Params | Description |
|--------|--------|-----------------|-------------|
| (default) | GET | username, password | Get full data (user, server, categories, channels) |
| get_epg | GET | username, password, stream_id | Get EPG for stream |
---
## Admin API (`/api.php`)
**Note:** IP-restricted to authorized server IPs only.
### Server Management
| Sub-action | Required Params | Description |
|------------|-----------------|-------------|
| server/list | - | List all servers |
### Stream Management
| Sub-action | Required Params | Description |
|------------|-----------------|-------------|
| stream/start | stream_id | Start stream |
| stream/stop | stream_id | Stop stream |
| stream/list | - | List all streams |
| stream/online | - | List online streams |
| stream/offline | - | List offline streams |
### VOD Management
| Sub-action | Required Params | Description |
|------------|-----------------|-------------|
| vod/start | stream_id | Start VOD encoding |
| vod/stop | stream_id | Stop VOD encoding |
### User Management
| Sub-action | Required Params | Description |
|------------|-----------------|-------------|
| user/info | user_id OR username | Get user info |
| user/create | username, password, [many optional] | Create user |
| user/edit | user_id, [fields to update] | Edit user |
### STB/MAG Management
| Sub-action | Required Params | Description |
|------------|-----------------|-------------|
| stb/info | mag_id OR mac | Get STB info |
| stb/create | mac, user_id | Create STB |
| stb/edit | mag_id, [fields to update] | Edit STB |
### Reseller Management
| Sub-action | Required Params | Description |
|------------|-----------------|-------------|
| reg_user/list | - | List resellers |
| reg_user/credits | reg_user_id | Get reseller credits |
---
## MAG Portal API (`/portal.php`)
### STB Actions (`type=stb`)
| Action | Required Params | Description |
|--------|-----------------|-------------|
| handshake | mac | Initial handshake, get token |
| get_profile | - | Get device profile |
| get_modules | - | Get available modules |
| get_localization | - | Get language strings |
| get_locales | - | Get available locales |
| get_timezones | - | Get timezones |
| get_preload_images | gmode | Get theme images |
| get_settings_profile | - | Get settings |
| set_volume | vol | Set volume |
| set_locale | locale | Set locale |
| set_parent_password | pass, repeat_pass | Set parental password |
| set_playback_buffer | playback_buffer_bytes, playback_buffer_size | Set buffer |
### ITV Actions (`type=itv`)
| Action | Required Params | Description |
|--------|-----------------|-------------|
| get_genres | - | Get live categories |
| get_ordered_list | [genre, sortby, fav] | Get channel list |
| get_all_channels | - | Get all channels |
| get_all_fav_channels | [genre] | Get favorite channels |
| create_link | cmd | Generate stream URL |
| get_short_epg | ch_id | Get EPG for channel |
| get_epg_info | [period] | Get full EPG |
| set_fav | fav_ch | Set favorites (comma-separated) |
| get_fav_ids | - | Get favorite IDs |
| set_last_id | id | Set last watched |
### VOD Actions (`type=vod`)
| Action | Required Params | Description |
|--------|-----------------|-------------|
| get_categories | - | Get VOD categories |
| get_ordered_list | [category, sortby, search, abc, genre, years, fav] | Get movies |
| create_link | cmd, [series] | Generate VOD URL |
| set_fav | video_id | Add to favorites |
| del_fav | video_id | Remove from favorites |
| get_years | - | Get available years |
| get_abc | - | Get alphabet filter |
### Series Actions (`type=series`)
| Action | Required Params | Description |
|--------|-----------------|-------------|
| get_categories | - | Get series categories |
| get_ordered_list | [category, sortby, search, movie_id] | Get series |
| set_fav | video_id | Add to favorites |
| del_fav | video_id | Remove from favorites |
### Watchdog Actions (`type=watchdog`)
| Action | Required Params | Description |
|--------|-----------------|-------------|
| get_events | - | Get pending events |
| confirm_event | event_active_id | Confirm event |
---
## Enigma2 API (`/enigma2.php`)
| Type | Required Params | Description |
|------|-----------------|-------------|
| (default) | username, password | Main menu |
| get_live_categories | username, password | Live categories |
| get_live_streams | username, password, [cat_id] | Live streams |
| get_vod_categories | username, password | VOD categories |
| get_vod_streams | username, password, [cat_id] | VOD streams |
| get_series_categories | username, password | Series categories |
| get_series | username, password, [cat_id] | Series list |
| get_seasons | username, password, series_id | Season list |
| get_series_streams | username, password, series_id, season | Episodes |
---
## Streaming Endpoints
### Live Streaming
```
GET /live/{username}/{password}/{stream_id}.ts
GET /live/{username}/{password}/{stream_id}.m3u8
GET /{username}/{password}/{stream_id}
```
### VOD Streaming
```
GET /movie/{username}/{password}/{stream_id}.{ext}
Extensions: mp4, mkv, avi, 3gp, flv, wmv, mov, ts
```
### Series Streaming
```
GET /series/{username}/{password}/{stream_id}.{ext}
```
### Timeshift/Catchup
```
GET /timeshift/{username}/{password}/{duration}/{start}/{stream_id}
GET /timeshift/{username}/{password}/{duration}/{start}/{stream_id}.m3u8
Start format: YYYY-MM-DD:HH-MM or YYYYMMDD-HH
```
### HLS Segments
```
GET /hls/{username}/{password}/{stream_id}/{segment}.ts
```
---
## Other Endpoints
### XMLTV/EPG
```
GET /xmltv.php?username={user}&password={pass}&prev_days=1&next_days=3
```
### Playlist Generator
```
GET /get.php?username={user}&password={pass}&type=m3u_plus&output=ts
Types: m3u, m3u_plus, m3u8
Outputs: ts, m3u8, rtmp
```
+424
View File
@@ -0,0 +1,424 @@
# Xtream Codes - IPTV Patterns & Integrations
## 1. Stream URL Patterns
### Live TV URL Structure
```
http://{server}:{port}/live/{username}/{password}/{stream_id}.{extension}
```
| Extension | Use Case | Content-Type |
|-----------|----------|--------------|
| .ts | MPEG Transport Stream (most compatible) | video/mp2t |
| .m3u8 | HLS Adaptive Streaming | application/x-mpegurl |
### VOD URL Structure
```
http://{server}:{port}/movie/{username}/{password}/{stream_id}.{extension}
```
Container extensions: mp4, mkv, avi, 3gp, flv, wmv, mov, ts
### Series URL Structure
```
http://{server}:{port}/series/{username}/{password}/{episode_stream_id}.{extension}
```
### Timeshift/Catchup URL Structure
```
http://{server}:{port}/timeshift/{username}/{password}/{duration_minutes}/{start_time}/{stream_id}
```
Start time formats:
- `YYYY-MM-DD:HH-MM` (e.g., `2025-12-24:10-00`)
- `YYYYMMDD-HH` (e.g., `20251224-10`)
---
## 2. M3U Playlist Format
### Standard M3U Plus Format
```m3u
#EXTM3U
#EXTINF:-1 tvg-id="channel.epg" tvg-name="Channel Name" tvg-logo="http://icon.url" group-title="Category",Channel Name
http://server:25461/live/user/pass/123.ts
```
### Extended Attributes
| Attribute | Description |
|-----------|-------------|
| tvg-id | EPG channel identifier |
| tvg-name | Display name |
| tvg-logo | Channel icon URL |
| group-title | Category name |
| tvg-chno | Channel number |
| radio | "true" for radio streams |
### Catchup Support Tags
```m3u
#EXTINF:-1 tvg-id="channel.epg" catchup="default" catchup-source="http://server:25461/timeshift/user/pass/{duration:60}/{start}/123.ts" catchup-days="7",Channel Name
```
---
## 3. EPG/XMLTV Integration
### XMLTV Format
```xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE tv SYSTEM "xmltv.dtd">
<tv generator-info-name="Provider Name">
<channel id="channel.epg">
<display-name>Channel Name</display-name>
<icon src="http://icon.url"/>
</channel>
<programme start="20251224120000 +0000" stop="20251224130000 +0000" channel="channel.epg">
<title lang="en">Program Title</title>
<desc lang="en">Description</desc>
<category>News</category>
</programme>
</tv>
```
### EPG URL
```
http://server:25461/xmltv.php?username={user}&password={pass}
```
### EPG Mapping
The `tvg-id` attribute in M3U must match the `channel id` in XMLTV.
---
## 4. MAG/Stalker Portal Integration
### Authentication Flow
1. Device sends handshake with MAC address
2. Server returns token
3. Device includes token in all subsequent requests
4. Watchdog keeps session alive
### Required Headers
```
Authorization: Bearer {token}
Cookie: mac={mac_address}; timezone={timezone}; locale={locale}
X-User-Agent: Model: MAG254; Link: WiFi
```
### Stalker URL Encryption
For secure streaming, URLs are encrypted:
```php
$stalker_key = base64_encode(mc_encrypt("{$mac}={$ip}={$stream_id}={$expire_time}", $secret));
```
### Event Types
| Event | Description |
|-------|-------------|
| send_msg | Display message |
| reboot | Reboot device |
| reload_portal | Reload portal |
| play_channel | Auto-tune to channel |
| cut_off | Disconnect device |
---
## 5. Enigma2 Integration
### Service Reference Format
Enigma2 uses service references for channels:
```
#SERVICE 4097:0:1:0:0:0:0:0:0:0:http://server:25461/live/user/pass/123.ts:Channel Name
#DESCRIPTION Channel Name
```
### Bouquet File Format
```
#NAME Provider Bouquet
#SERVICE 4097:0:1:0:0:0:0:0:0:0:http://server:25461/live/user/pass/123.ts:Channel 1
#DESCRIPTION Channel 1
#SERVICE 4097:0:1:0:0:0:0:0:0:0:http://server:25461/live/user/pass/124.ts:Channel 2
#DESCRIPTION Channel 2
```
### XML Response Format
All Enigma2 API responses use XML with Base64-encoded text:
```xml
<channel>
<title>Q2hhbm5lbCBOYW1l</title> <!-- Base64: "Channel Name" -->
<description>RGVzY3JpcHRpb24=</description>
<stream_url><![CDATA[http://server/live/user/pass/123.ts]]></stream_url>
</channel>
```
---
## 6. HLS Streaming
### Playlist Structure
```m3u
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:3
#EXT-X-MEDIA-SEQUENCE:1000
#EXTINF:3.0,
123_1000.ts?token=abc123
#EXTINF:3.0,
123_1001.ts?token=def456
#EXTINF:3.0,
123_1002.ts?token=ghi789
```
### Segment Token Validation
Each segment URL includes a token:
```
token = md5(segment_name + username + crypt_key + filesize)
```
### Connection Tracking
- HLS connections tracked via `user_activity_now` table
- `hls_last_read` timestamp updated per segment request
- Inactive HLS connections cleaned up by cron
---
## 7. Load Balancing
### Server Selection
Load balancer selects optimal server based on:
- Server load (active connections)
- Geographic proximity
- Server status (online/offline)
- Stream availability
### Redirect Mechanism
```nginx
location /live/ {
proxy_pass http://load_balancer;
}
```
### Balance Configuration
`nginx/conf/balance.conf`:
```nginx
upstream streaming_servers {
server 192.168.1.1:25461 weight=5;
server 192.168.1.2:25461 weight=3;
server 192.168.1.3:25461 backup;
}
```
---
## 8. TV Archive/Catchup
### Archive Storage
```
/home/xtreamcodes/iptv_xtream_codes/tv_archive/{stream_id}/YYYY-MM-DD:HH-MM.ts
```
### Archive Duration
Configured per-stream via `tv_archive_duration` (days).
### Timeshift Playback
```bash
# Last 60 minutes from channel 123
curl "http://server/timeshift/user/pass/60/2025-12-24:10-00/123"
# HLS format for player apps
curl "http://server/timeshift/user/pass/60/2025-12-24:10-00/123.m3u8"
```
---
## 9. Multi-Server Architecture
### Server Roles
| Role | Description |
|------|-------------|
| Main | Database, panel, management |
| Load Balancer | Traffic distribution |
| Streaming | Stream transcoding/delivery |
### Inter-Server Communication
Via `system_api.php`:
- Connection state synchronization
- Stream start/stop commands
- User activity tracking
### Server Registration
Each server has unique `SERVER_ID` from config file.
---
## 10. Authentication & Security
### User Authentication Checks (in order)
1. Username/password validation
2. Account expiration check
3. Admin enabled check
4. User enabled check
5. IP whitelist check
6. Country restriction check
7. User agent validation
8. ISP restriction check
9. Max connections check
10. Bouquet access check
### Security Features
| Feature | Description |
|---------|-------------|
| GeoIP | Country-based restrictions |
| ISP Lock | Restrict to specific ISPs |
| IP Whitelist | Per-user allowed IPs |
| UA Whitelist | Per-user allowed user agents |
| Max Connections | Concurrent connection limit |
| Flood Protection | Rate limiting failed auth |
### Play Token System
For MAG devices:
```
play_token = random_string:expire_timestamp:stream_id
```
Validated before streaming to prevent URL sharing.
---
## 11. Bouquet System
### Bouquet Structure
Bouquets group streams and categories for user access control.
```json
{
"bouquet_id": 1,
"bouquet_name": "Basic Package",
"bouquet_channels": [1, 2, 3, 4, 5],
"bouquet_series": [10, 11, 12],
"bouquet_movies": [100, 101, 102]
}
```
### User Bouquet Assignment
```json
{
"user_id": 100,
"bouquet": [1, 2, 3] // User has access to bouquets 1, 2, and 3
}
```
### Category-Based Access
Categories can be assigned to bouquets for bulk access control.
---
## 12. Reseller System
### Reseller Hierarchy
```
Admin
├── Reseller 1
│ ├── User A
│ ├── User B
│ └── Sub-reseller 1.1
│ └── User C
└── Reseller 2
└── User D
```
### Credit System
Resellers have credits to create/extend users:
- 1 credit = 1 month subscription
- Credits deducted on user creation/extension
- Admin can add credits to resellers
### Reseller Permissions
| Permission | Description |
|------------|-------------|
| add_user | Can create users |
| edit_user | Can modify own users |
| delete_user | Can delete own users |
| add_mag | Can register MAG devices |
| add_e2 | Can register Enigma2 |
| allowed_ips | Restrict reseller panel access |
---
## 13. Output Formats
### User-Allowed Formats
```json
{
"allowed_output_formats": ["ts", "m3u8", "rtmp"]
}
```
### Format Handling
| Format | Handler | Use Case |
|--------|---------|----------|
| ts | clients_live.php | Direct streaming |
| m3u8 | clients_live.php | HLS adaptive |
| rtmp | rtmp handler | Flash players |
### Container Mapping
```php
$containers = [
'ts' => 'video/mp2t',
'm3u8' => 'application/x-mpegurl',
'mp4' => 'video/mp4',
'mkv' => 'video/x-matroska',
'avi' => 'video/x-msvideo'
];
```
---
## 14. Client Activity Tracking
### Activity Table Structure
```sql
user_activity_now (
activity_id INT PRIMARY KEY,
user_id INT,
stream_id INT,
server_id INT,
user_agent VARCHAR,
user_ip VARCHAR,
container VARCHAR,
pid INT,
date_start INT,
geoip_country_code VARCHAR,
isp VARCHAR,
external_device VARCHAR,
hls_last_read INT,
hls_end TINYINT
)
```
### Connection Lifecycle
1. INSERT on stream start
2. UPDATE `hls_last_read` for HLS
3. DELETE on stream end
4. Archive to `user_activity` for history
---
## 15. Error Handling Patterns
### Graceful Degradation
```php
// Show alternative video on errors
ipTV_streaming::ShowVideo($is_restreamer, 'show_not_on_air_video', 'not_on_air_video_path', $extension);
```
### Video Placeholders
| Setting | Description |
|---------|-------------|
| show_expired_video | Show when user expired |
| show_banned_video | Show when user banned |
| show_not_on_air_video | Show when stream offline |
### Client Logging
All access attempts logged for debugging:
```php
ipTV_streaming::ClientLog($stream_id, $user_id, 'ERROR_CODE', $user_ip, $extra_data);
```
+118
View File
@@ -0,0 +1,118 @@
# Xtream Codes IPTV Panel - API Documentation
This documentation package provides comprehensive analysis of all API endpoints in the Xtream Codes v2.9.2 IPTV panel.
## Documentation Files
| File | Description |
|------|-------------|
| [XTREAM_CODES_API_DOCUMENTATION.md](XTREAM_CODES_API_DOCUMENTATION.md) | **Main Documentation** - Complete API reference with all endpoints, parameters, responses, and examples |
| [ENDPOINT_REFERENCE.md](ENDPOINT_REFERENCE.md) | Quick reference table of all endpoints and their parameters |
| [IPTV_PATTERNS_AND_INTEGRATIONS.md](IPTV_PATTERNS_AND_INTEGRATIONS.md) | IPTV-specific patterns, integrations, and technical details |
## API Summary
### Discovered APIs
| API | Endpoint | Auth Method | Purpose |
|-----|----------|-------------|---------|
| Player API | `/player_api.php` | Username/Password | Client applications |
| Panel API | `/panel_api.php` | Username/Password | Panel applications |
| Admin API | `/api.php` | IP-Based | Server management |
| System API | `/system_api.php` | IP-Based | Inter-server communication |
| MAG Portal | `/portal.php` | MAC/Token | MAG STB devices |
| Enigma2 | `/enigma2.php` | Username/Password | Enigma2 receivers |
| EPG/XMLTV | `/xmltv.php` | Username/Password | Program guide |
| Playlist | `/get.php` | Username/Password | M3U generation |
### Streaming Endpoints
| Type | URL Pattern |
|------|-------------|
| Live TV | `/live/{user}/{pass}/{stream_id}.{ts\|m3u8}` |
| VOD/Movies | `/movie/{user}/{pass}/{stream_id}.{ext}` |
| TV Series | `/series/{user}/{pass}/{stream_id}.{ext}` |
| Timeshift | `/timeshift/{user}/{pass}/{duration}/{start}/{stream_id}` |
| HLS Segments | `/hls/{user}/{pass}/{stream_id}/{segment}.ts` |
## Quick Start
### 1. Authenticate
```bash
curl "http://SERVER:25461/player_api.php?username=USER&password=PASS"
```
### 2. Get Live Channels
```bash
curl "http://SERVER:25461/player_api.php?username=USER&password=PASS&action=get_live_streams"
```
### 3. Play Stream
```bash
ffplay "http://SERVER:25461/live/USER/PASS/STREAM_ID.ts"
```
## Key Findings
### Total API Endpoints Documented
- **Player API**: 10 actions
- **Panel API**: 2 actions
- **Admin API**: 15+ sub-actions
- **MAG Portal**: 40+ type/action combinations
- **Enigma2 API**: 10 types
- **Streaming**: 5 endpoint patterns
### Authentication Methods
1. Username/Password (most common)
2. IP-Based (admin APIs)
3. MAC Address + Token (MAG devices)
4. Play Token (secure streaming)
### Security Features
- GeoIP country restrictions
- ISP locking
- IP whitelisting
- User agent filtering
- Rate limiting (20 req/sec)
- Flood protection
- Max connection limits
### Output Formats
- Transport Stream (TS)
- HLS (M3U8)
- MP4, MKV, AVI, FLV, WMV, MOV, 3GP
- XML (Enigma2, XMLTV)
- JSON (Player/Panel APIs)
## Source Code Analyzed
```
/home/xtream-codes-decoded/
├── wwwdir/
│ ├── api.php # Admin API
│ ├── player_api.php # Player API
│ ├── panel_api.php # Panel API
│ ├── system_api.php # System API
│ ├── portal.php # MAG Portal (1300+ lines)
│ ├── enigma2.php # Enigma2 API
│ ├── xmltv.php # EPG/XMLTV
│ ├── get.php # Playlist generator
│ ├── init.php # Bootstrap
│ ├── includes/
│ │ ├── functions.php
│ │ ├── lib.php
│ │ ├── streaming.php
│ │ └── mysql.php
│ └── streaming/
│ ├── clients_live.php # Live streaming
│ ├── clients_movie.php # VOD streaming
│ └── timeshift.php # Catchup
└── nginx/conf/
└── nginx.conf # URL routing
```
## Analysis Date
December 24, 2025
## Software Version
Xtream Codes v2.9.2
File diff suppressed because it is too large Load Diff