Skip to content

Commit

Permalink
feat(api): add playlist_move endpoint
Browse files Browse the repository at this point in the history
For completeness, this commit adds a new post endpoint
`/api/playlist_move/:source/:target`.
  • Loading branch information
open-dynaMIX committed Dec 31, 2019
1 parent 2e47afa commit 43197eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,31 @@ In order to have the notification work properly you need to at least once trigge
## Endpoints
You can also directly talk to the endpoints:

| URI | Method | Parameter | Description |
| ---------------------------- | ------ | ---------------------------------- | ----------------------------------------------------------------------- |
| /api/status | GET | | Returns JSON data about playing media --> see below |
| /api/play | POST | | Play media |
| /api/pause | POST | | Pause media |
| /api/toggle_pause | POST | | Toggle play/pause |
| /api/fullscreen | POST | | Toggle fullscreen |
| /api/seek/:seconds | POST | `int` or `float` (can be negative) | Seek |
| /api/set_position/:seconds | POST | | Go to position :seconds |
| /api/playlist_prev | POST | | Go to previous media in playlist |
| /api/playlist_next | POST | | Go to next media in playlist |
| /api/playlist_jump/:index | POST | `int` | Jump to playlist item at position `:index` |
| /api/playlist_move_up/:index | POST | `int` | Move playlist item at position `:index` one position up |
| /api/playlist_remove/:index | POST | `int` | Remove playlist item at position `:index` |
| /api/add_chapter/:amount | POST | `int` (can be negative) | Jump `:amount` chapters in current media |
| /api/add_volume/:percent | POST | `int` or `float` (can be negative) | Add :percent% volume |
| /api/set_volume/:percent | POST | `int` or `float` | Set volume to :percent% |
| /api/add_sub_delay/:ms | POST | `int` or `float` (can be negative) | Add :ms milliseconds subtitles delay |
| /api/set_sub_delay/:ms | POST | `int` or `float` (can be negative) | Set subtitles delay to :ms milliseconds |
| /api/add_audio_delay/:ms | POST | `int` or `float` (can be negative) | Add :ms miliseconds audio delay |
| /api/set_audio_delay/:ms | POST | `int` or `float` (can be negative) | Set audio delay to :ms milliseconds |
| /api/cycle_sub | POST | | Cycle trough available subtitles |
| /api/cycle_audio | POST | | Cycle trough available audio tracks |
| /api/cycle_audio_device | POST | | Cycle trough audio devices. [More information.](#audio-devices-string) |
| URI | Method | Parameter | Description |
| ---------------------------------- | ------ | ---------------------------------- | ----------------------------------------------------------------------- |
| /api/status | GET | | Returns JSON data about playing media --> see below |
| /api/play | POST | | Play media |
| /api/pause | POST | | Pause media |
| /api/toggle_pause | POST | | Toggle play/pause |
| /api/fullscreen | POST | | Toggle fullscreen |
| /api/seek/:seconds | POST | `int` or `float` (can be negative) | Seek |
| /api/set_position/:seconds | POST | | Go to position :seconds |
| /api/playlist_prev | POST | | Go to previous media in playlist |
| /api/playlist_next | POST | | Go to next media in playlist |
| /api/playlist_jump/:index | POST | `int` | Jump to playlist item at position `:index` |
| /api/playlist_move/:source/:target | POST | `int` and `int` | Move playlist item from position `:source` to position `:target` |
| /api/playlist_move_up/:index | POST | `int` | Move playlist item at position `:index` one position up |
| /api/playlist_remove/:index | POST | `int` | Remove playlist item at position `:index` |
| /api/add_chapter/:amount | POST | `int` (can be negative) | Jump `:amount` chapters in current media |
| /api/add_volume/:percent | POST | `int` or `float` (can be negative) | Add :percent% volume |
| /api/set_volume/:percent | POST | `int` or `float` | Set volume to :percent% |
| /api/add_sub_delay/:ms | POST | `int` or `float` (can be negative) | Add :ms milliseconds subtitles delay |
| /api/set_sub_delay/:ms | POST | `int` or `float` (can be negative) | Set subtitles delay to :ms milliseconds |
| /api/add_audio_delay/:ms | POST | `int` or `float` (can be negative) | Add :ms miliseconds audio delay |
| /api/set_audio_delay/:ms | POST | `int` or `float` (can be negative) | Set audio delay to :ms milliseconds |
| /api/cycle_sub | POST | | Cycle trough available subtitles |
| /api/cycle_audio | POST | | Cycle trough available audio tracks |
| /api/cycle_audio_device | POST | | Cycle trough audio devices. [More information.](#audio-devices-string) |

All POST endpoints return a JSON message. If successful: `{"message": "success"}`, otherwise, the message will contain
information about the error.
Expand Down
16 changes: 14 additions & 2 deletions webui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ local commands = {
return pcall(mp.commandv('playlist-remove', p))
end,

playlist_move = function(s, t)
args = {s, t}
for count = 1, 2 do
local valid, msg = validate_number_param(s)
if not valid then
return true, false, msg
end
end
return pcall(mp.commandv('playlist-move', s, t))
end,

playlist_move_up = function(p)
local valid, msg = validate_number_param(p)
if not valid then
Expand Down Expand Up @@ -330,11 +341,12 @@ local function handle_post(path)
return 404, get_content_type('plain'), "Error: Requested URL /"..path.." not found"
end
local command = components()
local param = components() or ""
local param1 = components() or ""
local param2 = components() or ""

local f = commands[command]
if f ~= nil then
local _, err, ret = f(param)
local _, err, ret = f(param1, param2)
if err then
return 200, get_content_type('json'), '{"message": "success"}'
else
Expand Down

0 comments on commit 43197eb

Please sign in to comment.