RESTFULAPI-Plugin for VDR


Version 0.1.1
Copyright © 2011 yavdr-Team, Michael Eiler

Organization/Community: team@yavdr.org
Developer: eiler.mike@gmail.com or aelo@yavdr.org
www.yavdr.org
www.github.com/yavdr/vdr-plugin-restfulapi


Table Of Contents


Preface



This plugin has been developed to offer a modern API for other developers to communicate with the VDR.
The plugin supports the following outputs formats: xml, json and html.
It also supports the folloing input formats: json and html.

It would not exist without the help of the following people:


This document describes the API and how to use it. It contains a lot of examples for the different formats and services but there is still a lot more to discover if you simply try to make a few simple requests.

Requirements



Someone who wants to install the plugin on his/her VDR needs following applications and libraries:
Someone who wants to develop an application which uses this API:

Configuration



Create a new file called plugin.restfulapi.conf in /etc/vdr/plugins/ .

# # Command line parameters for vdr-plugin-restfulapi # --port=8002 --ip=0.0.0.0 --epgimages=/var/cache/vdr/epgimages --channellogos=/usr/share/vdr/channel-logos



Channels



This service returns a list of channels.

The Request:

Method: GET

Examples:

GET http://<ip>:<port>/channels/.<format>
GET http://<ip>:<port>/channels/<channelid>.<format>
GET http://<ip>:<port>/channels/.<format>?start=<int>&limit=<int>


Description of the Parameters:



Example Result:

GET http://127.0.0.1:8002/channels.xml?start=0&limit=1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<channels xmlns="http://www.domain.org/restfulapi/2011/channels-xml">
 <channel>
  <param name="name"<ORF1 HD</param>
  <param name="number">1</param>
  <param name="channel_id">C-71-71-61920</param<
  <param name="image">true</param>
  <param name="group">hd</param>
  <param name="transponder">330</param>
  <param name="stream">C-71-71-61920.ts</param>
  <param name="is_atsc">false</param>
  <param name="is_cable">true</param>
  <param name="is_sat">false</param>
  <param name="is_terr">false</param>
 </channel>
 <count>1</count>
 <total>259</total>
</channels>

GET http://127.0.0.1:8002/channels.json?start=0&limit=1

{ "channels": [
{
"name":"ORF1 HD",
"number":1,
"channel_id":"C-71-71-61920",
"image":true,
"group":"hd",
"transponder":330,
"stream":"C-71-71-61920.ts",
"is_atsc":false,
"is_cable":true,
"is_terr":false,
"is_sat":false
}],
"count":1,
"total":259
}

Groups


This service will return a list containing all channel groups.

The Request:

Method: GET

Examples:

GET http://<ip>:<port>/channels/groups
GET http://<ip>:<port>/channels/groups?start=<int>&limit=<int>
GET http://<ip>:<port>/channels.<format>?group=<group>


Description of the Parameters



Example Result:

GET http://<ip>:<port>/channels/groups?start=0&limit=3

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<groups xmlns="http://www.domain.org/restfulapi/2011/groups-xml">
 <group>hd</group>
 <group>main</group>
 <group>stuff</group>
 <count>3</count>
 <total>3</total>
</groups>

GET http://<ip>:<port>/channels/groups?start=0&limit=3

{
"groups":
[
"hd",
"main",
"stuff"
],
"count":3,
"total":3
}

Images / Channel-Logos


This service returns the requested channel-logo.

XML or JSON Parser (Depends on which format you want to use!) URL Decoder Method: GET

Examples:

GET http://<ip>:<port>/channels/image/<channelid>



Events / EPG



This service returns the epg information.

Method: GET

Examples:

GET http://<ip>:<port>/events/<channelid>.<format>?timespan=<timespan>
GET http://<ip>:<port>/events/<channelid>/<eventid>.<format>
GET http://<ip>:<port>/events/<channelid>.<format>?timespan=<timespan>
GET http://<ip>:<port>/events/<channelid>.<format>?timespan=<timespan>&from=<from>&start=<int>&limit=<int>


Description of the Parameters:



