• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python translator.track_to_mpd_format函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: listallinfo

def listallinfo(context, uri=None):
    """
    *musicpd.org, music database section:*

        ``listallinfo [URI]``

        Same as ``listall``, except it also returns metadata info in the
        same format as ``lsinfo``.

        Do not use this command. Do not manage a client-side copy of MPD's
        database. That is fragile and adds huge overhead. It will break with
        large databases. Instead, query MPD whenever you need something.


    .. warning:: This command is disabled by default in Mopidy installs.
    """
    result = []
    for path, lookup_future in context.browse(uri):
        if not lookup_future:
            result.append(('directory', path))
        else:
            for tracks in lookup_future.get().values():
                for track in tracks:
                    result.extend(translator.track_to_mpd_format(track))
    return result
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:25,代码来源:music_db.py


示例2: plchanges

def plchanges(context, version):
    """
    *musicpd.org, current playlist section:*

        ``plchanges {VERSION}``

        Displays changed songs currently in the playlist since ``VERSION``.

        To detect songs that were deleted at the end of the playlist, use
        ``playlistlength`` returned by status command.

    *MPDroid:*

    - Calls ``plchanges "-1"`` two times per second to get the entire playlist.
    """
    # XXX Naive implementation that returns all tracks as changed
    tracklist_version = context.core.tracklist.get_version().get()
    if version < tracklist_version:
        return translator.tracks_to_mpd_format(
            context.core.tracklist.get_tl_tracks().get())
    elif version == tracklist_version:
        # A version match could indicate this is just a metadata update, so
        # check for a stream ref and let the client know about the change.
        stream_title = context.core.playback.get_stream_title().get()
        if stream_title is None:
            return None

        tl_track = context.core.playback.get_current_tl_track().get()
        position = context.core.tracklist.index(tl_track).get()
        return translator.track_to_mpd_format(
            tl_track, position=position, stream_title=stream_title)
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:31,代码来源:current_playlist.py


示例3: lsinfo

def lsinfo(context, uri=None):
    """
    *musicpd.org, music database section:*

        ``lsinfo [URI]``

        Lists the contents of the directory ``URI``.

        When listing the root directory, this currently returns the list of
        stored playlists. This behavior is deprecated; use
        ``listplaylists`` instead.

    MPD returns the same result, including both playlists and the files and
    directories located at the root level, for both ``lsinfo``, ``lsinfo
    ""``, and ``lsinfo "/"``.
    """
    result = []
    for path, lookup_future in context.browse(uri, recursive=False):
        if not lookup_future:
            result.append(('directory', path.lstrip('/')))
        else:
            tracks = lookup_future.get()
            if tracks:
                result.extend(translator.track_to_mpd_format(tracks[0]))

    if uri in (None, '', '/'):
        result.extend(protocol.stored_playlists.listplaylists(context))

    if not result:
        raise exceptions.MpdNoExistError('Not found')
    return result
开发者ID:Baileym1,项目名称:mopidy,代码行数:31,代码来源:music_db.py


示例4: playlistinfo

def playlistinfo(context, songpos=None, start=None, end=None):
    """
    *musicpd.org, current playlist section:*

        ``playlistinfo [[SONGPOS] | [START:END]]``

        Displays a list of all songs in the playlist, or if the optional
        argument is given, displays information only for the song
        ``SONGPOS`` or the range of songs ``START:END``.

    *ncmpc and mpc:*

    - uses negative indexes, like ``playlistinfo "-1"``, to request
      the entire playlist
    """
    if songpos == '-1':
        songpos = None
    if songpos is not None:
        songpos = int(songpos)
        tl_track = context.core.tracklist.tl_tracks.get()[songpos]
        return translator.track_to_mpd_format(tl_track, position=songpos)
    else:
        if start is None:
            start = 0
        start = int(start)
        if not (0 <= start <= context.core.tracklist.length.get()):
            raise MpdArgError('Bad song index')
        if end is not None:
            end = int(end)
            if end > context.core.tracklist.length.get():
                end = None
        tl_tracks = context.core.tracklist.tl_tracks.get()
        return translator.tracks_to_mpd_format(tl_tracks, start, end)
开发者ID:MacGyverQue,项目名称:mopidy,代码行数:33,代码来源:current_playlist.py


示例5: test_track_to_mpd_format_for_empty_track

 def test_track_to_mpd_format_for_empty_track(self):
     result = translator.track_to_mpd_format(Track())
     self.assertIn(('file', ''), result)
     self.assertIn(('Time', 0), result)
     self.assertIn(('Artist', ''), result)
     self.assertIn(('Title', ''), result)
     self.assertIn(('Album', ''), result)
     self.assertIn(('Track', 0), result)
     self.assertNotIn(('Date', ''), result)
     self.assertEqual(len(result), 6)
开发者ID:AndroidMarv,项目名称:mopidy,代码行数:10,代码来源:test_translator.py


示例6: test_track_to_mpd_format_for_empty_track

 def test_track_to_mpd_format_for_empty_track(self):
     result = translator.track_to_mpd_format(Track(uri="a uri", length=137000))
     self.assertIn(("file", "a uri"), result)
     self.assertIn(("Time", 137), result)
     self.assertNotIn(("Artist", ""), result)
     self.assertNotIn(("Title", ""), result)
     self.assertNotIn(("Album", ""), result)
     self.assertNotIn(("Track", 0), result)
     self.assertNotIn(("Date", ""), result)
     self.assertEqual(len(result), 2)
开发者ID:aefo,项目名称:mopidy,代码行数:10,代码来源:test_translator.py


示例7: test_track_to_mpd_format_for_empty_track

 def test_track_to_mpd_format_for_empty_track(self):
     result = translator.track_to_mpd_format(
         Track(uri='a uri', length=137000)
     )
     self.assertIn(('file', 'a uri'), result)
     self.assertIn(('Time', 137), result)
     self.assertNotIn(('Artist', ''), result)
     self.assertNotIn(('Title', ''), result)
     self.assertNotIn(('Album', ''), result)
     self.assertNotIn(('Track', 0), result)
     self.assertNotIn(('Date', ''), result)
     self.assertEqual(len(result), 2)
开发者ID:HaBaLeS,项目名称:mopidy,代码行数:12,代码来源:test_translator.py


示例8: currentsong

def currentsong(context):
    """
    *musicpd.org, status section:*

        ``currentsong``

        Displays the song info of the current song (same song that is
        identified in status).
    """
    tl_track = context.core.playback.current_tl_track.get()
    if tl_track is not None:
        position = context.core.tracklist.index(tl_track).get()
        return track_to_mpd_format(tl_track, position=position)
开发者ID:MacGyverQue,项目名称:mopidy,代码行数:13,代码来源:status.py


示例9: playlistfind

def playlistfind(context, tag, needle):
    """
    *musicpd.org, current playlist section:*

        ``playlistfind {TAG} {NEEDLE}``

        Finds songs in the current playlist with strict matching.
    """
    if tag == 'filename':
        tl_tracks = context.core.tracklist.filter({'uri': [needle]}).get()
        if not tl_tracks:
            return None
        position = context.core.tracklist.index(tl_tracks[0]).get()
        return translator.track_to_mpd_format(tl_tracks[0], position=position)
    raise exceptions.MpdNotImplemented  # TODO
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:15,代码来源:current_playlist.py


示例10: listallinfo

def listallinfo(context, uri=None):
    """
    *musicpd.org, music database section:*

        ``listallinfo [URI]``

        Same as ``listall``, except it also returns metadata info in the
        same format as ``lsinfo``.
    """
    result = []
    for path, lookup_future in context.browse(uri):
        if not lookup_future:
            result.append(('directory', path))
        else:
            for track in lookup_future.get():
                result.extend(translator.track_to_mpd_format(track))
    return result
开发者ID:Baileym1,项目名称:mopidy,代码行数:17,代码来源:music_db.py


示例11: playlistid

def playlistid(context, tlid=None):
    """
    *musicpd.org, current playlist section:*

        ``playlistid {SONGID}``

        Displays a list of songs in the playlist. ``SONGID`` is optional
        and specifies a single song to display info for.
    """
    if tlid is not None:
        tl_tracks = context.core.tracklist.filter(tlid=[tlid]).get()
        if not tl_tracks:
            raise exceptions.MpdNoExistError('No such song')
        position = context.core.tracklist.index(tl_tracks[0]).get()
        return translator.track_to_mpd_format(tl_tracks[0], position=position)
    else:
        return translator.tracks_to_mpd_format(
            context.core.tracklist.tl_tracks.get())
开发者ID:AndroidMarv,项目名称:mopidy,代码行数:18,代码来源:current_playlist.py


示例12: listallinfo

def listallinfo(context, uri=None):
    """
    *musicpd.org, music database section:*

        ``listallinfo [URI]``

        Same as ``listall``, except it also returns metadata info in the
        same format as ``lsinfo``.
    """
    dirs_and_futures = []
    result = []
    root_path = translator.normalize_path(uri)
    try:
        uri = context.directory_path_to_uri(root_path)
    except MpdNoExistError as e:
        e.command = 'listallinfo'
        e.message = 'Not found'
        raise
    browse_futures = [(root_path, context.core.library.browse(uri))]

    while browse_futures:
        base_path, future = browse_futures.pop()
        for ref in future.get():
            if ref.type == Ref.DIRECTORY:
                path = '/'.join([base_path, ref.name.replace('/', '')])
                future = context.core.library.browse(ref.uri)
                browse_futures.append((path, future))
                dirs_and_futures.append(('directory', path))
            elif ref.type == Ref.TRACK:
                # TODO Lookup tracks in batch for better performance
                dirs_and_futures.append(context.core.library.lookup(ref.uri))

    result = []
    for obj in dirs_and_futures:
        if hasattr(obj, 'get'):
            for track in obj.get():
                result.extend(translator.track_to_mpd_format(track))
        else:
            result.append(obj)

    if not result:
        raise MpdNoExistError('Not found')

    return [('directory', root_path)] + result
开发者ID:Shugyousha,项目名称:mopidy,代码行数:44,代码来源:music_db.py


示例13: test_track_to_mpd_format_for_nonempty_track

 def test_track_to_mpd_format_for_nonempty_track(self):
     result = translator.track_to_mpd_format(
         TlTrack(122, self.track), position=9)
     self.assertIn(('file', 'a uri'), result)
     self.assertIn(('Time', 137), result)
     self.assertIn(('Artist', 'an artist'), result)
     self.assertIn(('Title', 'a name'), result)
     self.assertIn(('Album', 'an album'), result)
     self.assertIn(('AlbumArtist', 'an other artist'), result)
     self.assertIn(('Composer', 'a composer'), result)
     self.assertIn(('Performer', 'a performer'), result)
     self.assertIn(('Genre', 'a genre'), result)
     self.assertIn(('Track', '7/13'), result)
     self.assertIn(('Date', datetime.date(1977, 1, 1)), result)
     self.assertIn(('Disc', '1'), result)
     self.assertIn(('Pos', 9), result)
     self.assertIn(('Id', 122), result)
     self.assertNotIn(('Comment', 'a comment'), result)
     self.assertEqual(len(result), 14)
开发者ID:FabrizioCongia,项目名称:mopidy,代码行数:19,代码来源:test_translator.py


示例14: test_track_to_mpd_format_for_nonempty_track

 def test_track_to_mpd_format_for_nonempty_track(self):
     result = translator.track_to_mpd_format(TlTrack(122, self.track), position=9)
     self.assertIn(("file", "a uri"), result)
     self.assertIn(("Time", 137), result)
     self.assertIn(("Artist", "an artist"), result)
     self.assertIn(("Title", "a name"), result)
     self.assertIn(("Album", "an album"), result)
     self.assertIn(("AlbumArtist", "an other artist"), result)
     self.assertIn(("Composer", "a composer"), result)
     self.assertIn(("Performer", "a performer"), result)
     self.assertIn(("Genre", "a genre"), result)
     self.assertIn(("Track", "7/13"), result)
     self.assertIn(("Date", "1977-01-01"), result)
     self.assertIn(("Disc", 1), result)
     self.assertIn(("Pos", 9), result)
     self.assertIn(("Id", 122), result)
     self.assertIn(("X-AlbumUri", "urischeme:album:12345"), result)
     self.assertIn(("X-AlbumImage", "image1"), result)
     self.assertNotIn(("Comment", "a comment"), result)
     self.assertEqual(len(result), 16)
开发者ID:aefo,项目名称:mopidy,代码行数:20,代码来源:test_translator.py


示例15: test_track_to_mpd_format_for_nonempty_track

 def test_track_to_mpd_format_for_nonempty_track(self):
     result = translator.track_to_mpd_format(
         TlTrack(122, self.track), position=9)
     self.assertIn(('file', 'a uri'), result)
     self.assertIn(('Time', 137), result)
     self.assertIn(('Artist', 'an artist'), result)
     self.assertIn(('Title', 'a name'), result)
     self.assertIn(('Album', 'an album'), result)
     self.assertIn(('AlbumArtist', 'an other artist'), result)
     self.assertIn(('Composer', 'a composer'), result)
     self.assertIn(('Performer', 'a performer'), result)
     self.assertIn(('Genre', 'a genre'), result)
     self.assertIn(('Track', '7/13'), result)
     self.assertIn(('Date', '1977-01-01'), result)
     self.assertIn(('Disc', 1), result)
     self.assertIn(('Pos', 9), result)
     self.assertIn(('Id', 122), result)
     self.assertIn(('X-AlbumUri', 'urischeme:album:12345'), result)
     self.assertIn(('X-AlbumImage', 'image1'), result)
     self.assertNotIn(('Comment', 'a comment'), result)
     self.assertEqual(len(result), 16)
开发者ID:HaBaLeS,项目名称:mopidy,代码行数:21,代码来源:test_translator.py


示例16: lsinfo

def lsinfo(context, uri=None):
    """
    *musicpd.org, music database section:*

        ``lsinfo [URI]``

        Lists the contents of the directory ``URI``.

        When listing the root directory, this currently returns the list of
        stored playlists. This behavior is deprecated; use
        ``listplaylists`` instead.

    MPD returns the same result, including both playlists and the files and
    directories located at the root level, for both ``lsinfo``, ``lsinfo
    ""``, and ``lsinfo "/"``.
    """
    result = []
    root_path = translator.normalize_path(uri, relative=True)
    try:
        uri = context.directory_path_to_uri(root_path)
    except MpdNoExistError as e:
        e.command = 'lsinfo'
        e.message = 'Not found'
        raise

    if uri is None:
        result.extend(stored_playlists.listplaylists(context))

    for ref in context.core.library.browse(uri).get():
        if ref.type == Ref.DIRECTORY:
            path = '/'.join([root_path, ref.name.replace('/', '')])
            result.append(('directory', path.lstrip('/')))
        elif ref.type == Ref.TRACK:
            # TODO Lookup tracks in batch for better performance
            tracks = context.core.library.lookup(ref.uri).get()
            if tracks:
                result.extend(translator.track_to_mpd_format(tracks[0]))
    return result
开发者ID:Shugyousha,项目名称:mopidy,代码行数:38,代码来源:music_db.py


示例17: test_track_to_mpd_format_with_position_and_tlid

 def test_track_to_mpd_format_with_position_and_tlid(self):
     result = translator.track_to_mpd_format(TlTrack(2, Track(uri="a uri")), position=1)
     self.assertIn(("Pos", 1), result)
     self.assertIn(("Id", 2), result)
开发者ID:aefo,项目名称:mopidy,代码行数:4,代码来源:test_translator.py


示例18: test_track_to_mpd_format_with_tlid

 def test_track_to_mpd_format_with_tlid(self):
     result = translator.track_to_mpd_format(TlTrack(1, Track()))
     self.assertNotIn(("Id", 1), result)
开发者ID:aefo,项目名称:mopidy,代码行数:3,代码来源:test_translator.py


示例19: test_track_to_mpd_format_with_position

 def test_track_to_mpd_format_with_position(self):
     result = translator.track_to_mpd_format(Track(), position=1)
     self.assertNotIn(("Pos", 1), result)
开发者ID:aefo,项目名称:mopidy,代码行数:3,代码来源:test_translator.py


示例20: test_track_to_mpd_format_musicbrainz_trackid

 def test_track_to_mpd_format_musicbrainz_trackid(self):
     track = self.track.replace(musicbrainz_id="foo")
     result = translator.track_to_mpd_format(track)
     self.assertIn(("MUSICBRAINZ_TRACKID", "foo"), result)
开发者ID:aefo,项目名称:mopidy,代码行数:4,代码来源:test_translator.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python encoding.locale_decode函数代码示例发布时间:2022-05-27
下一篇:
Python status.status函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap