Skip to content

Commit

Permalink
feat: make new properties "start" and "end" available
Browse files Browse the repository at this point in the history
Closes #331
  • Loading branch information
open-dynaMIX committed Nov 21, 2021
1 parent d504944 commit da8dc79
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ information about the error.
},
],
"duration": 6.024, # <-- seconds
"end": null, # <-- seconds as string or null
"filename": "01 - dummy.mp3",
"fullscreen": false,
"loop-file": false, # <-- false, true or integer
Expand Down Expand Up @@ -381,6 +382,7 @@ information about the error.
"position": -0.0, # <-- seconds
"remaining": 6.024, # <-- seconds
"speed": 1, # <-- multiplier
"start": null, , # <-- seconds as string or null
"sub-delay": 0, # <-- milliseconds
"track-list": [ # <-- all available video, audio and sub tracks
{
Expand Down
8 changes: 7 additions & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ local function build_status_response()
["chapter-list"] = mp.get_property_native("chapter-list") or '',
chapters = mp.get_property_native("chapters") or '',
duration = mp.get_property_native("duration") or '',
["end"] = mp.get_property_native("end") or '',
filename = mp.get_property('filename') or '',
fullscreen = mp.get_property_native("fullscreen"),
["loop-file"] = mp.get_property_native("loop-file"),
Expand All @@ -128,6 +129,7 @@ local function build_status_response()
position = mp.get_property_native("time-pos") or '',
remaining = mp.get_property_native("playtime-remaining") or '',
speed = mp.get_property_native('speed') or '',
start = mp.get_property_native('start') or '',
["sub-delay"] = mp.get_property_osd("sub-delay") or '',
["track-list"] = mp.get_property_native("track-list") or '',
volume = mp.get_property_native("volume") or '',
Expand Down Expand Up @@ -163,7 +165,11 @@ local function build_status_response()
return false
end

return utils.format_json(values)
local result = utils.format_json(values)
-- hack to have null values in the resulting json
result = result:gsub('"none"', "null")

return result
end

local function get_content_type(file_type)
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/snap_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"chapter-list": [],
"chapters": 0,
"duration": 6.024,
"end": None,
"filename": "01 - dummy.mp3",
"fullscreen": False,
"loop-file": False,
Expand Down Expand Up @@ -226,6 +227,7 @@
"position": -0.0,
"remaining": 6.024,
"speed": 1,
"start": None,
"sub-delay": 0,
"track-list": [
{
Expand Down
8 changes: 8 additions & 0 deletions webui-page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ <h3 id="album">Album</h3>
<td>Chapter:</td>
<td id="chapterContent"></td>
</tr>
<tr class="start">
<td>Start:</td>
<td id="startContent"></td>
</tr>
<tr class="end">
<td>End:</td>
<td id="endContent"></td>
</tr>
</table>
</div>

Expand Down
21 changes: 21 additions & 0 deletions webui-page/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,26 @@ function setChapter(chapters, chapter, chapterList) {
}
}

function setOrHideStartEnd(elementsClass, contentId, value) {
const elements = document.getElementsByClassName(elementsClass);
const content = document.getElementById(contentId);
if (value == null) {
[].slice.call(elements).forEach(function (div) {
div.classList.add('hidden');
});
} else {
[].slice.call(elements).forEach(function (div) {
div.classList.remove('hidden');
});
content.innerText = format_time(value);
}
}

function setStartEnd(start, end) {
setOrHideStartEnd("start", "startContent", start)
setOrHideStartEnd("end", "endContent", end)
}

function playlist_loop_cycle() {
const loopButton = document.getElementsByClassName('playlistLoopButton');
if (loopButton.value === "no") {
Expand Down Expand Up @@ -636,6 +656,7 @@ function handleStatusResponse(json) {
setLoop(json["loop-file"], json["loop-playlist"]);
setFullscreenButton(json['fullscreen']);
setChapter(json['chapters'], json['chapter'], json['chapter-list']);
setStartEnd(json['start'], json['end']);
populatePlaylist(json['playlist'], json['pause']);
setupNotification(json);
}
Expand Down

0 comments on commit da8dc79

Please sign in to comment.