Archive:Web Server HTTP API

From Official Kodi Wiki
Revision as of 15:25, 26 June 2006 by >Dankula (→‎Retrieving information commands)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Webserver Commands (HTTPAPI)

The list below is an active updated list of all the httpapi commands availible but if you wish to view the outdated one it can be downloaded from: http://prdownloads.sourceforge.net/xbmc/apiDoc.doc?download

This page is currently in the process of being built so commands with no explination have not yet been fully tested or else I'm still trying to figure out what exactly they do if anything :) please bare with while I figure them out. -TeknoJuce

HTTPAPI DOC

This document provides information on XBMC’s Application Programming Interface (API). The API operates over the HyperText Transfer Protocol and hence is called the HTTPAPI.

The same set of commands is now also available over ASP and from Python.

Getting started

The XBMC HTTP API provides a mechanism for a networked device (e.g. a PC or a PDA with WiFi) to interact with XBMC. The API provides access to XBMC status information and control of XBMC functions.

The API can be called from and results displayed in a standard web browser which is probably the easiest way to experiment with these commands. Fire up your browser and enter the following into the address field:

http://xbox/xbmcCmds/xbmcHttp?command=getcurrentlyplaying

Information about the media currently being played by XBMC will be displayed, if nothing is being played then "[Nothing Playing]" will be displayed.

If you want to control the volume of XBMC enter the following into your browser’s address field:

http://xbox/xbmcCmds/xbmcHttp?command=setvolume&parameter=80

"OK" will be displayed and the volume will be set to 80% which you will probably find is rather quiet.

If you find that the above commands don’t work then check that:

  • The address "xbox" is understood by your browser to point to your Xbox’s address. You may need to enter the full IP address e.g. 192.168.0.1
  • The XBMC web server has been turned on. This setting can be found in Settings, Network, Server.
  • You didn’t mistype the command.


Note: If you are a Windows user, you can configure a name for your Xbox's IP address. Edit with your favorite text editor the file “host” inside C:\WINDOWS\system32\drivers\etc\ and add a line at the end with your xbox ip address.

192.168.0.1 xbox