Example Result:

GET http://<ip>:<port>/events/C-1-1011-11110/3600.xml?start=0&limit=1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<events xmlns="http://www.domain.org/restfulapi/2011/events-xml">
 <event>
  <param name="id">51514</param>
  <param name="title">Eine Serie</param>
  <param name="short_text">Der Episodentitel</param>
  <param name="description">Die Beschreibung</param>
  <param name="channel">C-1-1011-11110</param>
  <param name="start_time">1308845100</param>
  <param name="duration">3300</param>
  <param name="images">1</param>
  <param name="components">    <component stream="5" type="11" language="deu" description="H.264/AVC high definition Video, 16:9 aspect ratio," />    <component stream="2" type="3" language="deu" description="stereo deutsch" />    <component stream="2" type="3" language="eng" description="stereo englisch" />    <component stream="2" type="5" language="deu" description="Dolby Digital 2.0" />   </param>   <param name="timer_exists">true</param>   <param name="timer_active">true</param>   <param name="timer_id">C-71-71-61920:0:1315173600:2100:2300</param>  </event>
 <count>1</count>
 <total>236</total>
</events>

GET http://<ip>:<port>/events/C-1-1011-11110/3600.json?start=0&limit=1

{"events":[{
"id":51514,
"title":"Eine Serie",
"short_text":"Der Episodentitel",
"description":"Die Beschreibung",
"start_time":1308845100,
"duration":3300,
"images":3,
"count":1,
"timer_exists":true,
"timer_active":true,
"timer_id":"C-71-71-61920:0:1315173600:2100:2300",
"components":[
{"stream":5, "type":11, "language":"deu", "description":"H.264\/AVC high definition Video, 16:9 aspect ratio,"},
{"stream":2,"type":3,"language":"deu","description":"stereo deutsch"},
{"stream":2,"type":3,"language":"eng","description":"stereo englisch"},
{"stream":2,"type":5,"language":"deu","description":"Dolby Digital 2.0"}],
"total":236}

Images


This service returns the requested epg image.

Method: GET

Examples:

GET http://<ip>:<port>/events/image/<eventid>/<imagenumber>


Description of the Parameters:

Search

This service allows you to search for events.

The Request:

Method: POST

Example URL:

POST http://<ip>:<port>/events/search.<format>?limit=5&start=0;

HTTP-Body-Parameters:

Example:
{"query":"Asterix", "mode":0, "channelid":0,"use_title":true}



Info


General Information about the plugin and vdr.

Examples:

GET http://<ip>:<port>/info.<format>

Example Results:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <info xmlns="http://www.domain.org/restfulapi/2011/info-xml"> <version>0.0.1</version> <time>1311710291</time> <services> <service path="/info" version="1" internal="true" /> <service path="/channels" version="1" internal="true" /> <service path="/channels/groups" version="1" internal="true" /> <service path="/channels/image" version="1" internal="true" /> <service path="/events" version="1" internal="true" /> <service path="/events/image" version="1" internal="true" /> <service path="/events/search" version="1" internal="false" /> <service path="/recordings" version="1" internal="true" /> <service path="/remote" version="1" internal="true" /> <service path="/timers" version="1" internal="true" /> <service path="/osd" version="1" internal="true" /> <service path="/searchtimers" version="1" internal="false" /> </services> <channel>C-71-71-61920</channel> <vdr> <plugins> <plugin name="restfulapi" version="0.0.1" /> <plugin name="shutdown" version="0.0.2" /> <plugin name="vnsiserver" version="0.9.0" /> <plugin name="live" version="0.2.0" /> <plugin name="epgsearchonly" version="0.0.1" /> <plugin name="svdrposd" version="0.1.0" /> <plugin name="xineliboutput" version="1.0.90-cvs" /> <plugin name="streamdev-server" version="0.5.1-git" /> <plugin name="epgsearch" version="0.9.25.beta22" /> <plugin name="quickepgsearch" version="0.0.1" /> <plugin name="text2skin" version="1.3.1" /> <plugin name="conflictcheckonly" version="0.0.1" /> </plugins> </vdr> </info>

Instead of the channel it can also contain the currently playing video file:

<video name="Asterix in Amerika">/var/lib/video.00/Asterix_in_Amerika/2011-06-19.12.40.1-0.rec</video>



Osd


OSD

Examples:

GET http://<ip>:<port>/osd.<format>

Example Results:

{"TextOsd":{"type":"TextOsd","title":"VDR - Disk 68% - 57:53 free","message":"","red":"","green":"Audio","yellow":"","blue":"Stop","items":[{"content":" 1 Schedule","is_selected":true},{"content":" 2 Channels","is_selected":false},{"content":" 3 Timers","is_selected":false},{"content":" 4 Recordings","is_selected":false},{"content":" 5 Search","is_selected":false},{"content":" 6 Media Player","is_selected":false},{"content":" 7 Program guide","is_selected":false},{"content":" 8 Quick search","is_selected":false},{"content":" 9 Timer conflicts","is_selected":false},{"content":" 10 Setup","is_selected":false},{"content":" 11 Commands","is_selected":false},{"content":" Stop replaying","is_selected":false}]}}


{"ProgrammeOsd":{"present_time":1311710264,"present_title":"Der letzte Bulle","present_subtitle":"Ich hab sie alle gehabt","following_time":1311713161,"following_title":"direkt - das magazin","following_subtitle":""}}



Recordings



This service can delete recordings and can also return all the recordings as a list.

The Request:

Method: GET, DELETE

Examples:

GET http://<ip>:<port>/recordings/.<format>
GET http://<ip>:<port>/recordings/<recordingnumber>.<format>?marks=true
DELETE http://<ip>:<port>/recordings/<number>


Description of the Parameters:



Example Result:

GET http://127.0.0.1:8002/recordings.xml?start=0&limit=1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recordings xmlns="http://www.domain.org/restfulapi/2011/recordings-xml">
 <recording>
  <param name="number">0</param>
  <param name="name">Asterix in Amerika</param>
  <param name="filename">/var/lib/video.00/Asterix_in_Amerika/2011-06-19.12.40.1-0.rec</param>
  <param name="is_new">false</param>
  <param name="is_edited">false</param>
  <param name="is_pes_recording">false</param>
  <param name="duration">-1</param>
  <param name="frames_per_second">50</param>
  <param name="marks"><0:03:17.10><1:43:07.24></param>
  <param name="event_title">Asterix in Amerika</param>
  <param name="event_short_text"></param>
  <param name="event_description">(Zeichentrickfilm, DEU 1994)</param>
  <param name="event_start_time">1308480705</param>
  <param name="event_duration">4611</param>
 </recording>
 <count>2</count><total>2</total>
</recordings>

GET http://127.0.0.1:8002/recordings.json?start=0&limit=1i&marks=true

{"recordings":[{
"number":0,
"name":"Asterix in Amerika",
"file_name":"\/var\/lib\/video.00\/Asterix_in_Amerika\/2011-06-19.12.40.1-0.rec",
"is_new":false,
"is_edited":false,
"is_pes_recording":false,
"duration":-1,
"frames_per_second":50,
"marks":["0:03:17.10", "1:43:07.24"],
"event_title":"Asterix in Amerika",
"event_short_text":"",
"event_description":"(Zeichentrickfilm, DEU 1994)",
"event_start_time":1308480705,
"event_duration":4611
}],"count":1,"total":2}



Cut

This service tells your VDR to cut a recording or can tell the client if the vdr cutter is currently cutting a recording:

Method: GET, POST

Examples:

POST http://<ip>:<port>/recordings/cut/<recordingnumber> # do it! (cut the recording)
GET http://<ip>:<port>/recordings/cut.<format> # this will return the status of the VDR Cutter


Marks

This service can save and delete marks. To retrieve them use the parameter "marks=true" in the request url for the recordings.

Delete Cutting Marks:

Method: DELETE

Examples:

DELETE http://<ip>:<port>/recordings/marks/<recordingnumber>

Create new Cutting Marks:

Method: POST

Examples:

POST http://<ip>:<port>/recordings/marks/<recordingnumber>


Example Body-Content (required, Only JSON supported):

{'marks':['0:02:18.10','0:34:08.24']}



Remote



This service retrieves remote commands and sends them to VDR:

Method: POST

Syntax:

POST http://<ip>:<port>/remote/<key>
POST http://<ip>:<port>/remote/switch/<channelid>

The parameter <key> can be set to the following remote control commands:

Up, Down, Menu, Ok, Back, Left, Right, Red, Green, Yellow, Blue, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, Info, Play, Pause, Stop, Record, FastFwd, FastRew, Next, Prev, Power, ChanUp, ChanDn, ChanPrev, VolUp, VolDn, Mute, Audio, Subtitles, Schedule, Channels, Timers, Recordings, Setup, Commands, User0, User1, User2, User3, User4, User5, User6, User7, User8, User9, None, Kbd

The second address allows to directly switch to a specific channel.


Timers



Reading/Deleting Timers


This service returns a list of timers.

The Request:

Method: GET, DELETE

Examples:

GET http://<ip>:<port>/timers.<format>
GET http://<ip>:<port>/timers/<timerid>.<format>
GET http://<ip>:<port>/timers.<format>?start=<int>&limit=<int>
DELETE http://<ip>:<port>/timers/<timerid>


Description of the Parameters:



Example Result:

GET http://127.0.0.1:8002/timers.xml?start=0&limit=1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<timers xmlns="http://www.domain.org/restfulapi/2011/timers-xml">
 <timer>
  <param name="id">C-71-71-61920:0:1309039200:2013:2200</param>
  <param name="start">2013</param>
  <param name="stop">2200</param>
  <param name="start_timestamp">2011-12-24 19:00:00</param>   <param name="stop_timestamp">2011-12-24 20:00:00</param>   <param name="priority">50</param>
  <param name="lifetime">99</param>
  <param name="event_id">27312</param>
  <param name="weekdays">-------</param>
  <param name="day">2011-06-26</param>
  <param name="channel">C-71-71-61920</param>
  <param name="is_recording">false</param>
  <param name="is_pending">false>/param>
  <param name="filename">Mad Money>/param>
  <param name="channel_name">ORF1 HD>/param>
  <param name="is_active">true>/param>
 </timer>
 <count>1</count><total>2</total>
</timers>

GET http://127.0.0.1:8002/timers.json?start=0&limit=1


Creating Timers


This service can create new timers.

Method: POST

Example:

POST http:/<ip>:<ip>/timers

Required Body Parameters:

Example Request (including HTTP-Header):

POST /timers HTTP/1.1
Content-Length: 98
Connection: close

file=Ein%20Film&flags=1&start=1400&stop=1615&day=2011-12-24&channel=C-71-71-61920&weekdays=-------

Example Response (including HTTP-Header):

HTTP/1.1 200 OK
Content-Length: 0
Server: cxxtools-Http-Server 2.0
Connection: close
Date: Sun, 26 Jun 2011 19:03:48 GMT

Updating Timers


This service can update the previously created timers.

Method: PUT

Example:

PUT http://<ip>:<port>/timers

Required Body Parameters:

Optional Body Parameters are the ones you use to create the timer and now want to update.

Example Request (including HTTP-Header):

PUT /timers HTTP/1.1
Content-Length: 81
Connection: close

timer_id=C-71-71-61920:0:1324681200:1400:1615&start=2015&stop=2230

Example Response (including HTTP-Header):

HTTP/1.1 200 OK
Content-Length: 0
Server: cxxtools-Http-Server 2.0
Connection: close
Date: Sun, 26 Jun 2011 19:20:03 GMT



SearchTimers



Create a SearchTimer



POST http://<ip>:<port>/searchtimers

Possible parameters:


Delete a SearchTimer


DELETE http://<ip>:<port>/searchtimers/<id>


Show one SearchTimer


GET http://<ip>:<port>/searchtimers.<format>


Search Events of a SearchTimer


GET http://<ip>:<port>/searchtimers/search/<id>