GStreamer # symbol in uri of local file

1.8k views Asked by At

When I try to play local file with "#" in filename on my Linux machine, it displays:

Error: message about my installation of GStreamer missing plugin /var/tmp/portage/media-libs/gst-plugins-base-0.10.36-r1/work/gst-plugins-base-0.10.36/gst/playback/gstplaybasebin.c(1686): gen_source_element (): /GstPlayBin:player:
No URI handler for file

I use this to set URI:

self.player.set_property('uri', 'file://' + filepath)

where filepath is absolute path to e.g. MP3 file "/home/me/untitled #1.mp3"

Is there some kind of escape or workaround?

1

There are 1 answers

1
rezca On

filepath should be URL quoted.

Use urllib.parse.quote() (Python 3) or urllib.quote() (Python 2)

This is what I use (Python 3) which should work on Windows too:

def file_to_uri(filename):
    filepath = os.path.abspath(filename) 
    drive, filepath = os.path.splitdrive(filepath)
    filepath = urllib.parse.quote(filepath.replace(os.sep, '/'))
    return 'file://%s%s' % (drive, filepath)