本文整理汇总了Python中mopidy.frontends.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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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 is not None:
songpos = int(songpos)
cp_track = context.backend.current_playlist.get(cpid=songpos).get()
return track_to_mpd_format(cp_track, position=songpos)
else:
if start is None:
start = 0
start = int(start)
if not (0 <= start <= context.backend.current_playlist.length.get()):
raise MpdArgError(u"Bad song index", command=u"playlistinfo")
if end is not None:
end = int(end)
if end > context.backend.current_playlist.length.get():
end = None
cp_tracks = context.backend.current_playlist.cp_tracks.get()
return tracks_to_mpd_format(cp_tracks, start, end)
示例2: translate
def translate(self, track):
base_path = self.media_dir.encode("utf-8")
result = dict(translator.track_to_mpd_format(track))
result["file"] = uri_to_path(result["file"])[len(base_path) + 1 :]
result["key"] = os.path.basename(result["file"])
result["mtime"] = mtime("")
return translator.order_mpd_track_info(result.items())
示例3: translate
def translate(self, track):
base_path = self.media_dir.encode('utf-8')
result = dict(translator.track_to_mpd_format(track))
result['file'] = uri_to_path(result['file'])[len(base_path) + 1:]
result['key'] = os.path.basename(result['file'])
result['mtime'] = mtime('')
return translator.order_mpd_track_info(result.items())
示例4: translate
def translate(self, track):
folder = settings.LOCAL_MUSIC_PATH
result = dict(translator.track_to_mpd_format(track))
result['file'] = uri_to_path(result['file'])
result['file'] = result['file'][len(folder)+1:]
result['key'] = os.path.basename(result['file'])
result['mtime'] = mtime('')
return translator.order_mpd_track_info(result.items())
示例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.assert_(('file', '') in result)
self.assert_(('Time', 0) in result)
self.assert_(('Artist', '') in result)
self.assert_(('Title', '') in result)
self.assert_(('Album', '') in result)
self.assert_(('Track', 0) in result)
self.assert_(('Date', '') in result)
self.assertEqual(len(result), 7)
示例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())
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.assertIn(("Date", ""), result)
self.assertEqual(len(result), 7)
示例7: 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(("Track", "7/13"), result)
self.assertIn(("Date", datetime.date(1977, 1, 1)), result)
self.assertIn(("Pos", 9), result)
self.assertIn(("Id", 122), result)
self.assertEqual(len(result), 10)
示例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).
"""
current_cp_track = context.backend.playback.current_cp_track.get()
if current_cp_track is not None:
position = context.backend.playback.current_playlist_position.get()
return track_to_mpd_format(current_cp_track, position=position)
示例9: 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)
示例10: test_track_to_mpd_format_for_nonempty_track
def test_track_to_mpd_format_for_nonempty_track(self):
result = translator.track_to_mpd_format(self.track, position=9, cpid=122)
self.assert_(('file', 'a uri') in result)
self.assert_(('Time', 137) in result)
self.assert_(('Artist', 'an artist') in result)
self.assert_(('Title', 'a name') in result)
self.assert_(('Album', 'an album') in result)
self.assert_(('AlbumArtist', 'an other artist') in result)
self.assert_(('Track', '7/13') in result)
self.assert_(('Date', dt.date(1977, 1, 1)) in result)
self.assert_(('Pos', 9) in result)
self.assert_(('Id', 122) in result)
self.assertEqual(len(result), 10)
示例11: 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(('Track', '7/13'), result)
self.assertIn(('Date', datetime.date(1977, 1, 1)), result)
self.assertIn(('Pos', 9), result)
self.assertIn(('Id', 122), result)
self.assertEqual(len(result), 10)
示例12: playlistid
def playlistid(context, cpid=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 cpid is not None:
try:
cpid = int(cpid)
cp_track = context.backend.current_playlist.get(cpid=cpid).get()
position = context.backend.current_playlist.index(cp_track).get()
return track_to_mpd_format(cp_track, position=position)
except LookupError:
raise MpdNoExistError(u"No such song", command=u"playlistid")
else:
return tracks_to_mpd_format(context.backend.current_playlist.cp_tracks.get())
示例13: playlistfind
def playlistfind(context, tag, needle):
"""
*musicpd.org, current playlist section:*
``playlistfind {TAG} {NEEDLE}``
Finds songs in the current playlist with strict matching.
*GMPC:*
- does not add quotes around the tag.
"""
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 MpdNotImplemented # TODO
示例14: 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:
tlid = int(tlid)
tl_tracks = context.core.tracklist.filter(tlid=tlid).get()
if not tl_tracks:
raise MpdNoExistError('No such song', command='playlistid')
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())
示例15: playlistfind
def playlistfind(context, tag, needle):
"""
*musicpd.org, current playlist section:*
``playlistfind {TAG} {NEEDLE}``
Finds songs in the current playlist with strict matching.
*GMPC:*
- does not add quotes around the tag.
"""
if tag == "filename":
try:
cp_track = context.backend.current_playlist.get(uri=needle).get()
position = context.backend.current_playlist.index(cp_track).get()
return track_to_mpd_format(cp_track, position=position)
except LookupError:
return None
raise MpdNotImplemented # TODO