diff --git a/README.md b/README.md index 44b52d8..dbd2878 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 { diff --git a/main.lua b/main.lua index 825ecbb..1d5ab8d 100644 --- a/main.lua +++ b/main.lua @@ -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"), @@ -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 '', @@ -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) diff --git a/tests/snapshots/snap_tests.py b/tests/snapshots/snap_tests.py index a5671b2..d09cf63 100644 --- a/tests/snapshots/snap_tests.py +++ b/tests/snapshots/snap_tests.py @@ -199,6 +199,7 @@ "chapter-list": [], "chapters": 0, "duration": 6.024, + "end": None, "filename": "01 - dummy.mp3", "fullscreen": False, "loop-file": False, @@ -226,6 +227,7 @@ "position": -0.0, "remaining": 6.024, "speed": 1, + "start": None, "sub-delay": 0, "track-list": [ { diff --git a/webui-page/index.html b/webui-page/index.html index 0efdf3b..acb0f24 100644 --- a/webui-page/index.html +++ b/webui-page/index.html @@ -115,6 +115,14 @@

Album

Chapter: + + Start: + + + + End: + + diff --git a/webui-page/webui.js b/webui-page/webui.js index 90fb30e..bf2b4a8 100644 --- a/webui-page/webui.js +++ b/webui-page/webui.js @@ -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") { @@ -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); }