Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper slash seperator for windows file paths #6565

Closed
AlexanderEvans opened this issue Mar 18, 2019 · 14 comments
Closed

Use proper slash seperator for windows file paths #6565

AlexanderEvans opened this issue Mar 18, 2019 · 14 comments

Comments

@AlexanderEvans
Copy link

AlexanderEvans commented Mar 18, 2019

mpv version and platform

Windows 10

Reproduction steps

Add
ctrl+e run explorer /select, ${path}
to input.conf in windows 10

Expected behavior

On Windows use '\' only as the separator when printing paths so that it can be passed to file explorer to open the explorer with the file selected properly.

Actual behavior

mpv outputs the path using '/'s instead for sub-directories which apparently confuses windows' file explorer.

Alternate reproduction method

This behaviour can be very clearly observed why playing a folder of files in windows with a command such as:
mpv.exe "<path to music folder>/Music videos folder" --shuffle
and adding
ctrl+e show-text ${path}
to input.conf

Then just press ctrl+e and observe the mixed \ and /

This was discussed more in this thread if it is unclear: #6560

@avih
Copy link
Member

avih commented Mar 18, 2019

mpv outputs the path using '/'s instead for sub-directories which apparently confuses windows' file explorer.

No, it outputs exactly the value you used when running mpv .

If you want paths to contain only \, call mpv with paths with only \, or write a script to normalize the path either on load or when you invoke explorer.

edit: mpv does seem to use / to append items when creating a playlist from a directory. Not sure it should normalize the path because it works for mpv needs, but some external programs (explorer) could be more picky. But a script can still trivially do it for you.

@AlexanderEvans
Copy link
Author

AlexanderEvans commented Mar 18, 2019

mpv outputs the path using '/'s instead for sub-directories which apparently confuses windows' file explorer.

No, it outputs exactly the value you used when running mpv .

If you want paths to contain only \, call mpv with paths with only \, or write a script to normalize the path either on load or when you invoke explorer.

edit: mpv does seem to use / to append items when creating a playlist from a directory. Not sure it should normalize the path because it works for mpv needs, but some external programs (explorer) could be more picky. But a script can still trivially do it for you.

Can you point me to some documentation to how I can hook into mpv with a script to do that? I really don't understand much of anything about how input.conf works or what it is, and explorer doesn't seem to like the way mpv spits out the path by default...

@avih
Copy link
Member

avih commented Mar 18, 2019

The manual has sections about scripting in lua/js.

This should work also for directory playlist items: save this text as show-in-explorer.js at your scripts/ folder:

mp.register_script_message("show-in-explorer", function(path) {
    mp.commandv("run", "explorer", "/select,", (path || ".").replace(/\//g, "\\"));
});

Then in your input.conf add:

ctrl+e script-message show-in-explorer ${path}

@AlexanderEvans
Copy link
Author

The manual has sections about scripting in lua/js.

This should work also for directory playlist items: save this text as show-in-explorer.js at your scripts/ folder:

mp.register_script_message("show-in-explorer", function(path) {
    mp.commandv("run", "explorer", "/select,", (path || ".").replace(/\//g, "\\"));
});

Then in your input.conf add:

ctrl+e script-message show-in-explorer ${path}

Ty, this works exactly as I needed. I had no idea that mpv could be extended like this. I will keep this in mind going forward. Still might want to consider changing how mpv appends slashes to paths in windows, but this is good enough for me. Ty again. 😄

@zc62
Copy link
Contributor

zc62 commented Mar 19, 2019

See #6570

zc62 added a commit to zc62/mpv that referenced this issue Mar 19, 2019
This is done by converting `/` to `\` when the joined path is a windows
absolute file path, otherwise `/` is kept.

Fixes mpv-player#6565.
@Akemi
Copy link
Member

Akemi commented Sep 20, 2019

since the PR was closed this idea is off the table.

@CogentRedTester
Copy link
Contributor

CogentRedTester commented Jul 8, 2022

You can also do this entirely from within input.conf using powershell:

ctrl+e run powershell.exe -command ``explorer.exe '/select,' ( "${path}" -replace '/', '\' )``

Note that this example is using the custom quote syntax with the backtick ` character.

Edit: updated to use two backticks instead of `!

@stax76
Copy link
Contributor

stax76 commented Jul 8, 2022

I use forward slashes only for my personal usage, in my public user scripts and mpv.net I don't generate forward and double slashes to ensure the highest possible compatibility with other user scripts. In mpv.net, I normalize paths in some locations to ensure compatibility with some user scripts that generate forward slashes, such as mpv-file-browser @CogentRedTester, and also mpv generating a playlist from a directory. There are other opinions, that's how I do it.

@stax76
Copy link
Contributor

stax76 commented Jul 8, 2022

@CogentRedTester

Powershell is a bit slow, in most use cases fast enough, to be exact the startup is 200 ms when it was started before, for pwsh it's 400 ms. I try your solution and use it if it works.

@CogentRedTester
Copy link
Contributor

@CogentRedTester

Powershell is a bit slow, in most use cases fast enough, to be exact the startup is 200 ms when it was started before, for pwsh it's 400 ms. I try your solution and use it if it works.

Oh yea it's very slow compared to cmd or bash, but if you're just trying to open explorer.exe then I doubt even a 1 second delay matters much.

@stax76
Copy link
Contributor

stax76 commented Jul 8, 2022

I confirm that it works perfectly, and the delay is no problem for this use case.

@stax76
Copy link
Contributor

stax76 commented Jul 8, 2022

@CogentRedTester

I'm not understanding the exclamation marks in the command line, what do I have to google to find the documentation for it?

@CogentRedTester
Copy link
Contributor

CogentRedTester commented Jul 8, 2022

@CogentRedTester

I'm not understanding the exclamation marks in the command line, what do I have to google to find the documentation for it?

flat-command-syntax, the 5th paragraph on custom quotes. I should probably change the example to use two backticks instead of `! though, I didn't know that two backticks were valid.

@stax76
Copy link
Contributor

stax76 commented Jul 8, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants