Filenames with special chars failed to load under Windows XP - string encoding problem

Issue #3 resolved
Former user created an issue

I could fix it by modifying a function:
{{{

!python

# some custom methods
def _run_cmd(self, cmd, *args):
    if not self.process_alive:
        raise NoMplayerRunning('You have first to start the mplayer,' 
                                'use Start()')
    args = ' '.join(i for i in args if not i is None)
    args.replace('\\', '\\\\') # escape escaped backslashes :D
    _debug('%r, %r' % (cmd, args), 'running command')

    args = args.encode(sys.getfilesystemencoding())
    if self.keep_pause:
        self._stdin.write('pausing_keep %s %s\n' % (cmd, args))
    else:
        self._stdin.write('%s %s\n' % (cmd, args))

}}}

Comments (9)

  1. David repo owner
    • changed status to new

    Sorry I cant reproduce this problem, do you have an example when this error occurs?

  2. Former user Account Deleted

    Loading a file with the name "3sat Kalter Frühling 20101118_201027 #1.ts" for example won't work in your version. It throws an error:

    ...
       File "v:\_pyffmpeg\src\MplayerCtrl.py", line 1155, in Loadfile
        self._run_cmd('loadfile', file_url, append)
      File "v:\_pyffmpeg\src\MplayerCtrl.py", line 952, in _run_cmd
        self._stdin.write('pausing_keep %s %s\n' % (cmd, args))
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 40: ordinal not in range(128)
    

    The fix I posted prevents this.

  3. David repo owner
    • changed status to open

    I can't reproduce this error, which Python version do you have? Can you show me your code?

  4. wobbler

    My Python version is 2.6.4 .

    I used a "wx.FileDropTarget" to get the name of a file, but it also doesn't work when I specify the filename directly in the script escaping the special character in the name. Your MplayerCtrl.py version can only handle ASCII file names.

    If there is a 'ä','ü' or 'ö' for example, your current version throws something like

      File "v:\_pyffmpeg\src\MplayerCtrl.py", line 1169, in Loadfile
        self._run_cmd('loadfile', file_url, append)
      File "v:\_pyffmpeg\src\MplayerCtrl.py", line 944, in _run_cmd
        args if not i is None)
      File "v:\_pyffmpeg\src\MplayerCtrl.py", line 944, in <genexpr>
        args if not i is None)
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 20:
     ordinal not in range(128)
    

    Your code line 943,944:

            args = ' '.join(str(i.replace(' ', '\\ ')) for i in
                            args if not i is None)
    

    "str" converts it to ASCII. Remove the "str()". "i.replace()" returns already a string.

  5. David repo owner

    Ok. I'll try to fix this, the problem is, this error never occours to me (and I've atm no computer)

  6. Former user Account Deleted

    Hello. I removed the str () and put as a comment line:

    # args = args.encode (sys.getfilesystemencoding ())
    

    Doing this allows the use of non-ASCII characters such as ä, í, etc... I use Debian Linux testing and Python 2.6. Will not know if in windows.

  7. Log in to comment