-
-
Notifications
You must be signed in to change notification settings - Fork 24
API
Official documentation for the Powder Web API.
- Introduction
- Authentication
- Getting User Settings
- List Available Streams
- Embedding in Websites
- Transcoding Streams
- Using History
- Torrents
- Youtube-DL Links
- AceStream Links
- SopCast Links
- Local Media
In order to use the Powder Web API, you need an access key, there are 2 types of access keys:
- user access key
- master key
The most common way of using the API is with a user access key, which is gotten by authenticating to the API with the user's email and password. The reason this is required is because user access keys are generated during the authentication process and have an expiration time.
For all API calls (except the authorisation call) the user access key or master key need to be added as the authorization
request header.
All API calls are GET http requests made to the /actions
endpoint, and all include a method
parameter.
The difference between a user access key and a master key is the power you will have with the API. Both access key types support starting downloads, playback and changing settings, but the master key will give access to administrator only settings.
The master key cannot be gotten through authentication, a master key is generated on app start and changes every time you start Powder Web, as it is meant to be used only locally to change advanced settings, not for the use with the API. The master key is printed in the terminal window that you started Powder Web from, and is only visible if you started Powder Web through a terminal.
To authenticate you need to create a GET request in the form to:
/actions?method=login&value=%7B%22email%22%3A%22test%40test.com%22%2C%22password%22%3A%22test%22%7D
-
The
method
parameter must belogin
for this call. -
The
value
parameter must be a URL encoded JSON string in the form of:{ "email": "...", "password": "..." }
The API will respond with a JSON string in the form of:
{
"token": "fe4a644605bf5e3da9c12a2696645669",
"expiresOn": 1595781786600
}
From this response, the token
is the user access key, which you will need to set as the authorization
header for all future API calls, and the expiresOn
value is the unix timestamp (in milliseconds) of the expiration moment of the user access key.
To get the user settings, you can make a request in the form of:
/actions?method=setting&for=getAll
The response will be a JSON string in the form of:
{
"embedToken": "8235bd682c1c5b33b682cb0512a2412a",
"subLangs": "all",
"subLimit": 3,
...
}
To get the list of available streams, there are 2 different endpoints:
- Torrent list:
/actions?method=getall
- Youtube-DL links, Ace Stream links, SopCast links, Local Media, etc:
/actions?method=getallextra
The response from these API requests will be a JSON string containing an object with items.
To embed in websites, you will first need an embed key, you can get the embed key from the [getting user settings(https://github.com/jaruba/PowderWeb/wiki/API#getting-user-settings) API response.
For further information on embedding in websites, refer to the documentation for the embedding feature.
If you require streams that are transcoded for Web Browsers, then it is highly recommended that you use the embedding feature. Embedding has many advantages as it will also identify the user's browser and transcode the video accordingly for that particular browser.
If, however, you require the transcoding engine to make the videos work in a particular scenario, and you know what you are doing, then you can make requests in the form of:
/web/08ada5a7a6183aae1e09d831df6748d566095a10/0/360p.mp4?token=fe4a644605bf5e3da9c12a2696645669&maxHeight=404&maxWidth=720&needsAudio=0&needsVideo=0&a=aac&v=h264&forAudio=-1©ts=-1&forceTranscode=-1&useMatroska=1&audioDelay=0&start=0
This request will return a transcoded video directly.
Breakdown of the URL request:
/web/${infoHash}/${fileIdx}/${videoQuality}.mp4?token=${userAccessToken}&maxHeight=${maximumVideoHeight}&maxWidth=${maximumVideoWith}&needsAudio=${requiresAudioTranscoded}&needsVideo=${requiresVideoTranscoded}&a=${audioCodec}&v=${videoCodec}&forAudio=${audioTrack}©ts=${copyTimestamp}&forceTranscode=${forceTranscoding}&useMatroska=${shouldUseMatroska}&audioDelay=${audioDelay}&start=${startTime}&isYtdl=${isYoutubeDlLink}&isLocal=${isLocalFile}
-
${infoHash}
: theinfoHash
received from the starting downloads or list available stream API requests -
${fileIdx}
: the file index of the video in the torrent (starts from0
), see getting torrent data for more information, (if the file is not a torrent, then always set this to0
) -
${videoQuality}
: the video quality to transcode to, can be360p
,480p
,720p
,1080p
, etc. -
${userAccessToken}
: the user access token that is normally set as theauthorization
header. -
${maximumVideoHeight}
: the maximum height (in pixels) that the transcoded video should have -
${maximumVideoWith}
: the maximum width (in pixels) that the transcoded video should have -
${requiresAudioTranscoded}
: if the audio stream should also be transcoded for the file, can be0
or1
-
${requiresVideoTranscoded}
: if the video stream should also be transcoded for the file, can be0
or1
-
${audioCodec}
: what audio codec to transcode to -
${videoCodec}
: what video codec to transcode to -
${audioTrack}
: what audio stream to include in the transcoded version (a video can have multiple audio tracks), starts from-1
(not set by user) -
${copyTimestamp}
: if the timestamp should be copied to the transcoded video -
${forceTranscoding}
: if it should transcode regardless of the other settings (such as${requiresAudioTranscoded}
or${requiresVideoTranscoded}
), starts from-1
(not set by user) -
${shouldUseMatroska}
: if the Matroska video codec should be used for transcoding -
${audioDelay}
: the audio delay, can be negative also, set in seconds -
${startAt}
: start the stream from a specific time, in seconds, set as float -
${isYoutubeDlLink}
: if the stream is from ayoutube-dl
link or not (can be0
or1
) -
${isLocalFile}
: if the stream is from a local media file (can be0
or1
)
The history is saved automatically for each item that is player with the web player. You can interact with the history through the API by getting the list of history items and by setting the history items.
You can get the entire list of history items with this request:
/actions?method=historyList
The response will be a JSON string containing an array in the form of:
[
{
"method": "updateHistory",
"filename": "Lounge Beats Deep Jazzy House - by DJ Dimsa",
"time": "2.207079",
"duration": "3693",
"infohash": "httpswwwyoutubecomwatchvEYSo692Cl68",
"fileID": "0",
"ended": false,
"isLocal": false,
"isYtdl": "1",
"utime": 1595238311646
},
...
]
You can update the item in the history by using this request:
/actions?method=updateHistory&filename=Sintel.mp4&time=9.481249&duration=888&infohash=08ada5a7a6183aae1e09d831df6748d566095a10&fileID=5&ended=false&isLocal=undefined&isYtdl=undefined
Breakdown of the request:
/actions?method=updateHistory&filename=${filename}&time=${time}&duration=${duration}&infohash=${infoHash}&fileID=${fileIdx}&ended=${hasEnded}&isLocal=${isLocal}&isYtdl=${isYtdl}
-
${filename}
: the filename of the video file, where a filename is not available, then a video title can be used as the value -
${time}
: the current playback time to save the history with, in seconds, set as float -
${duration}
: total duration of the video, in seconds -
${infoHash}
: the infohash of the torrent, where a torrent infohash is not available, apid
for the video can be used as the value -
${fileIdx}
: the file id of the torrent, starts from0
, see getting torrent data for more information (if the file is not from a torrent, then always set this to0
) -
${hasEnded}
: if the video has ended playback, boolean, can betrue
orfalse
-
${isLocal}
: if the video is a local file, set to1
if it is a local video, any other value is considered false -
${isYoutubeDl}
: if the video is a Youtube-DL link, set to1
if it is a Youtube-DL link, any other value is considered false
To start a new torrent download, use:
/actions?method=new&torrent=...
-
The
method
parameter must benew
for this call. -
The
torrent
parameter must be a URL encoded magnet link
The API will respond with a JSON string in the form of:
{
"opener": "...",
"utime": 1595177980886,
"infoHash": "08ada5a7a6183aae1e09d831df6748d566095a10",
"name": "Sintel [H264 - Eng - Multisubs] [Tntvillage]",
"totalSize": 0,
"path": false,
"peers": 0,
"uploadedStart": 0,
"uploadSpeed": 0,
"uploaded": 0,
"downloadSpeed": 0,
"downloaded": 0
}
It is important to take note of the utime
and infoHash
values from this response, as you will use them later on to identify your newly started torrent and in order to stream the content from it.
To stream newly added torrents, you must first find when they are ready to be streamed, in order to do so, use this API call:
/actions?method=isListening&utime=1595177980886
Where utime
is the value received from the starting downloads or list available streams API requests.
The typical response will be a JSON string in the form of:
{
"value": false
}
The value
parameter is a boolean, and can be false
or true
, once this parameter returns true
, the torrent is ready for streaming.
To download the playlist of a torrent, use this request:
/playlist.m3u?id=c4abdb6d30b1cdae74e1237868dc64d47dfcd714&token=fe4a644605bf5e3da9c12a2696645669
Where id
is the infoHash
received from the starting downloads or list available stream API requests and token
is the user access token that is normally set as the authorization
header.
This request will return a M3U
playlist containing the streamable videos from the requested torrent.
To get additional torrent data (of torrents that have been previously added) use:
/actions?method=torrentData&id=08ada5a7a6183aae1e09d831df6748d566095a10
Where id
is the infoHash
received from the starting downloads or list available stream API requests.
A typical response will be a JSON string in the form of:
{
"name": "Sintel",
"infoHash": "08ada5a7a6183aae1e09d831df6748d566095a10",
"files": [
{
"length": 129241752,
"id": "5",
"name": "Sintel.mp4",
"streamable": true,
"progress": 4,
"downloaded": "493.0 MB",
"selected": true
}
],
"swarm":{
"wires":{
"length": 7
},
"downloadSpeed": 1146852.6,
"uploadSpeed": 0,
"downloaded": 4194304,
"uploaded": 0,
"paused": false
},
"total":{
"length": 129302391
},
"isFinished": false,
"opener": "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel",
"uploadedStart": 0,
"path": false
}
The files
array in this response uses an absolute order, which means that for all other purposes where you will need a file index, the order of this array is used to get that file index, which will be the same as the array index for the element.
If you require streams that are transcoded for Web Browsers, then it is highly recommended that you use the embedding feature. Embedding has many advantages as it will also identify the user's browser and transcode the video accordingly for that particular browser. Embedding supports all stream types (torrents, youtube-dl, acestream, sopcast, etc.)
Example transcoding stream URL:
/web/08ada5a7a6183aae1e09d831df6748d566095a10/0/360p.mp4?token=fe4a644605bf5e3da9c12a2696645669&maxHeight=404&maxWidth=720&needsAudio=0&needsVideo=0&a=aac&v=h264&forAudio=-1©ts=-1&forceTranscode=-1&useMatroska=1&audioDelay=0&start=0
This request will return a transcoded video directly.
For docs regarding transcoding torrents, refer to transcoding streams.
Example request:
/actions?method=updateHistory&filename=Sintel.mp4&time=9.481249&duration=888&infohash=08ada5a7a6183aae1e09d831df6748d566095a10&fileID=5&ended=false&isLocal=undefined&isYtdl=undefined
For more information on setting history, read the Setting History docs.
Example request:
/actions?method=getSubs&infohash=08ada5a7a6183aae1e09d831df6748d566095a10&id=0
Breakdown of the request:
/actions?method=getSubs&infohash=${infoHash}&id=${fileIdx}
-
${infoHash}
: theinfoHash
received from the starting downloads or list available stream API requests -
${fileIdx}
: the file index of the video in the torrent (starts from0
), see getting torrent data for more information
A JSON string containing an array of subtitle objects in the form of:
[
{
"label": "Portuguese (BR)",
"sublang": "pb",
"src": "http://localhost:3000/srt2vtt/subtitle.vtt?token=a988b56c50bb6a55b944f293ac38c50c&from=aHR0cDovL2RsLm9wZW5zdWJ0aXRsZXMub3JnL2VuL2Rvd25sb2FkL3N1YmVuY29kaW5nLXV0ZjgvdnJmLTFhMDgwYzY2L2ZpbGUvMTk1Njc5Nzc2NC5zcnQ=",
"ext": "srt"
},
...
]
Where label
is the subtitle language, sublang
is the ISO 639-1 two letter code for the language, src
is the download link for the subtitle and ext
is the subtitle extension.
Example request:
/actions?method=cancel&noDelete=true&infohash=08ada5a7a6183aae1e09d831df6748d566095a10
Where infohash
is the torrent infohash which you can get from the torrent data or list available streams API requests.
To resume a torrent, the simplest way is by requesting it's playlist:
/getplaylist.m3u?id=08ada5a7a6183aae1e09d831df6748d566095a10
Where id
is the torrent infohash which you can get from the torrent data or list available streams API requests.
Example request:
/actions?method=cancel&force=true&infohash=08ada5a7a6183aae1e09d831df6748d566095a10
Where infohash
is the torrent infohash which you can get from the torrent data or list available streams API requests.
To start a new Youtube-DL Link download, use:
/actions?method=ytdlAdd&pid=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEYSo692Cl68
-
The
method
parameter must beytdlAdd
-
The
pid
parameter must be a URL encoded Youtube-DL supported link
The response will be a JSON string in the form of:
{
"pid": "httpswwwyoutubecomwatchvEYSo692Cl68",
"utime": 1595184197986,
"name": "Lounge Beats Deep Jazzy House - by DJ Dimsa",
"thumbnail": "https://i.ytimg.com/vi/EYSo692Cl68/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLA2WQg8Iu8WiQ4RoxXy1uuNpFPE1Q",
"originalURL": "https://www.youtube.com/watch?v=EYSo692Cl68",
"extracted": "...",
"isYtdl": true
}
Notice extracted
which includes the extracted stream from the Youtube-DL link.
To download the playlist of a Youtube-DL link, use this request:
/getytdlplaylist.m3u?pid=httpswwwyoutubecomwatchvEYSo692Cl68&token=d65b35e7de4da52315db9793052db49b
Where pid
is the pid
received from the starting downloads or list available stream API requests and token
is the user access token
that is normally set as the authorization
header.
This request will return a M3U
playlist containing the streamable videos from the requested torrent.
If you require streams that are transcoded for Web Browsers, then it is highly recommended that you use the embedding feature. Embedding has many advantages as it will also identify the user's browser and transcode the video accordingly for that particular browser. Embedding supports all stream types (torrents, youtube-dl, acestream, sopcast, etc.)
Example transcoding stream URL:
/web/httpswwwyoutubecomwatchvEYSo692Cl68/0/360p.mp4?token=d65b35e7de4da52315db9793052db49b&maxHeight=360&maxWidth=480&needsAudio=0&needsVideo=0&a=aac&v=h264&forAudio=null©ts=-1&forceTranscode=-1&useMatroska=1&audioDelay=0&isYtdl=1
This request will return a transcoded video directly.
Breakdown of the URL request:
/web/${infoHash}/${fileIdx}/${videoQuality}.mp4?token=${userAccessToken}&maxHeight=${maximumVideoHeight}&maxWidth=${maximumVideoWith}&needsAudio=${requiresAudioTranscoded}&needsVideo=${requiresVideoTranscoded}&a=${audioCodec}&v=${videoCodec}&forAudio=${audioTrack}©ts=${copyTimestamp}&forceTranscode=${forceTranscoding}&useMatroska=${shouldUseMatroska}&audioDelay=${audioDelay}&start=${startTime}&isYtdl=${isYoutubeDlLink}
For Youtube-DL streams, the ${infoHash}
is the pid
from the starting downloads or list available stream API request.
The ${fileIdx}
parameter should always be 0
for Youtube-DL streams.
The ${isYoutubeDlLink}
parameter should always be 1
for Youtube-DL streams.
For more information regarding transcoding Youtube-DL links, refer to transcoding streams.
Example request:
/actions?method=updateHistory&filename=Dua%20Lipa%2C%20Coldplay%2C%20Martin%20Garrix%20%26%20Kygo%2C%20The%20Chainsmokers%20Style%20-%20Feeling%20Me%20%2369&time=9.832819&duration=7152&infohash=httpswwwyoutubecomwatchvreslB6GXRHo&fileID=0&ended=false&isLocal=undefined&isYtdl=1
Compared to other saving history requests, ${isYoutubeDl}
will always be 1
, the ${filename}
will be the video title, and the ${infoHash}
will be the pid
from the starting downloads or list available stream API request.
For more information on setting history, read the Setting History docs.
Example request:
/actions?method=ytdlDestroy&pid=httpswwwyoutubecomwatchvreslB6GXRHo
Where pid
is the pid
from the starting downloads or list available stream API request.
To start a new AceStream Link download, use:
/actions?method=ace&torrent=c4abdb6d30b1cdae74e1237868dc64d47dfcd714
-
The
method
parameter must beace
for this call. -
The
torrent
parameter must be an AceStream infoHash (for example, if the AceStream link isacestream://c4abdb6d30b1cdae74e1237868dc64d47dfcd714
then the infoHash isc4abdb6d30b1cdae74e1237868dc64d47dfcd714
)
The response will be a JSON string in the form of:
{
"hasAcestream": true
}
If hasAcestream
is true
, then the download started, if it is false
, then AceStream was not configured on the Powder Web server.
To stream newly added AceStream links, you must first find when they are ready to be streamed, in order to do so, use this API call:
/actions?method=aceMsg&torrent=c4abdb6d30b1cdae74e1237868dc64d47dfcd714
Where torrent
is the value used for acestream links - starting downloads or from the response of the list available streams API request.
The typical response will be a JSON string in the form of:
{
"utime": 1595185273869,
"pid": "c4abdb6d30b1cdae74e1237868dc64d47dfcd714",
"status": "Prebuffering 0%",
"running": true,
"isLive": true,
"infohash": "a41915eababbf8d37ff5f96c0db70a289d1b206c",
"name": "My Channel",
"directLink": "http://127.0.0.1:3000/ace/c4abdb6d30b1cdae74e1237868dc64d47dfcd714/0?token=fe4a644605bf5e3da9c12a2696645669",
"transcodeLink": "http://127.0.0.1:3000/hls/c4abdb6d30b1cdae74e1237868dc64d47dfcd714/fe4a644605bf5e3da9c12a2696645669/out.m3u8"
}
Notice directLink
and transcodeLink
from this response, these may not be available at the start. When directLink
is available, then it is ready to stream (to video players with extended video codec support), when transcodeLink
is ready then that is ready to stream (to web browsers).
To download the playlist of a AceStream link, use this request:
/getaceplaylist.m3u?pid=c4abdb6d30b1cdae74e1237868dc64d47dfcd714&token=d65b35e7de4da52315db9793052db49b
Where pid
is the pid
received from the list available stream API request and token
is the user access token that is normally set as the authorization
header.
This request will return a M3U
playlist containing the streamable videos from the requested torrent.
The transcoding link (web ready HLS) is available in the API response from AceStream Links - Ready to Stream as transcodeLink
.
Example request:
/actions?method=aceDestroy&pid=c4abdb6d30b1cdae74e1237868dc64d47dfcd714
Where pid
is the pid
received from the list available stream API request.
To check if SopCast is enabled use:
/actions?method=haveSop
The response will be a JSON string in the form of:
{
"hasSopcast": true
}
If hasSopcast
is true
, then SopCast is enabled and you can stream it, if it is false
, then SopCast is not enabled in Powder Web.
A typical SopCast link is in the form of sop://185.122.61.8:3938/221961
.
To start a new SopCast Link download, use:
/actions?method=sop&torrent=sop%3A%2F%2F185.122.61.8%3A3938%2F221961
-
The
method
parameter must besop
for this call. -
The
torrent
parameter must be a URL encoded SopCast Link (for example:sop://185.122.61.8:3938/221961
)
The response will be a JSON string in the form of:
{
"hasSopcast": true
}
If Sopcast
is true
, then the download started, if it is false
, then SopCast was not configured on the Powder Web server.
To stream newly added AceStream links, you must first find when they are ready to be streamed, in order to do so, use this API call:
/actions?method=sopMsg&torrent=sop1851225983912256238
Where torrent
is the pid
value from the list available streams API request.
The typical response will be a JSON string in the form of:
{
"utime": 1595240430438,
"name": "SopCast Channel",
"pid": "sop1851225983912256238",
"status": "Starting Download",
"running": false,
"isLive": true,
"isSopcast": true,
"directLink": "http://127.0.0.1:63517/",
"sopUrl": "sop://185.122.61.8:3938/221961"
}
Notice directLink
and transcodeLink
from this response, these may not be available at the start. When directLink
is available, then it is ready to stream (to video players with extended video codec support), when transcodeLink
is ready then that is ready to stream (to web browsers).
A typical SopCast link is in the form of sop://185.122.61.8:3938/221961
.
To download the playlist for this example SopCast link, use:
/getsopplaylist.m3u?pid=sop%3A%2F%2F185.122.61.8%3A3938%2F221961&token=11de62fad136c60307bcb5dedaf33992
Where pid
is the URL encoded SopCast link (for this example: sop://185.122.61.8:3938/221961
) and token
is the user access token that is normally set as the authorization
header.
This request will return a M3U
playlist containing the streamable videos from the requested torrent.
Note: This request will also add this SopCast link to the downloads list.
The transcoding link (web ready HLS) is available in the API response from SopCast Links - Ready to Stream as transcodeLink
.
Example request:
/actions?method=sopDestroy&pid=sop1851225983912256238
Where pid
is the pid
from the list available streams API request.
Local media cannot be added through the API, if you have a legitimate use case for this, please create an issue for it. Until then, for security concerns, local media can only be added through the GUI.
Example request:
/getlocalplaylist.m3u?pid=1595244791277&token=a982b56b50bb6a55b944f293ac38c50c
Where pid
is the pid
from the list available streams API request and token
is the user access token that is normally set as the authorization
header.
This request will return a M3U
playlist containing the streamable videos from the requested torrent.
Example request:
/web/1595244791277/0/720p.mp4?token=a982b56b50bb6a55b944f293ac38c50c&maxHeight=720&maxWidth=1280&needsAudio=-1&needsVideo=0&a=aac&v=h264&forAudio=null©ts=-1&forceTranscoding=-1&useMatroska=1&audioDelay=0&isLocal=1
This request will return a transcoded video directly.
Breakdown of the URL request:
/web/${infoHash}/${fileIdx}/${videoQuality}.mp4?token=${userAccessToken}&maxHeight=${maximumVideoHeight}&maxWidth=${maximumVideoWith}&needsAudio=${requiresAudioTranscoded}&needsVideo=${requiresVideoTranscoded}&a=${audioCodec}&v=${videoCodec}&forAudio=${audioTrack}©ts=${copyTimestamp}&forceTranscode=${forceTranscoding}&useMatroska=${shouldUseMatroska}&audioDelay=${audioDelay}&start=${startTime}&isLocal=${isLocalFile}
For local media streams, the ${infoHash}
is the pid
from the response of the list available stream API request.
The ${fileIdx}
parameter should always be 0
for local media streams.
The ${isLocalFile}
parameter should always be 1
for local media streams.
For more information regarding transcoding local media links, refer to transcoding streams.
Example request:
/actions?method=updateHistory&filename=Sintel.mp4&time=4.152596&duration=888&infohash=1595244791277&fileID=0&ended=false&isLocal=1&isYtdl=undefined
Compared to other saving history requests, ${isLocal}
will always be 1
, the ${filename}
will be the video filename, and the ${infoHash}
will be the pid
from the response of the list available stream API request.
For more information on setting history, read the Setting History docs.
Example request:
/actions?method=getSubs&infohash=1595246625795&id=0
Breakdown of the request:
/actions?method=getSubs&infohash=${pid}&id=${fileIdx}
-
${pid}
: thepid
from the response of the list available stream API request -
${fileIdx}
: the file index of the video in the folder (starts from0
, will commonly be0
if the folder only contains one media file)
A JSON string containing an array of subtitle objects in the form of:
[
{
"label": "Portuguese (BR)",
"sublang": "pb",
"src": "http://localhost:3000/srt2vtt/subtitle.vtt?token=a988b56c50bb6a55b944f293ac38c50c&from=aHR0cDovL2RsLm9wZW5zdWJ0aXRsZXMub3JnL2VuL2Rvd25sb2FkL3N1YmVuY29kaW5nLXV0ZjgvdnJmLTFhMDgwYzY2L2ZpbGUvMTk1Njc5Nzc2NC5zcnQ=",
"ext": "srt"
},
...
]
Where label
is the subtitle language, sublang
is the ISO 639-1 two letter code for the language, src
is the download link for the subtitle and ext
is the subtitle extension.
Example request:
/actions?method=locDestroy&pid=1595244791277
Where pid
is the pid
from the list available streams API request.