本文整理汇总了Python中senf.fsn2uri函数的典型用法代码示例。如果您正苦于以下问题:Python fsn2uri函数的具体用法?Python fsn2uri怎么用?Python fsn2uri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fsn2uri函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_example_xml
def get_example_xml(song_path, rating, lastplayed):
song_uri = fsn2uri(song_path)
mount_uri = fsn2uri(find_mount_point(song_path))
return (u"""\
<?xml version="1.0" standalone="yes"?>
<rhythmdb version="1.9">
<entry type="song">
<title>Music</title>
<genre>Unknown</genre>
<track-number>7</track-number>
<duration>199</duration>
<file-size>4799124</file-size>
<location>%s</location>
<mountpoint>%s</mountpoint>
<mtime>1378717158</mtime>
<first-seen>1339576187</first-seen>
<last-seen>1409855394</last-seen>
<last-played>%d</last-played>
<play-count>1</play-count>
<bitrate>191</bitrate>
<rating>%d</rating>
<date>731881</date>
<media-type>audio/mpeg</media-type>
<composer>Unknown</composer>
</entry>
</rhythmdb>\
""" % (song_uri, mount_uri, lastplayed, rating)).encode("utf-8")
开发者ID:LudoBike,项目名称:quodlibet,代码行数:29,代码来源:test_rbimport.py
示例2: test_fsn2uri
def test_fsn2uri(self):
if os.name != "nt":
uri = fsn2uri(fsnative(u"/öäü.txt"))
self.assertEqual(uri, u"file:///%C3%B6%C3%A4%C3%BC.txt")
else:
uri = fsn2uri(fsnative(u"C:\\öäü.txt"))
self.assertEqual(
uri, "file:///C:/%C3%B6%C3%A4%C3%BC.txt")
self.assertEqual(
fsn2uri(u"C:\\SomeDir\xe4"), "file:///C:/SomeDir%C3%A4")
开发者ID:faubiguy,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py
示例3: test_thumb
def test_thumb(s):
thumb = thumbnails.get_thumbnail(s.filename, (50, 60))
#check for right scaling
s.failUnless(thumb)
s.failUnlessEqual((thumb.get_width(), thumb.get_height()), (50, 25))
#test the thumbnail filename
uri = fsn2uri(s.filename)
name = hash.md5(uri.encode("ascii")).hexdigest() + ".png"
path = thumbnails.get_thumbnail_folder()
path = os.path.join(path, "normal", name)
s.failUnless(os.path.isfile(path))
#check for metadata
thumb_pb = GdkPixbuf.Pixbuf.new_from_file(path)
meta_mtime = thumb_pb.get_option("tEXt::Thumb::MTime")
meta_uri = thumb_pb.get_option("tEXt::Thumb::URI")
s.failUnlessEqual(int(meta_mtime), int(mtime(s.filename)))
s.failUnlessEqual(meta_uri, uri)
#check rights
if os.name != "nt":
s.failUnlessEqual(os.stat(path).st_mode, 33152)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:27,代码来源:test_util_thumbnails.py
示例4: get_cache_info
def get_cache_info(path, boundary):
"""For an image at `path` return (cache_path, thumb_size)
cache_path points to a potential cache file
thumb size is either 128 or 256
"""
assert isinstance(path, fsnative)
width, height = boundary
if width <= ThumbSize.NORMAL and height <= ThumbSize.NORMAL:
size_name = "normal"
thumb_size = ThumbSize.NORMAL
else:
size_name = "large"
thumb_size = ThumbSize.LARGE
thumb_folder = get_thumbnail_folder()
cache_dir = os.path.join(thumb_folder, size_name)
uri = fsn2uri(path)
thumb_name = hashlib.md5(uri).hexdigest() + ".png"
thumb_path = os.path.join(cache_dir, thumb_name)
return (thumb_path, thumb_size)
开发者ID:urielz,项目名称:quodlibet,代码行数:26,代码来源:thumbnails.py
示例5: _show_files_thunar
def _show_files_thunar(dirname, entries):
# https://git.xfce.org/xfce/thunar/tree/thunar/thunar-dbus-service-infos.xml
XFCE_PATH = "/org/xfce/FileManager"
XFCE_NAME = "org.xfce.FileManager"
XFCE_IFACE = "org.xfce.FileManager"
try:
dbus_proxy = _get_dbus_proxy(XFCE_NAME, XFCE_PATH, XFCE_IFACE)
if not entries:
dbus_proxy.DisplayFolder('(sss)',
fsn2uri(dirname), "", _get_startup_id())
else:
dbus_proxy.DisplayFolderAndSelect(
'(ssss)', fsn2uri(dirname), entries[0], "", _get_startup_id())
except GLib.Error as e:
raise BrowseError(e)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:17,代码来源:showfiles.py
示例6: _get_image_uri
def _get_image_uri(self, song):
"""A unicode file URI or an empty string"""
fileobj = app.cover_manager.get_cover(song)
self._set_image_fileobj(fileobj)
if fileobj:
return fsn2uri(fileobj.name)
return u""
开发者ID:Muges,项目名称:quodlibet,代码行数:8,代码来源:notify.py
示例7: _show_files_fdo
def _show_files_fdo(dirname, entries):
# https://www.freedesktop.org/wiki/Specifications/file-manager-interface/
FDO_PATH = "/org/freedesktop/FileManager1"
FDO_NAME = "org.freedesktop.FileManager1"
FDO_IFACE = "org.freedesktop.FileManager1"
try:
dbus_proxy = _get_dbus_proxy(FDO_NAME, FDO_PATH, FDO_IFACE)
if not entries:
dbus_proxy.ShowFolders('(ass)',
[fsn2uri(dirname)], _get_startup_id())
else:
item_uri = fsn2uri(os.path.join(dirname, entries[0]))
dbus_proxy.ShowItems('(ass)', [item_uri], _get_startup_id())
except GLib.Error as e:
raise BrowseError(e)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:17,代码来源:showfiles.py
示例8: test_roundtrip
def test_roundtrip(self):
if os.name == "nt":
paths = [u"C:\\öäü.txt"]
else:
paths = [u"/öäü.txt", u"//foo/bar", u"///foo/bar"]
for source in paths:
path = uri2fsn(fsn2uri(fsnative(source)))
self.assertTrue(is_fsnative(path))
self.assertEqual(path, fsnative(source))
开发者ID:faubiguy,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py
示例9: label_path
def label_path(path):
l = Gtk.Label(label="<a href='%s'>%s</a>" % (
fsn2uri(path), escape(fsn2text(unexpand(path)))),
use_markup=True,
ellipsize=Pango.EllipsizeMode.MIDDLE,
xalign=0,
selectable=True)
l.connect("activate-link", show_uri)
return l
开发者ID:LudoBike,项目名称:quodlibet,代码行数:10,代码来源:appinfo.py
示例10: _show_files_fdo
def _show_files_fdo(dirname, entries):
# http://www.freedesktop.org/wiki/Specifications/file-manager-interface
FDO_PATH = "/org/freedesktop/FileManager1"
FDO_NAME = "org.freedesktop.FileManager1"
FDO_IFACE = "org.freedesktop.FileManager1"
if not dbus:
raise BrowseError("no dbus")
try:
bus = dbus.SessionBus()
bus_object = bus.get_object(FDO_NAME, FDO_PATH)
bus_iface = dbus.Interface(bus_object, dbus_interface=FDO_IFACE)
if not entries:
bus_iface.ShowFolders([fsn2uri(dirname)], _get_startup_id())
else:
item_uri = fsn2uri(os.path.join(dirname, entries[0]))
bus_iface.ShowItems([item_uri], _get_startup_id())
except dbus.DBusException as e:
raise BrowseError(e)
开发者ID:Muges,项目名称:quodlibet,代码行数:21,代码来源:showfiles.py
示例11: test_parse_onesong_uri
def test_parse_onesong_uri(self):
target = get_data_path("silence-44-s.ogg")
target = fsn2uri(target).encode("ascii")
target = self.prefix + target
with temp_filename() as name:
with open(name, "wb") as f:
f.write(target)
with open(name, "rb") as f:
pl = self.Parse(f, name)
self.failUnlessEqual(len(pl), 1)
self.failUnlessEqual(pl[0]("title"), "Silence")
pl.delete()
开发者ID:LudoBike,项目名称:quodlibet,代码行数:12,代码来源:test_browsers_playlists.py
示例12: _show_files_thunar
def _show_files_thunar(dirname, entries):
# http://git.xfce.org/xfce/thunar/tree/thunar/thunar-dbus-service-infos.xml
XFCE_PATH = "/org/xfce/FileManager"
XFCE_NAME = "org.xfce.FileManager"
XFCE_IFACE = "org.xfce.FileManager"
if not dbus:
raise BrowseError("no dbus")
try:
bus = dbus.SessionBus()
bus_object = bus.get_object(XFCE_NAME, XFCE_PATH)
bus_iface = dbus.Interface(bus_object, dbus_interface=XFCE_IFACE)
if not entries:
bus_iface.DisplayFolder(fsn2uri(dirname), "", _get_startup_id())
else:
item_name = os.path.join(dirname, entries[0])
bus_iface.DisplayFolderAndSelect(
fsn2uri(dirname), item_name, "", _get_startup_id())
except dbus.DBusException as e:
raise BrowseError(e)
开发者ID:Muges,项目名称:quodlibet,代码行数:22,代码来源:showfiles.py
示例13: test_parse_onesong_uri
def test_parse_onesong_uri(self):
h, name = mkstemp()
os.close(h)
target = get_data_path("silence-44-s.ogg")
target = fsn2uri(target)
target = self.prefix + target
with open(name, "w") as f:
f.write(target)
list = self.Parse(name)
os.unlink(name)
self.failUnlessEqual(len(list), 1)
self.failUnlessEqual(list[0]("title"), "Silence")
list.delete()
开发者ID:urielz,项目名称:quodlibet,代码行数:13,代码来源:test_browsers_playlists.py
示例14: get_property
def get_property(self, interface, name):
if interface == MediaObject.IFACE:
if name == "Parent":
return EntryObject.PATH
elif name == "Type":
return "image"
elif name == "Path":
return Icon.PATH
elif name == "DisplayName":
return "I'm an icon \o/"
elif interface == MediaItem.IFACE:
if name == "URLs":
return [fsn2uri(self.__f.name)]
elif name == "MIMEType":
return "image/png"
elif name == "Width" or name == "Height":
return Icon.SIZE
elif name == "ColorDepth":
return self.__depth
开发者ID:urielz,项目名称:quodlibet,代码行数:19,代码来源:mediaserver.py
示例15: browse_folders_thunar
def browse_folders_thunar(songs, display=""):
# http://git.xfce.org/xfce/thunar/tree/thunar/thunar-dbus-service-infos.xml
XFCE_PATH = "/org/xfce/FileManager"
XFCE_NAME = "org.xfce.FileManager"
XFCE_IFACE = "org.xfce.FileManager"
if not dbus:
raise BrowseError("no dbus")
try:
bus = dbus.SessionBus()
bus_object = bus.get_object(XFCE_NAME, XFCE_PATH)
bus_iface = dbus.Interface(bus_object, dbus_interface=XFCE_IFACE)
# open each folder and select the first file we have selected
for dirname, sub_songs in group_songs(songs).items():
bus_iface.DisplayFolderAndSelect(
fsn2uri(dirname),
sub_songs[0]("~basename"),
display,
get_startup_id())
except dbus.DBusException as e:
raise BrowseError(e)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:23,代码来源:browsefolders.py
示例16: __drag_data_get
def __drag_data_get(self, view, ctx, sel, tid, etime):
model, rows = view.get_selection().get_selected_rows()
dirs = [model[row][0] for row in rows]
for songs in self.__find_songs(view.get_selection()):
pass
if tid == self.TARGET_QL:
cant_add = filter(lambda s: not s.can_add, songs)
if cant_add:
qltk.ErrorMessage(
qltk.get_top_parent(self), _("Unable to copy songs"),
_("The files selected cannot be copied to other "
"song lists or the queue.")).run()
ctx.drag_abort(etime)
return
to_add = filter(self.__library.__contains__, songs)
self.__add_songs(view, to_add)
qltk.selection_set_songs(sel, songs)
else:
# External target (app) is delivered a list of URIS of songs
uris = list({fsn2uri(dir) for dir in dirs})
print_d("Directories to drop: %s" % dirs)
sel.set_uris(uris)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:23,代码来源:filesystem.py
示例17: __get_metadata_real
def __get_metadata_real(self):
"""
https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata/
"""
metadata = {}
metadata["mpris:trackid"] = self.__get_current_track_id()
def ignore_overflow(dbus_type, value):
try:
return dbus_type(value)
except OverflowError:
return 0
song = app.player.info
if not song:
return metadata
metadata["mpris:length"] = ignore_overflow(
dbus.Int64, song("~#length") * 10 ** 6)
if self.__cover is not None:
self.__cover.close()
self.__cover = None
cover = app.cover_manager.get_cover(song)
if cover:
is_temp = cover.name.startswith(tempfile.gettempdir())
if is_temp:
self.__cover = cover
metadata["mpris:artUrl"] = fsn2uri(cover.name)
# All list values
list_val = {"artist": "artist", "albumArtist": "albumartist",
"comment": "comment", "composer": "composer", "genre": "genre",
"lyricist": "lyricist"}
for xesam, tag in iteritems(list_val):
vals = song.list(tag)
if vals:
metadata["xesam:" + xesam] = listmap(unival, vals)
# All single values
sing_val = {"album": "album", "title": "title", "asText": "~lyrics"}
for xesam, tag in iteritems(sing_val):
vals = song.comma(tag)
if vals:
metadata["xesam:" + xesam] = unival(vals)
# URI
metadata["xesam:url"] = song("~uri")
# Integers
num_val = {"audioBPM": "bpm", "discNumber": "disc",
"trackNumber": "track", "useCount": "playcount"}
for xesam, tag in iteritems(num_val):
val = song("~#" + tag, None)
if val is not None:
metadata["xesam:" + xesam] = ignore_overflow(dbus.Int32, val)
# Rating
metadata["xesam:userRating"] = ignore_overflow(
dbus.Double, song("~#rating"))
# Dates
ISO_8601_format = "%Y-%m-%dT%H:%M:%S"
tuple_time = time.gmtime(song("~#lastplayed"))
iso_time = time.strftime(ISO_8601_format, tuple_time)
metadata["xesam:lastUsed"] = iso_time
year = song("~year")
if year:
try:
tuple_time = time.strptime(year, "%Y")
iso_time = time.strftime(ISO_8601_format, tuple_time)
except ValueError:
pass
else:
metadata["xesam:contentCreated"] = iso_time
return metadata
开发者ID:LudoBike,项目名称:quodlibet,代码行数:81,代码来源:mpris2.py
示例18: test_win_unc_path
def test_win_unc_path(self):
if os.name == "nt":
self.assertEqual(
fsn2uri(u"\\\\server\\share\\path"),
u"file://server/share/path")
开发者ID:faubiguy,项目名称:quodlibet,代码行数:5,代码来源:test_util_path.py
示例19: __call__
def __call__(self, key, default=u"", connector=" - ", joiner=', '):
"""Return the value(s) for a key, synthesizing if necessary.
Multiple values for a key are delimited by newlines.
A default value may be given (like `dict.get`);
the default default is an empty unicode string
(even if the tag is numeric).
If a tied tag ('a~b') is requested, the `connector` keyword
argument may be used to specify what it is tied with.
In case the tied tag contains numeric and file path tags, the result
will still be a unicode string.
The `joiner` keyword specifies how multiple *values* will be joined
within that tied tag output, e.g.
~people~title = "Kanye West, Jay Z - New Day"
For details on tied tags, see the documentation for `util.tagsplit`.
"""
if key[:1] == "~":
key = key[1:]
if "~" in key:
real_key = "~" + key
values = []
sub_tags = util.tagsplit(real_key)
# If it's genuinely a tied tag (not ~~people etc), we want
# to delimit the multi-values separately from the tying
j = joiner if len(sub_tags) > 1 else "\n"
for t in sub_tags:
vs = [decode_value(real_key, v) for v in (self.list(t))]
v = j.join(vs)
if v:
values.append(v)
return connector.join(values) or default
elif key == "#track":
try:
return int(self["tracknumber"].split("/")[0])
except (ValueError, TypeError, KeyError):
return default
elif key == "#disc":
try:
return int(self["discnumber"].split("/")[0])
except (ValueError, TypeError, KeyError):
return default
elif key == "length":
length = self.get("~#length")
if length is None:
return default
else:
return util.format_time_display(length)
elif key == "#rating":
return dict.get(self, "~" + key, config.RATINGS.default)
elif key == "rating":
return util.format_rating(self("~#rating"))
elif key == "people":
return "\n".join(self.list_unique(PEOPLE)) or default
elif key == "people:real":
# Issue 1034: Allow removal of V.A. if others exist.
unique = self.list_unique(PEOPLE)
# Order is important, for (unlikely case): multiple removals
for val in VARIOUS_ARTISTS_VALUES:
if len(unique) > 1 and val in unique:
unique.remove(val)
return "\n".join(unique) or default
elif key == "people:roles":
return (self._role_call("performer", PEOPLE)
or default)
elif key == "peoplesort":
return ("\n".join(self.list_unique(PEOPLE_SORT)) or
self("~people", default, connector))
elif key == "peoplesort:roles":
# Ignores non-sort tags if there are any sort tags (e.g. just
# returns "B" for {artist=A, performersort=B}).
# TODO: figure out the "correct" behavior for mixed sort tags
return (self._role_call("performersort", PEOPLE_SORT)
or self("~peoplesort", default, connector))
elif key in ("performers", "performer"):
return self._prefixvalue("performer") or default
elif key in ("performerssort", "performersort"):
return (self._prefixvalue("performersort") or
self("~" + key[-4:], default, connector))
elif key in ("performers:roles", "performer:roles"):
return (self._role_call("performer") or default)
elif key in ("performerssort:roles", "performersort:roles"):
return (self._role_call("performersort")
or self("~" + key.replace("sort", ""), default,
connector))
elif key == "basename":
return os.path.basename(self["~filename"]) or self["~filename"]
elif key == "dirname":
return os.path.dirname(self["~filename"]) or self["~filename"]
elif key == "uri":
try:
return self["~uri"]
except KeyError:
return fsn2uri(self["~filename"])
elif key == "format":
return self.get("~format", text_type(self.format))
elif key == "codec":
codec = self.get("~codec")
#.........这里部分代码省略.........
开发者ID:elfalem,项目名称:quodlibet,代码行数:101,代码来源:_audio.py
示例20: get_thumbnail
def get_thumbnail(path, boundary):
"""Get a thumbnail pixbuf of an image at `path`.
Will create/use a thumbnail in the user's thumbnail directory if possible.
Follows the Free Desktop specification:
http://specifications.freedesktop.org/thumbnail-spec/
Can raise GLib.GError. Thread-safe.
"""
assert isinstance(path, fsnative)
width, height = boundary
new_from_file_at_size = GdkPixbuf.Pixbuf.new_from_file_at_size
# larger than thumbnails, load directly
if width > ThumbSize.LARGEST or height > ThumbSize.LARGEST:
return new_from_file_at_size(path, width, height)
path_mtime = mtime(path)
if path_mtime == 0:
return new_from_file_at_size(path, width, height)
# embedded thumbnails come from /tmp/
# FIXME: move this to another layer
if path.startswith(tempfile.gettempdir()):
return new_from_file_at_size(path, width, height)
thumb_path, thumb_size = get_cache_info(path, boundary)
cache_dir = os.path.dirname(thumb_path)
try:
mkdir(cache_dir, 0o700)
except OSError:
return new_from_file_at_size(path, width, height)
try:
pb = new_from_file_at_size(thumb_path, width, height)
except GLib.GError:
# in case it fails to load, we recreate it
pass
else:
meta_mtime = pb.get_option("tEXt::Thumb::MTime")
if meta_mtime is not None:
try:
meta_mtime = int(meta_mtime)
except ValueError:
pass
else:
if meta_mtime == int(path_mtime):
return pb
info, pw, ph = GdkPixbuf.Pixbuf.get_file_info(path)
# Too small picture, no thumbnail needed
if pw < thumb_size and ph < thumb_size:
return new_from_file_at_size(path, width, height)
thumb_pb = new_from_file_at_size(path, thumb_size, thumb_size)
uri = fsn2uri(path)
mime = info.get_mime_types()[0]
options = {
"tEXt::Thumb::Image::Width": str(pw),
"tEXt::Thumb::Image::Height": str(ph),
"tEXt::Thumb::URI": uri,
"tEXt::Thumb::MTime": str(int(path_mtime)),
"tEXt::Thumb::Size": str(os.path.getsize(path)),
"tEXt::Thumb::Mimetype": mime,
"tEXt::Software": "QuodLibet"
}
thumb_pb.savev(thumb_path, "png", options.keys(), options.values())
try:
os.chmod(thumb_path, 0o600)
except OSError:
pass
return scale(thumb_pb, boundary)
开发者ID:urielz,项目名称:quodlibet,代码行数:79,代码来源:thumbnails.py
注:本文中的senf.fsn2uri函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论