open-dynaMIX/simple-mpv-webui

Feature Request: open a file to play through the WebUI

francwalter opened this issue · 11 comments

Hallo
still thanks for the great work, really use and appreciate it :)

I have a Feature Request: could it be possible to open a file from the computer, where mpv is running, so that mpv will play it, using your WebUI?
I can start mpv remotely in the foreground with ssh (same user than the console user) on a Windows 10 Computer with:
schtasks /create /TN RunMPV /RU DeinUser /tr mpv.exe /sc EINMAL /ST 00:00
and then start mpv in the foreground with:
schtasks /run /tn RunMPV

The WebUI is indeed active, I can do commands (fullscreen e.g.) to mpv, but I cannot load a movie or file.

It would be great if I would get grip of the Desktop or the user's folder in a Dialog or List to open something.

Thanks!
frank

Hey @francwalter

Yes, this is possible, but not available from the frontend yet. There are the loadfile- and the collections-endpoints and they are listed in the list of endpoints here.
Here some work has been started to make this available from the frontend.

Could you give me an example for the collections api?
I tried a GET Request with:

http://192.168.0.161:8080/api/collections/C:/Users/f/Desktop/Filme

But this seems unknown. Backslash, also double, the same.
I put that path in the main.lua in the collections variable and i can get it with:

http://192.168.0.161:8080/api/collections/

But how can i use my path to play a movie?
In the help it's not clear enough for me.
Thanks.

No need to edit the main.lua just add it to the mpv config or pass it as CLI arg as described in the docs.

Everything that needs configuration can be configured from outside the main.lua. This way you can easily just pull new changes, without the need of resolving any conflicts.

The path needs to be URL-encoded in the URI. You can use an online URL encoder for this. So the URL would look like this: http://192.168.0.161:8080/api/collections/C%3A%2FUsers%2Ff%2FDesktop%2FFilme.

The path needs to be URL-encoded in the URI. You can use an online URL encoder for this. So the URL would look like this: http://192.168.0.161:8080/api/collections/C%3A%2FUsers%2Ff%2FDesktop%2FFilme.

But I get with that URL:

Error: Requested URL /api/collections/C%3A%2FUsers%2Ff%2FDesktop%2FFilme not found

and just with http://192.168.0.161:8080/api/collections/ I get the successful response:

[{"path":"c:\\Users\\f\\Desktop\\Filme","is-directory":true}]

as I have still (for the moment) that path hardcoded in collections in main.lua - what am I doing wrong?

But this works:

http://192.168.0.161:8080/api/loadfile/c%3A%2FUsers%2Ff%2FDesktop%2FFilme%2Fdonald.mkv/replace

So I must have some misunderstand about the collections, I guess.
What I thought is, that I could retrieve a list of files and folders in the path I send.
With:

http://192.168.0.161:8080/api/collections/here-comes-my-url-encoded-path

I thought that the response should be the content of that path.
Possible?

http://192.168.0.161:8080/api/collections/C:/Users/f/Desktop/Filme

My error was the slash instead of backslash!
So with %5C instead of %2F
In line 688 of main.lua (and in every other line where that always same "Error: Requested URL..." is thrown) I changed the code as debug measurement (I dont know other in lua) to:

      if not is_path_in_collection(fs_path) or not is_dir(fs_path) then
        return response(404, "plain", "fcw: Z688: Error: Requested URL /"..request.raw_path.." not found. fs_path: "..fs_path, {})
      end

So I could see, what the exact value of fs_path was, that there was wrongly slashes (%2F) instead of backslashes (%5C):

fcw: Z688: Error: Requested URL /api/collections/C%3A%2FUsers%2Ff%2FDesktop%2FFilme not found. fs_path: C:/Users/f/Desktop/Filme

The very same path must be in collections and as parameter as a directory (if ... is_dir(fs_path)).
It must be in exact same spelling, case-sensitive, despite Windows unawareness of cases. It took me a while to find the error when I had C:... in the collections (hardcoded) but put c:... in my parameter of the GET Request.
The code could be a bit optimized here ;)
Also the output (json) is a bit strange: all paths are with double backslash, e.g.:

0 |  
path | "c:\\Temp\\BE"
is-directory | true
1 |  
path | "c:\\Temp\\ePub"
is-directory | true
2 |  
path | "c:\\Temp\\Bericht"
is-directory | true
3 |  
path | "c:\\Temp\\WordPress Themes"
is-directory | true

But it is working in the end :)

What is still unclear: how can I set the option "collections" not just hardcoded?
I will scrutinize it further...

No need to edit the main.lua just add it to the mpv config or pass it as CLI arg as described in the docs.

I tried to put that collections into the mpv.conf:

webui-collections="C:\\Users\\f\\Desktop\\Filme"

but now I get an error on mpv start:

Error parsing option webui-collections (option not found)
C:\Users\f\AppData\Roaming/mpv/mpv.conf:147: setting option webui-collections='C:\\Users\\f\\Desktop\\Filme' failed.

Everything that needs configuration can be configured from outside the main.lua. This way you can easily just pull new changes, without the need of resolving any conflicts.

So where can I put that collections?
BTW: I can live with hardcoding it ;)

Hey @francwalter
Sorry for not getting back to you sooner!

The whole handling of paths is the only part that has special handling for windows. Windows support is really on a best effort basis, as I don't have a windows system. Sometimes I mess with it in a virtual machine, but it doesn't spark joy at all, so I mostly avoid it.

How to proceed: Please open a new issue, exactly describing the problem with path handling in windows as well as the requirements to get it fixed. I'm willing to implement any changes needed to meet those requirements. Or - even better - maybe some other person steps up that likes to work in windows and opens a PR.

Thank a lot!
In v3.0.0 you already fixed that issue with case-sensitive paths, that helped a lot!
The rest could be programming on my side (e.g. in Tasker).
For opening files in the browser indeed it would need programming in main.lua and the static web folder.

For the issue with the hardcoded path (in collections var.) I should then open a new issue, because this variable would be overwritten in any update, if coming ;)
If there is no update, then it could be indeed hard coded easily.

Thank!

I would like to see this as well.

However, I'm pretty happy with a simple workaround I use at the moment.

On my Windows install, I just have a batch file in my g:\videos directory that loops through all recursive directories and generates a playlist.txt file. So, for example g:\videos\Ascendance of a Bookworm will have a playlist of all episodes in order, as long as I keep videos organized. Then just start mpv from that directory with --playlist=playlist.txt

The batch to generate playlists.

@echo off
set videoFormats=*.mkv *.mp4

call :treeProcess
goto :eof

:treeProcess
dir /O:N /B %videoFormats% > playlist.txt
echo Parsing %CD%
for /D %%d in (*) do (
    cd %%d
    call :treeProcess
    cd ..
)
exit /b

Then just copy a simple mpv wrapper script to every directory in videos with a for /D %%d in (*) loop

Far from elegant, but works well enough for me to skip through vids of a show I'm watching.

Implemented in #427