Save it (don't need to restart) and test if the command “ping xbox” works. You should now resolve your Xbox IP address

If you still can’t get them working, try:

http://xbox

This should display the default XBMC web page. If this does not work then check out other XBMC documentation on the web server and come back when it is working.

Once you have the above working we can look at the structure of the http command line.

All API commands start with the following:

http://xbox/xbmcCmds/xbmcHttp?command=

(Remember you may need to swap “xbox” for the IP address.)

The next part of the line is the command itself, which in the two examples above are "getCurrentlyPlaying" and "setVolume". The command is not case sensitive: "SetVolume", "setvolume" and "SETVOLUME" can also be used.

If the command takes parameters then "&parameter=" is added after the command.

Finally comes the parameter values. If there are multiple parameters then each value is separated by a semi-colon ";". The following is an example of a command with 4 parameters.

http://xbox/xbmcCmds/xbmcHttp?command=takescreenshot&parameter=test.jpg,300,200,90

Response Structure

The API returns information in a consistent form but which is dependent on the type of information returned. Those commands which:

  • don’t return a value e.g. SetVolume return the standard response OK
  • return a single value e.g. GetVolume return just the value
  • return multiple values e.g. GetCurrentlyPlaying return multiple lines with each line having the format
    • name:value

An error in the execution of a command, for example a missing parameter, is indicated by the response:

Error[:Reason]

i.e. all errors are indicated by returning "Error" and depending on the error there may be additional information provided.

e.g.

Error:Missing parameter

The following is the default response format. To change the format see the command SetResponseFormat.

Every line in the response is prefixed by the HTML tag <li>. The only exception to this is the GetThumb command where a prefix is not included. The use of this prefix means that the responses are displayed clearly within a browser but the <li> tag does not require a corresponding close tag i.e. </li> is not required.

Finally, and to create a valid HTML response, the whole response is top and tailed with the web server’s default header and footer.

ASP

The commands are also available as ASP commands using the command "xbmcAPI" just as the current "xbmcCommand" works now (see default.asp in the XBMC web directory). All xbmcAPI commands have an identical name and the same parameters as the commands listed in the document. The response structure is also identical apart from the web server’s default header and footer which will not be present.

e.g.

Response = xbmcAPI("GetCurrentlyPlaying");


Python

The commands are also callable from Python scripts through the function executehttpapi imported from the xbmc module. All xbmcAPI commands have an identical name and the same parameters as the commands listed in the document. The response structure is also identical apart from the web server’s default header and footer which will not be present.

e.g.

import xbmc

response = xbmc.executehttpapi("TakeScreenShot(q:\\test.jpg,0,false,200,-1,90)") 


The Commands

This section presents a complete list of HTTP API commands. In the list, after the command name is presented, the text between the parentheses is the list of semi-colon separated parameters for the command.

Remember to use the syntax:

http://xbox/xbmcCmds/xbmcHttp?command=setvolume&parameter=80

and not

http://xbox/xbmcCmds/xbmcHttp?command=setvolume(80)


A parameter in square brackets is optional. An optional parameter typically specifies an alternative to a default value.

In the following list the Playlist parameter identifies one of the four available playlists by using the values 0..3:

0. Music playlist
1. Temporary music playlist
2. Video playlist
3. Temporary video playlist

These playlists should not be confused with:

The slideshow playlist. The slideshow commands implicitly refer to the latter. Playlist files e.g m3u files.


The commands are presented in five sections. Those commands that:

  • retrieve information
  • set/modify information
  • perform/initiate an action
  • perform an action on a file
  • don’t fit into one of the above and hence are miscellaneous
  • HTTPAPI commands and examples


Click on sample link it should load in you're browser window then edit the link: XBOXIP -Make it your Xbox IP-> 192.168.1.101 whatever that IP may be. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying -> http://192.168.1.101/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying


Retrieving information commands

Command Information Example
GetMediaLocation music, video, pictures, files; PATH; pathsonly http://XBOXIP/xbmcCmds/xbmcHttp?command=GetMediaLocation&parameter=files;smb:\\F\;pathsonly
GetMediaShare music, video, pictures, files; Pathsonly (0,1) http://XBOXIP/xbmcCmds/xbmcHttp?command=GetMediaShare&parameter=music;1
GetCurrentPlaylist Retrieves the current playlist identifier. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetCurrentPlaylist
GetCurrentlyPlaying Retrieves the filename, details and status of the currently playing media. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying
GetCurrentSlide Retrieves the file name of the image currently being displayed. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetCurrentSlide
GetDirectory directory;[mask];[option]

Retrieves the contents of the directory specified by directory. If the option parameter = 1 then file modified dates will be appended. The mask parameter can take the following form: .mp3 returns just the matching files "*" return just folders all files and folders.

http://XBOXIP/xbmcCmds/xbmcHttp?command=GetDirectory&parameter=F:\music\;.mp3;1
GetGuiDescription Retrieves various GUI values. (Currently just the screen resolution) http://XBOXIP/xbmcCmds/xbmcHttp?command=GetGUIDescription
GetGuiSetting type; name

Retrieves the value of GUI setting name. type specifies whether the setting is of type integer (0), boolean (1) or float (2).

http://XBOXIP/xbmcCmds/xbmcHttp?command=getguisetting&parameter=0;settingname
GetPercentage Retrieves the current playing position of the currently playing media as a percentage of the media’s length. http://XBOXIP/xbmcCmds/xbmcHttp?command=getpercentage
GetPlaylistContents [playlist]

Retrieves the contents (file names) of the current playlist or the playlist specified by playlist. 0 – Music playlist, 1 – Temporary music playlist, 2 – Video playlist, 3 – Temporary video playlist (I pretty much use 1 for everything doesnt seem to make much of a difference except that the temp list xbmc seems to use is 1 I've noticed.)

http://xbox/xbmcCmds/xbmcHttp?command=GetPlaylistContents&parameter=1
GetPlaylistSong [position]

Retrieves the currently playing song number in the playlist (basically just a number)

http://XBOXIP/xbmcCmds/xbmcHttp?command=GetPlaylistSong
GetPlaySpeed Retrieves the current playing speed. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetPlaySpeed
GetSlideshowContents Retrieves the contents (file names) of the slideshow playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetSlideshowContents
GetSystemInfo InfoID's

Retrives System Information like anything from the system info page in xbmc you can supply multipal numbers if you wish to retreive a bunch at a time GuiInfoManager This sample will get Version of XBMC & Build Date

http://XBOXIP/xbmcCmds/xbmcHttp?command=GetSystemInfo&parameter=120;121
GetSystemInfoByName infonames

Go down to the "CGUIInfoManager::TranslateSingleString" section and you will find all the strings GuiInfoManager

http://XBOXIP/xbmcCmds/xbmcHttp?command=GetSystemInfoByName&parameter=weather.location;weather.temperature
GetTagFromFilename filename

Retrieves information for the audio file filename

http://XBOXIP/xbmcCmds/xbmcHttp?command=GetTagFromFilename&parameter=F:\music\test.mp3
GetThumbFilename album;filename

Retrieves the file name of the corresponding thumbnail for the music media file with album name album and file name filename

http://XBOXIP/xbmcCmds/xbmcHttp?command=GetThumbFilename&parameter=album;F:\music\test.mp3
GetVolume Retrieves the current volume setting as a percentage of the maximum possible value. http://XBOXIP/xbmcCmds/xbmcHttp?command=GetVolume

Setting commands

Command Information Example
AddToPlayList(file/folder;[playlist];[mask]) Adds a file or folder to the current playlist or the playlist specified by playlist. To specify a file mask use mask. http://XBOXIP/xbmcCmds/xbmcHttp?command=AddToPlayList&parameter=F:/music/test2.mp3;1
AddToSlideshow(file/directory) Adds a file or directory file/directory to the slideshow playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=AddToSlideshow&parameter=F:\apps\xbmc\media\
ClearPlayList([playlist]) Clears the current playlist or the playlist specified by playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=ClearPlayList&parameter=1
ClearSlideshow Clears the slideshow playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=ClearSlideshow
RemoveFromPlaylist(filename,[playlist]) Removes the file filename from the current playlist or from playlist playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=RemoveFromPlaylist&parameter=f:\test2.mp3,1 <— need to know filenames in playlist
SeekPercentage Sets the playing position of the currently playing media as a percentage of the media’s length. http://XBOXIP/xbmcCmds/xbmcHttp?command=SeekPercentage&parameter=50
SeekPercentageRelative Adds/Subtracts the current percentage on to the current postion in the song http://XBOXIP/xbmcCmds/xbmcHttp?command=SeekPercentageRelative&parameter=-10
SetCurrentPlaylist(playlist) Sets the current playlist to the playlist with identifier{1} playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=SetCurrentPlaylist&parameter=1
SetGUISetting(type; name; value) Sets the value of GUI setting name to value. type specifies whether the setting is of type integer (0), boolean (1) or float (2). http://XBOXIP/xbmcCmds/xbmcHttp?command=SetGUISetting(type;name;value) (havnt tried yet)
SetPlaylistSong(position) Sets the media at playlist position position to be the next item to be played. play 6th song in playlist --> http://XBOXIP/xbmcCmds/xbmcHttp?command=SetPlaylistSong&parameter=5
SetPlaySpeed(speed) Sets the playing speed to the integer speed. http://XBOXIP/xbmcCmds/xbmcHttp?command=SetPlaySpeed&parameter(speed) (havnt tried currently)
SlideshowSelect(filename) Sets the slideshow playlist position. Filename specifies the next image to show. http://XBOXIP/xbmcCmds/xbmcHttp?command=SlideshowSelect&parameter=filename (didnt try it)
SetVolume Sets the volume as a percentage of the maximum possible volume value. http://XBOXIP/xbmcCmds/xbmcHttp?command=SetVolume&parameter=50
SetAutoGetPictureThumbs If set to True then media thumbnails will be automatically created when required. (Default: True.) http://XBOXIP/xbmcCmds/xbmcHttp?command=SetAutoGetPictureThumbs&parameter=false


Action commands

Command Information Example
Exit Reboots to dashboard http://XBOXIP/xbmcCmds/xbmcHttp?command=Exit
Move(deltaX, deltaY) Moves the currently displayed image in the direction specified by deltaX and deltaY. http://XBOXIP/xbmcCmds/xbmcHttp?command=Move&parameter=200;200 (Didnt work)
PlayListNext Starts playing the next media in the current playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=PlayListNext
PlayListPrev Starts playing the previous media in the current playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=PlayListPrev
PlayNext Starts playing/showing the next media/image in the current playlist or, if currently showing a slidshow, the slideshow playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=PlayNext
PlayPrev Starts playing/showing the previous media/image in the current playlist or, if currently showing a slidshow, the slideshow playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=PlayPrev
PlaySlideshow([directory];[recursive]) Starts the slideshow. directory specifies a folder of images to add to the slideshow playlist. If recursive has a value of True then all directories beneath directory are searched for images and added to the slideshow playlist. http://XBOXIP/xbmcCmds/xbmcHttp?command=PlaySlideshow&parameter=F:\pictures;true
PlayerPlayFile(filename) Starts playing the media file filename on the current playlist. BROKEN
Reset Resets XBMC http://XBOXIP/xbmcCmds/xbmcHttp?command=Reset
Restart Restarts XBOX http://XBOXIP/xbmcCmds/xbmcHttp?command=Restart
Rotate Rotates the currently displayed image by 90 degree clockwise. http://XBOXIP/xbmcCmds/xbmcHttp?command=Rotate
SendKey(buttoncode;[LeftTrigger];[RightTrigger];[LeftThumbX];[LeftThumbY] ;[RightThumbX];[RightThumbY]) Initiates a button, key or mouse event. Buttoncode specifies the type of event and the other parameters specify additional information that is specific to each buttoncode value. key.h{keycodes} (A button) --> http://XBOXIP/xbmcCmds/xbmcHttp?command=SendKey&parameter=256
ShowPicture(filename) Displays the image filename. http://XBOXIP/xbmcCmds/xbmcHttp?command=ShowPicture&parameter=F:\apps\xbmc\media\splash.png
Shutdown Shutdown XBOX http://XBOXIP/xbmcCmds/xbmcHttp?command=Shutdown
TakeScreenshot([filename];[flash];[rotation];[width];[height];[quality];[download];[imgtag]) o Captures the current contents of the Xbox screen.

 If no parameters then the action is the same as initiating a regular screenshot command with the image being saved in the screenshot directory.
 If filename is provided then the image is saved to filename.
 If flash=True the screen will flash as the command executes.
 If resolution, width, height and quality are given then those values are used to define the rotation (in degrees), resolution and jpeg quality of the saved image.
 If download = True then the image is downloaded to the client as a base64 encoded stream.
o The command must conform to one of:

 No parameters
 Filename, flash, rotation, width, height, quality
 Filename, flash, rotation, width, height, quality, download

NEW: imgtag is new it will put a Convert Base64 to image tag with the Base64 code so in firefox browsers it will show the image instead of the Base64 code.

http://XBOXIP/xbmcCmds/xbmcHttp?command=takescreenshot&parameter=test.jpg;true;0;300;200;90;true;imgtag
Zoom(magnification) Zooms the currently displayed image to a level specified by magnifaction. A magnification of 0 is the standard zoom level of none. Magnification can take values up to 8. http://XBOXIP/xbmcCmds/xbmcHttp?command=Zoom&parameter=4


File Commands

Command Information Example
FileCopy(sourceFilename, destinationFilename) Copies the Xbox file sourceFilename to the Xbox file desitinationFilename. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileCopy&parameter=F:\apps\xbmc\media\splash.png,E:\pictures\
FileDelete(filename) Deletes the Xbox file filename. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileDelete&parameter=F:\pictures\kim-smith-1024x768–22677.jpg
FileDownload(filename) Download a file specified by filename from the Xbox to the client as a base64 stream. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileDownload&parameter=F:\apps\xbmc\default.xbe
FileDownloadFromInternet(URL;[filename]) Downloads the file with address URL to the client as a base64 encoded stream. If the filename parameter is present, the downloaded file is also saved on the Xbox as the file filename. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileDownloadFromInternet&parameter=http://wallpapers.skins.be/kim-smith/kim-smith-1024x768–22677.jpg;F:\pictures\kim-smith-1024x768–22677.jpg

To test quickly: http://XBOXIP/xbmcCmds/xbmcHttp?command=ShowPicture&parameter=F:\pictures\kim-smith-1024x768–22677.jpg

FileExists(filename) Returns True if the Xbox file filename exists otherwise returns False. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileExists&parameter=F:\pictures\kim-smith-1024x768–22677.jpg
FileSize(filename) Returns the file size of filename. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileSize&parameter=F:\pictures\kim-smith-1024x768–22677.jpg
FileUpload(filename, contents) Uploads a file encoded as a base64 stream contents to the file filename on the Xbox. http://XBOXIP/xbmcCmds/xbmcHttp?command=FileUpload&parameter=filename,contents (havnt tried / no clue)


Miscellaneous commands

Command Information Example
ChooseAlbum(URL) Retrieves the cover image and review text of the album with URL URL as returned by the Lookup Album? command. http://XBOXIP/xbmcCmds/xbmcHttp?command=ChooseAlbum&parameter=http://www.allmusic.com/cg/amg.dll?p=amg&sql=10:e38e4j276wal <--Didnt work :(
Config(command; parameters) Provides access to the ASP configuration commands. command is the ASP command and parameters is a semi-colon separated list of parameters to accompany the command. For further information see: XBMCConfiguration.cpp http://XBOXIP/xbmcCmds/xbmcHttp?command=Config(command;parameters)
ExecBuiltIn(function) Executes the XBMC ‘built-in’ function function. For the list of available functions see: Manual:builtin functions OR ExecBuiltIn Functions http://XBOXIP/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=Notification(WARNING,SHUTTING%20DOWN%20SYSTEM!)
Help Displays a list of some (NOT ALL) of the HTTPApi commands http://XBOXIP/xbmcCmds/xbmcHttp?command=Help
LookupAlbum(album) Looks up the album with name album on an Internet music site and returns the resulting matches as a list with the format:album_name<@@>album_URL http://XBOXIP/xbmcCmds/xbmcHttp?command=LookupAlbum&parameter=legion%20of%20boom
SetResponseFormat(format; value) o Sets the format of the response from HTTPApi. Format takes one of the following:

 WebHeader – if True then the default web server header will be prepended to the response (ignored for Python and ASP responses).
 WebFooter – if True then the default web server footer will be appended (ignored for Python and ASP responses).
 Header – A user definable string that will be added after the WebHeader (if present) and before the main body of the response.
 Footer – A user definable string that will be before after the WebFooter (if present) and after the main body of the response.
 OpenTag – A user definable string that will be inserted before each element of the main response.
 CloseTag – A user definable string that will be inserted after each element of the main response. Whether to insert this tag after the final element is defined by the CloseFinalTag setting.
 CloseFinalTag – if True then the final element will have a closing tag.
o The default format values are:

 WebHeader=True
 WebFooter=True
 Header=””
 Footer=””

 OpenTag=”

  •  CloseTag=[carriage return]
     CloseFinalTag=False
  • http://XBOXIP/xbmcCmds/xbmcHttp?command=SetResponseFormat&parameter=WebHeader;False (and no you can't specify multipal formats only one after another)


    Name Changes

    To make the names of the commands more logical some have been changed. The old names are still recognised but it is strongly advised that the new names are now used.

    Old Name New Name
    CopyFile FileCopy
    DeleteFile FileDelete
    GetInternetFile FileDownloadFromInternet
    GetThumb FileDownload
    GUISetting SetGUISetting, GetGUISetting
    SetFile FileUpload
    SetKey SendKey