Midwest Dev Chat

MidwestDevChat.com github.com/skidvis/Midwest-Dev-Chat

  • The newest 15 messages in the super-cool #linux channel.

  • 07/13 08:01:42 Tawnya: Good morning guys,

    So I decided to create a small tool to help keep the music on my phone in sync with a playlist on my computer, I figured it would be good Python3 practice as well.

    The first step was to make sure that the files matched from both sources. I figured i could `glob` the files from the Music directory on my phone, and export a playlist file from RhythmBox, which has the path to the files. Using `os.path.basename` and a regular expression on the file with some list matching, and I should be good to go, cool.

    Problem was, the exported playlist file exported some strange values for some file names with spaces:

    RhythmeBox's pls file:

    path/to/phone/music/Ed Sheeran - Shape Of You.mp3
    So I was getting 'differences' even though there weren't any, so I decided I would try using Clementine, I imported the `.pls` (with no problems) and exported a `.xspf` from Clementine. XML, great. Switching from regular expression to `minidom`, this file handled the spaces with no problems, but....
    Clementine's xspf file
    <location>file:///absolute/path/to/Music/EUNG FREESTYLE (%EC%9D%91%ED%94%84%EB%A6%AC%EC%8A%A4%ED%83%80%EC%9D%BC) - LIVE, SIK-K, PUNCHNELLO, OWEN OVADOZ, FLOWSIK.mp3</location>

    /path/to/phone/Music/EUNG FREESTYLE (응프리스타일) - LIVE, SIK-K, PUNCHNELLO, OWEN OVADOZ, FLOWSIK.mp3

    .... has trouble with foreign characters.

  • 07/13 08:10:13 Tawnya: I thought maybe the `os` module would know what to do with these path values, but `os.path.exists` returned `false` for the strange playlist values and `true` for the correct phone path values.

    So I'm not sure how to go about working with these values.
    I've tried:
    1. Adjusting the file export settings, but RhythmBox doesn't really have options for that, and neither does Clementine.
    2. Encoding the file to UTF-8, but there were no changes to the file name.
    3. Using `os.path.abspath` hoping the os knew what to do with them stuck_out_tongue

    But yeah, I'm not sure how to go about dealing with these values, any help is appreciated smile

  • 07/13 08:20:41 Barbera: @Tawnya Those paths with spaces replaced by %20, etc. are "url-encoded"

  • 07/13 08:20:54 Barbera: and you can use this to convert strings to/from that encoding https://docs.python.org/2/library/urllib.html#urllib.urlencode

  • 07/13 08:22:53 Barbera: well, that to encode, and `urllib.unquote()` to decode

  • 07/13 08:24:34 Barbera: So IIUC you could take the encoded string from the playlist, and say `urllib.unquote(playlist_filename).decode('utf8')` and that should get you a string that matches the name of the file that you get from `os.path.basename`

  • 07/13 08:25:13 Barbera: we might should take this to for any further discussion though :)

  • 07/13 08:27:50 Tawnya: Oh, I will try that and see how it goes, so sorry, I was so sure I was in the Python channel lol

  • 07/13 08:28:48 Tawnya: Thanks for the help, I'll let you know if it works in !

  • 07/19 11:26:57 Rea: has left the channel

  • 07/25 13:04:29 Wilfred: Shell script style guides

  • 07/25 13:04:43 Wilfred: Opinions?

  • *Usernames have been changed to protect the innocent.

Check out all the cool channels!

Join the conversation!