-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
playlist: Add option to force forward slashes in paths #3331
Comments
Sounds like a reasonable feature! Perhaps there is a built-in |
Just to clarify, Windows MPD expects forward slashes "/" so I think the feature would be the opposite of the text you've written (addendum in bold is my addition):
Do you have any advice on how to get started on this? I am eager to contribute a pull request if I can :) update1: Line 172 in 8b4d030
and beets/beetsplug/smartplaylist.py Line 198 in 5ad1698
are the place where the conversion happens (the code is super readable!!!!) update2: >>> from pathlib import Path
>>> p = Path("Various Artists\Beatport 2017\9492281_Itsa_Trumpet_Thing_Extended_Mix.mp3")
>>> str(p.as_posix())
'Various Artists/Beatport 2017/9492281_Itsa_Trumpet_Thing_Extended_Mix.mp3'
>>> |
Cool! Looks like you're on your way there. One nit is that pathlib is only available on Python 3.4+. Could be worth seeing if the implementation of that method is simple enough that we could just call some underlying function… Anyway, throwing this behind a config option seems good! |
>>> from pathlib import Path
>>> p = Path("Various Artists\Beatport 2017\9492281_Itsa_Trumpet_Thing_Extended_Mix.mp3")
>>> p.as_posix
<bound method PurePath.as_posix of WindowsPath('Various Artists/Beatport 2017/9492281_Itsa_Trumpet_Thing_Extended_Mix.mp3')>
>>> import inspect
>>> inspect.getsourcelines(p.as_posix)
([' def as_posix(self):\n', ' """Return the string representation of the path with forward (/)\n', ' slashes."""\n', ' f = self._flavour\n', " return str(self).replace(f.sep, '/')\n"], 703) so this means that the method is defined like: def as_posix(self):
"""Return the string representation of the path with forward (/)
slashes."""
f = self._flavour
return str(self).replace(f.sep, '/') I imagine here since beets already uses only |
Oh wow, that's quite a bit simpler than what I was imagining! One concern, however: I imagine that the absolute paths that beets stores on Windows start with a drive letter, like |
Surprisingly yes, I was waiting for something with lots of edge cases !!! >>> from pathlib import Path
>>> p = Path("C:\Program Files\internet explorer\iexplore.exe")
>>> p.as_posix()
'C:/Program Files/internet explorer/iexplore.exe' MPD uses relative path, relative to the root of the library (and not the playlist files). MusicPlayerDaemon/MPD#200 |
Nah, no need for that—we already have a Let's just add an option called |
https://github.com/MartyLake/beets/tree/martylake_add_forward_slash_option I think I am quite close to the goal, but encoding always beats me at this game =/ do you have any advice on how to get any further ? why do we use "bytes" instead of string in the playlist code ? It prints |
All paths in beets are bytes, not strings, because Unix paths are bytes—they don't necessarily use any particular text encoding, and certainly not consistently anything Unicode. See also: http://beets.io/blog/paths.html In your code, I think it should be fine to just use bytestring replacement, i.e., >>> b'foo'.replace(b'o', b'x')
b'fxx' |
Oh my, I remember having read thig article a long time ago... I am so glad that you figured things out before e !!! |
For the record, MaxKellermann also fixed it for MPD 2 hours ago. MusicPlayerDaemon/MPD@90ea3bf |
Use case
Following up on #irc and MusicPlayerDaemon/MPD#607
I'm trying to use beets to export playlists for MPD. Unfortunately, I am using Windows, and beets uses backslashes on windows, and MPD can only recognize forwards.
Example of playlist that works fixed by bash+sed:
Example of playlist that does not work, generated by beets.io:
Solution
add a new option called
separator_char
that, if set, forces this character to be used as a separator.or
add a new option called
type_of_separator
that defaults toauto
(current behavior), but can also beforce_backslash
orforce_forward
Alternatives
Have a post script hook where I can call my own bash+sed solution
The text was updated successfully, but these errors were encountered: