本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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())
示例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
示例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)
示例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)
示例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)