当前位置: 首页>>代码示例>>Python>>正文


Python path.path_to_uri函数代码示例

本文整理汇总了Python中mopidy.utils.path.path_to_uri函数的典型用法代码示例。如果您正苦于以下问题:Python path_to_uri函数的具体用法?Python path_to_uri怎么用?Python path_to_uri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了path_to_uri函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dir_and_path

 def test_dir_and_path(self):
     if sys.platform == 'win32':
         result = path.path_to_uri('C:/WINDOWS/', 'clock.avi')
         self.assertEqual(result, 'file:///C://WINDOWS/clock.avi')
     else:
         result = path.path_to_uri('/etc', 'fstab')
         self.assertEqual(result, 'file:///etc/fstab')
开发者ID:Halfnhav,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例2: test_utf8_in_path

 def test_utf8_in_path(self):
     if sys.platform == 'win32':
         result = path.path_to_uri('C:/æøå'.encode('utf-8'))
         self.assertEqual(result, 'file:///C://%C3%A6%C3%B8%C3%A5')
     else:
         result = path.path_to_uri('/tmp/æøå'.encode('utf-8'))
         self.assertEqual(result, 'file:///tmp/%C3%A6%C3%B8%C3%A5')
开发者ID:Halfnhav,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例3: test_space_in_path

 def test_space_in_path(self):
     if sys.platform == 'win32':
         result = path.path_to_uri('C:/test this')
         self.assertEqual(result, 'file:///C://test%20this')
     else:
         result = path.path_to_uri('/tmp/test this')
         self.assertEqual(result, 'file:///tmp/test%20this')
开发者ID:Halfnhav,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例4: test_unicode_in_path

 def test_unicode_in_path(self):
     if sys.platform == "win32":
         result = path_to_uri(u"C:/æøå")
         self.assertEqual(result, "file:///C://%C3%A6%C3%B8%C3%A5")
     else:
         result = path_to_uri(u"/tmp/æøå")
         self.assertEqual(result, u"file:///tmp/%C3%A6%C3%B8%C3%A5")
开发者ID:Amli,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例5: test_unicode_in_path

 def test_unicode_in_path(self):
     if sys.platform == 'win32':
         result = path.path_to_uri(u'C:/æøå')
         self.assertEqual(result, 'file:///C://%C3%A6%C3%B8%C3%A5')
     else:
         result = path.path_to_uri(u'/tmp/æøå')
         self.assertEqual(result, u'file:///tmp/%C3%A6%C3%B8%C3%A5')
开发者ID:Dvad,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例6: test_folder_and_path

 def test_folder_and_path(self):
     if sys.platform == "win32":
         result = path_to_uri(u"C:/WINDOWS/", u"clock.avi")
         self.assertEqual(result, "file:///C://WINDOWS/clock.avi")
     else:
         result = path_to_uri(u"/etc", u"fstab")
         self.assertEqual(result, u"file:///etc/fstab")
开发者ID:Amli,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例7: test_space_in_path

 def test_space_in_path(self):
     if sys.platform == "win32":
         result = path_to_uri(u"C:/test this")
         self.assertEqual(result, "file:///C://test%20this")
     else:
         result = path_to_uri(u"/tmp/test this")
         self.assertEqual(result, u"file:///tmp/test%20this")
开发者ID:Amli,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例8: test_latin1_in_path

 def test_latin1_in_path(self):
     if sys.platform == 'win32':
         result = path.path_to_uri('C:/æøå'.encode('latin-1'))
         self.assertEqual(result, 'file:///C://%E6%F8%E5')
     else:
         result = path.path_to_uri('/tmp/æøå'.encode('latin-1'))
         self.assertEqual(result, 'file:///tmp/%E6%F8%E5')
开发者ID:Halfnhav,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例9: test_simple_path

 def test_simple_path(self):
     if sys.platform == 'win32':
         result = path_to_uri(u'C:/WINDOWS/clock.avi')
         self.assertEqual(result, 'file:///C://WINDOWS/clock.avi')
     else:
         result = path_to_uri(u'/etc/fstab')
         self.assertEqual(result, 'file:///etc/fstab')
开发者ID:arambelo,项目名称:mopidy,代码行数:7,代码来源:path_test.py

示例10: _convert_mpd_data

