Skip to content

Latest commit

 

History

History
228 lines (181 loc) · 4.99 KB

File metadata and controls

228 lines (181 loc) · 4.99 KB

RTP Play API Reference

Quick Example

// Node.js
const RTPPlayAPI = require('./node/rtpplay_api');
const api = new RTPPlayAPI();
const channels = await api.getChannels();
# Python
from python.rtpplay_api import RTPPlayAPI
api = RTPPlayAPI()
channels = api.get_channels()

Authentication

Static iOS credentials (auto-managed):

  • Token valid: ~8 hours
  • Auto-refresh: yes
  • Rate limits: none

Endpoints

Channels

getChannels() - All channels (TV + Radio)

const channels = await api.getChannels();
// [{channel_id: "5", channel_name: "RTP1", ...}]

getLiveTVChannels() - Live TV channels with EPG

const tvChannels = await api.getLiveTVChannels();

getLiveRadioChannels() - Live radio channels

const radioChannels = await api.getLiveRadioChannels();

getChannel(channelId) - Channel details

const channel = await api.getChannel('5'); // RTP1

getChannelEPG(channelId, date) - TV guide

const epg = await api.getChannelEPG('5', '2024-01-15');
// date optional, defaults to today

Programs

getPrograms(options) - List programs

const programs = await api.getPrograms({
    limit: 30,              // optional, default 30
    categoryId: null,       // optional filter
    orderType: 'desc',      // optional: 'desc' | 'asc'
    broadcaster: 'tv',      // optional: 'tv' | 'tvlinear' | 'radio'
    includeEpisode: true    // optional, default true
});

getProgram(programId) - Program details

const program = await api.getProgram('1743');

listEpisodes(programId, options) - All episodes

const episodes = await api.listEpisodes('1743', {
    page: 1,           // optional, default 1
    orderType: 'desc'  // optional: 'desc' | 'asc'
});

getEpisode(programId, episodeId, includeAssets) - Episode with video

const episode = await api.getEpisode('1743', '199022', true);
console.log(episode.assets); // [{url: "https://...", type: "video"}]

Discovery

search(query, page) - Search content

const results = await api.search('telejornal', 1);
// {programs: [...]}

getPopular(options) - Popular content

const popular = await api.getPopular({
    assetType: '',  // optional filter
    page: 1         // optional, default 1
});

getCategories() - Content categories

const categories = await api.getCategories();
// {categories: [{id: "1", name: "News"}]}

getCollection(collectionId) - Collection details

const collection = await api.getCollection('123');

getSlideshow() - Featured content

const slideshow = await api.getSlideshow();

getAsset(assetId) - Media asset

const asset = await api.getAsset('392203');

Complete Example

// Node.js - Get video URL from latest episode
const RTPPlayAPI = require('./node/rtpplay_api');

async function getLatestVideo() {
    const api = new RTPPlayAPI();

    // Find program
    const results = await api.search('telejornal');
    const programId = results.programs[0].program_id;

    // Get latest episode
    const episodes = await api.listEpisodes(programId, { page: 1 });
    const episodeId = episodes.episodes[0].episode_id;

    // Get video URL
    const episode = await api.getEpisode(programId, episodeId, true);
    const videoUrl = episode.assets.find(a => a.type === 'video').url;

    console.log('Video URL:', videoUrl);
}

getLatestVideo();
# Python - Get video URL from latest episode
from python.rtpplay_api import RTPPlayAPI

def get_latest_video():
    api = RTPPlayAPI()

    # Find program
    results = api.search('telejornal')
    program_id = results['programs'][0]['program_id']

    # Get latest episode
    episodes = api.list_episodes(program_id, page=1)
    episode_id = episodes['episodes'][0]['episode_id']

    # Get video URL
    episode = api.get_episode(program_id, episode_id, include_assets=True)
    video_url = next(a['url'] for a in episode['assets'] if a['type'] == 'video')

    print(f'Video URL: {video_url}')

get_latest_video()

Response Structures

Channel:

{
  "channel_id": "5",
  "channel_name": "RTP1",
  "channel_type": "tvlinear",
  "channel_image": "https://...",
  "channel_live": "1"
}

Program:

{
  "program_id": "1743",
  "title": "Telejornal",
  "description": "...",
  "latest_episode": {
    "episode_id": "199022",
    "title": "..."
  }
}

Episode with Assets:

{
  "episode_id": "199022",
  "program_id": "1743",
  "title": "...",
  "assets": [{
    "asset_id": "392203",
    "type": "video",
    "url": "https://streaming-vod.rtp.pt/.../manifest.m3u8",
    "format": "hls"
  }]
}

Tips

  • Reuse API instance (tokens are cached)
  • Add delays for bulk requests
  • Date format: YYYY-MM-DD
  • Check paging object for pagination
  • Assets array may contain multiple formats (HLS, MP4, etc.)