ideasman42 / mpvctl

Command line MPV remote control.
4 stars 2 forks source link

[improvement] Start a file in current playlist #2

Open Bellavene opened 3 months ago

Bellavene commented 3 months ago

mpvctl play "/path/to/file" or play last added Is this possible?

ideasman42 commented 3 months ago

I don't think this is possible at the moment

So what you're after is something like:

Where the files are appended instead of replacing the playlist, and --change-track jumps to the first of the newly added FILE(s).

Is this what you're after?

Bellavene commented 3 months ago

Yes, exactly

ideasman42 commented 3 months ago

@Bellavene committed a --change option, thanks for the suggestion.

Bellavene commented 3 months ago

Thank You

Bellavene commented 3 months ago

--change outputs an error now. mpvctl add doesn't give an error, but doesn't add to playlist anymore.

Traceback (most recent call last):
  File "/Users/Bellavene/CLI/mpvctl", line 621, in <module>
    main()
  File "/Users/Bellavene/CLI/mpvctl", line 617, in main
    args.func(args)
  File "/Users/Bellavene/CLI/mpvctl", line 513, in <lambda>
    subparse.set_defaults(func=lambda args: cmd_add(args.files, args.replace, args.change))
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 202, in cmd_add
    result_list = socket_command_list_as_json_data(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 136, in socket_command_list_as_json_data
    return [json.loads(result) for result in result_list]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 136, in <listcomp>
    return [json.loads(result) for result in result_list]
            ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
ideasman42 commented 3 months ago

@Bellavene do you have any files in the playlist? I tried to re-create an error both with an empty playlist and with items in the playlist but both work for me.

Not sure why this would fail, I'm just interested to know if there are items in your playlist. It's possible a "None" result means it can be assumed to be empty.

What version of mpv to you have? using v0.38.0.

Bellavene commented 3 months ago

macos 14 mpv v0.37.0

Was lazy to try to compile it myself. 0.37.0 is the latest precompiled version available for macos. Brew also installs 0.37.0 Yes, I had items in the playlist.

For me, this error looks like something is wrong with the python script itself. As It starts with subparse.set_defaults(func=lambda args: cmd_add(args.files, args.replace, args.change))

ideasman42 commented 3 months ago

Could you please replace socket_command_list_as_json_data with this function & report the results?

def socket_command_list_as_json_data(json_str_list: Sequence[str]) -> Sequence[Dict[str, Any]]:
    result_list = socket_command_list(json_str_list)
    print(repr(result_list))
    return [json.loads(result) for result in result_list]

This simply adds a print(repr(result_list))

Bellavene commented 3 months ago

Nothing changed, nothing printed. On "--change" error is mostly the same, on "add" just silence.

ideasman42 commented 3 months ago

@Bellavene please include the error as it will include the text that causes the failure.

Bellavene commented 3 months ago
['']
Traceback (most recent call last):
  File "/Users/Bellavene/CLI/mpvctl", line 635, in <module>
    main()
  File "/Users/Bellavene/CLI/mpvctl", line 631, in main
    args.func(args)
  File "/Users/Bellavene/CLI/mpvctl", line 527, in <lambda>
    subparse.set_defaults(func=lambda args: cmd_add(args.files, args.replace, args.change))
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 204, in cmd_add
    result_list = socket_command_list_as_json_data(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 138, in socket_command_list_as_json_data
    return [json.loads(result) for result in result_list]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 138, in <listcomp>
    return [json.loads(result) for result in result_list]
            ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
ideasman42 commented 3 months ago

Could you check if reading any other values works? for example:

mpvctl stash

... while playing.

Then:

mpvctl stash pop

If these work to restore the state that was playing, accessing many other values will be working, so it's very strange that accessing playlist-count fails.

Bellavene commented 3 months ago

mpv stash answers with this:

Traceback (most recent call last):
  File "/Users/Bellavene/CLI/mpvctl", line 634, in <module>
    main()
  File "/Users/Bellavene/CLI/mpvctl", line 630, in main
    args.func(args)
  File "/Users/Bellavene/CLI/mpvctl", line 531, in <lambda>
    subparse.set_defaults(func=lambda args: cmd_stash_push())
                                            ^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 345, in cmd_stash_push
    result_list = socket_command_list_as_json_data(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 137, in socket_command_list_as_json_data
    return [json.loads(result) for result in result_list]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Bellavene/CLI/mpvctl", line 137, in <listcomp>
    return [json.loads(result) for result in result_list]
            ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

All of this works with previous code

ideasman42 commented 3 months ago

@Bellavene could you please bisect the revision that broke stash ? - I'm fairly sure this logic didn't change but it's possible a more recent change broke behavior on macOS.