def _convert_mpd_data(data, tracks, music_dir):
    if not data:
        return

    track_kwargs = {}
    album_kwargs = {}
    artist_kwargs = {}
    albumartist_kwargs = {}

    if "track" in data:
        album_kwargs["num_tracks"] = int(data["track"].split("/")[1])
        track_kwargs["track_no"] = int(data["track"].split("/")[0])

    if "artist" in data:
        artist_kwargs["name"] = data["artist"]
        albumartist_kwargs["name"] = data["artist"]

    if "albumartist" in data:
        albumartist_kwargs["name"] = data["albumartist"]

    if "album" in data:
        album_kwargs["name"] = data["album"]

    if "title" in data:
        track_kwargs["name"] = data["title"]

    if "musicbrainz_trackid" in data:
        track_kwargs["musicbrainz_id"] = data["musicbrainz_trackid"]

    if "musicbrainz_albumid" in data:
        album_kwargs["musicbrainz_id"] = data["musicbrainz_albumid"]

    if "musicbrainz_artistid" in data:
        artist_kwargs["musicbrainz_id"] = data["musicbrainz_artistid"]

    if "musicbrainz_albumartistid" in data:
        albumartist_kwargs["musicbrainz_id"] = data["musicbrainz_albumartistid"]

    if data["file"][0] == "/":
        path = data["file"][1:]
    else:
        path = data["file"]

    if artist_kwargs:
        artist = Artist(**artist_kwargs)
        track_kwargs["artists"] = [artist]

    if albumartist_kwargs:
        albumartist = Artist(**albumartist_kwargs)
        album_kwargs["artists"] = [albumartist]

    if album_kwargs:
        album = Album(**album_kwargs)
        track_kwargs["album"] = album

    track_kwargs["uri"] = path_to_uri(music_dir, path)
    track_kwargs["length"] = int(data.get("time", 0)) * 1000

    track = Track(**track_kwargs)
    tracks.add(track)
开发者ID:bok,项目名称:mopidy,代码行数:60,代码来源:translator.py

示例11: change_track

 def change_track(self, track):
     media_dir = self.backend.config['local']['media_dir']
     # TODO: check that type is correct.
     file_path = path.uri_to_path(track.uri).split(b':', 1)[1]
     file_path = os.path.join(media_dir, file_path)
     track = track.copy(uri=path.path_to_uri(file_path))
     return super(LocalPlaybackProvider, self).change_track(track)
开发者ID:eisnerd,项目名称:mopidy,代码行数:7,代码来源:playback.py

示例12: test_albumartist_tag_cache

 def test_albumartist_tag_cache(self):
     tracks = parse_mpd_tag_cache(path_to_data_dir("albumartist_tag_cache"), path_to_data_dir(""))
     uri = path_to_uri(path_to_data_dir("song1.mp3"))
     artist = Artist(name="albumartistname")
     album = expected_albums[0].copy(artists=[artist])
     track = Track(name="trackname", artists=expected_artists, track_no=1, album=album, length=4000, uri=uri)
     self.assertEqual(track, list(tracks)[0])
开发者ID:ruudud,项目名称:mopidy,代码行数:7,代码来源:translator_test.py

示例13: refresh

    def refresh(self):
        playlists = []

        for m3u in glob.glob(os.path.join(self._playlists_dir, '*.m3u')):
            uri = path.path_to_uri(m3u)
            name = os.path.splitext(os.path.basename(m3u))[0]

            tracks = []
            for track_uri in parse_m3u(m3u, self._media_dir):
                try:
                    # TODO We must use core.library.lookup() to support tracks
                    # from other backends
                    tracks += self.backend.library.lookup(track_uri)
                except LookupError as ex:
                    logger.warning('Playlist item could not be added: %s', ex)

            playlist = Playlist(uri=uri, name=name, tracks=tracks)
            playlists.append(playlist)

        self.playlists = playlists
        listener.BackendListener.send('playlists_loaded')

        logger.info(
            'Loaded %d local playlists from %s',
            len(playlists), self._playlists_dir)
开发者ID:Halfnhav,项目名称:mopidy,代码行数:25,代码来源:playlists.py

示例14: test_simple_cache

 def test_simple_cache(self):
     tracks = parse_mpd_tag_cache(path_to_data_dir('simple_tag_cache'),
         path_to_data_dir(''))
     uri = path_to_uri(path_to_data_dir('song1.mp3'))
     track = Track(name='trackname', artists=expected_artists, track_no=1,
         album=expected_albums[0], length=4000, uri=uri)
     self.assertEqual(set([track]), tracks)
开发者ID:Amli,项目名称:mopidy,代码行数:7,代码来源:translator_test.py

示例15: parse_m3u

def parse_m3u(file_path, media_dir):
    r"""
    Convert M3U file list of uris

    Example M3U data::

        # This is a comment
        Alternative\Band - Song.mp3
        Classical\Other Band - New Song.mp3
        Stuff.mp3
        D:\More Music\Foo.mp3
        http://www.example.com:8000/Listen.pls
        http://www.example.com/~user/Mine.mp3

    - Relative paths of songs should be with respect to location of M3U.
    - Paths are normaly platform specific.
    - Lines starting with # should be ignored.
    - m3u files are latin-1.
    - This function does not bother with Extended M3U directives.
    """
    # TODO: uris as bytes
    uris = []
    try:
        with open(file_path) as m3u:
            contents = m3u.readlines()
    except IOError as error:
        logger.warning('Couldn\'t open m3u: %s', locale_decode(error))
        return uris

    for line in contents:
        line = line.strip().decode('latin1')

        if line.startswith('#'):
            continue

        if urlparse.urlsplit(line).scheme:
            uris.append(line)
        elif os.path.normpath(line) == os.path.abspath(line):
            path = path_to_uri(line)
            uris.append(path)
        else:
            path = path_to_uri(os.path.join(media_dir, line))
            uris.append(path)

    return uris
开发者ID:eisnerd,项目名称:mopidy,代码行数:45,代码来源:translator.py


注:本文中的mopidy.utils.path.path_to_uri函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。