Esempio n. 1
0
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)
        start = songpos
        end = songpos + 1
        if start == -1:
            end = None
        cpids = [
            ct[0] for ct in context.backend.current_playlist.cp_tracks.get()
        ]
        return tracks_to_mpd_format(
            context.backend.current_playlist.tracks.get(),
            start,
            end,
            cpids=cpids)
    else:
        if start is None:
            start = 0
        start = int(start)
        if not (0 <= start <= len(
                context.backend.current_playlist.tracks.get())):
            raise MpdArgError(u'Bad song index', command=u'playlistinfo')
        if end is not None:
            end = int(end)
            if end > len(context.backend.current_playlist.tracks.get()):
                end = None
        cpids = [
            ct[0] for ct in context.backend.current_playlist.cp_tracks.get()
        ]
        return tracks_to_mpd_format(
            context.backend.current_playlist.tracks.get(),
            start,
            end,
            cpids=cpids)
Esempio n. 2
0
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', command='playlistinfo')
        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)
Esempio n. 3
0
def search(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``search {TYPE} {WHAT}``

        Searches for any song that contains ``WHAT``. ``TYPE`` can be
        ``title``, ``artist``, ``album`` or ``filename``. Search is not
        case sensitive.

    *GMPC:*

    - does not add quotes around the field argument.
    - uses the undocumented field ``any``.
    - searches for multiple words like this::

        search any "foo" any "bar" any "baz"

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the field argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = _build_query(mpd_query)
    except ValueError:
        return
    return tracks_to_mpd_format(
        context.core.library.search(**query).get())
Esempio n. 4
0
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)
Esempio n. 5
0
def find(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``find {TYPE} {WHAT}``

        Finds songs in the db that are exactly ``WHAT``. ``TYPE`` should be
        ``album``, ``artist``, or ``title``. ``WHAT`` is what to find.

    *GMPC:*

    - does not add quotes around the field argument.
    - also uses ``find album "[ALBUM]" artist "[ARTIST]"`` to list album
      tracks.

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the type argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = _build_query(mpd_query)
    except ValueError:
        return
    return tracks_to_mpd_format(context.core.library.find_exact(**query).get())
Esempio n. 6
0
def search(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``search {TYPE} {WHAT}``

        Searches for any song that contains ``WHAT``. ``TYPE`` can be
        ``title``, ``artist``, ``album`` or ``filename``. Search is not
        case sensitive.

    *GMPC:*

    - does not add quotes around the field argument.
    - uses the undocumented field ``any``.
    - searches for multiple words like this::

        search any "foo" any "bar" any "baz"

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the field argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = _build_query(mpd_query)
    except ValueError:
        return
    return tracks_to_mpd_format(context.core.library.search(**query).get())
Esempio n. 7
0
def find(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``find {TYPE} {WHAT}``

        Finds songs in the db that are exactly ``WHAT``. ``TYPE`` should be
        ``album``, ``artist``, or ``title``. ``WHAT`` is what to find.

    *GMPC:*

    - does not add quotes around the field argument.
    - also uses ``find album "[ALBUM]" artist "[ARTIST]"`` to list album
      tracks.

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the type argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = _build_query(mpd_query)
    except ValueError:
        return
    return tracks_to_mpd_format(
        context.core.library.find_exact(**query).get())
Esempio n. 8
0
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)
        start = songpos
        end = songpos + 1
        if start == -1:
            end = None
        cpids = [ct[0] for ct in
            context.backend.current_playlist.cp_tracks.get()]
        return tracks_to_mpd_format(
            context.backend.current_playlist.tracks.get(),
            start, end, cpids=cpids)
    else:
        if start is None:
            start = 0
        start = int(start)
        if not (0 <= start <= len(
                context.backend.current_playlist.tracks.get())):
            raise MpdArgError(u'Bad song index', command=u'playlistinfo')
        if end is not None:
            end = int(end)
            if end > len(context.backend.current_playlist.tracks.get()):
                end = None
        cpids = [ct[0] for ct in
            context.backend.current_playlist.cp_tracks.get()]
        return tracks_to_mpd_format(
            context.backend.current_playlist.tracks.get(),
            start, end, cpids=cpids)
Esempio n. 9
0
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
    if int(version) < context.backend.current_playlist.version:
        return tracks_to_mpd_format(context.backend.current_playlist.cp_tracks.get())
Esempio n. 10
0
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
    if int(version) < context.core.tracklist.version.get():
        return translator.tracks_to_mpd_format(
            context.core.tracklist.tl_tracks.get())
Esempio n. 11
0
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())
Esempio n. 12
0
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())
Esempio n. 13
0
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())
Esempio n. 14
0
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())
Esempio n. 15
0
def find(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``find {TYPE} {WHAT}``

        Finds songs in the db that are exactly ``WHAT``. ``TYPE`` can be any
        tag supported by MPD, or one of the two special parameters - ``file``
        to search by full path (relative to database root), and ``any`` to
        match against all available tags. ``WHAT`` is what to find.

    *GMPC:*

    - does not add quotes around the field argument.
    - also uses ``find album "[ALBUM]" artist "[ARTIST]"`` to list album
      tracks.

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the type argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = _query_from_mpd_search_format(mpd_query)
    except ValueError:
        return
    results = context.core.library.find_exact(**query).get()
    result_tracks = []
    if ('artist' not in query and 'albumartist' not in query
            and 'composer' not in query and 'performer' not in query):
        result_tracks += [_artist_as_track(a) for a in _get_artists(results)]
    if 'album' not in query:
        result_tracks += [_album_as_track(a) for a in _get_albums(results)]
    result_tracks += _get_tracks(results)
    return translator.tracks_to_mpd_format(result_tracks)
Esempio n. 16
0
def find(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``find {TYPE} {WHAT}``

        Finds songs in the db that are exactly ``WHAT``. ``TYPE`` can be any
        tag supported by MPD, or one of the two special parameters - ``file``
        to search by full path (relative to database root), and ``any`` to
        match against all available tags. ``WHAT`` is what to find.

    *GMPC:*

    - does not add quotes around the field argument.
    - also uses ``find album "[ALBUM]" artist "[ARTIST]"`` to list album
      tracks.

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the type argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = translator.query_from_mpd_search_format(mpd_query)
    except ValueError:
        return
    results = context.core.library.find_exact(**query).get()
    result_tracks = []
    if 'artist' not in query:
        result_tracks += [_artist_as_track(a) for a in _get_artists(results)]
    if 'album' not in query:
        result_tracks += [_album_as_track(a) for a in _get_albums(results)]
    result_tracks += _get_tracks(results)
    return translator.tracks_to_mpd_format(result_tracks)
Esempio n. 17
0
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.cp_tracks.get().index(
                cp_track)
            return cp_track.track.mpd_format(position=position, cpid=cpid)
        except LookupError:
            raise MpdNoExistError(u'No such song', command=u'playlistid')
    else:
        cpids = [ct[0] for ct in
            context.backend.current_playlist.cp_tracks.get()]
        return tracks_to_mpd_format(
            context.backend.current_playlist.tracks.get(), cpids=cpids)
Esempio n. 18
0
def search(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``search {TYPE} {WHAT} [...]``

        Searches for any song that contains ``WHAT``. Parameters have the same
        meaning as for ``find``, except that search is not case sensitive.

    *GMPC:*

    - does not add quotes around the field argument.
    - uses the undocumented field ``any``.
    - searches for multiple words like this::

        search any "foo" any "bar" any "baz"

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the field argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = translator.query_from_mpd_search_format(mpd_query)
    except ValueError:
        return
    results = context.core.library.search(**query).get()
    artists = [_artist_as_track(a) for a in _get_artists(results)]
    albums = [_album_as_track(a) for a in _get_albums(results)]
    tracks = _get_tracks(results)
    return translator.tracks_to_mpd_format(artists + albums + tracks)
Esempio n. 19
0
def search(context, mpd_query):
    """
    *musicpd.org, music database section:*

        ``search {TYPE} {WHAT} [...]``

        Searches for any song that contains ``WHAT``. Parameters have the same
        meaning as for ``find``, except that search is not case sensitive.

    *GMPC:*

    - does not add quotes around the field argument.
    - uses the undocumented field ``any``.
    - searches for multiple words like this::

        search any "foo" any "bar" any "baz"

    *ncmpc:*

    - does not add quotes around the field argument.
    - capitalizes the field argument.

    *ncmpcpp:*

    - also uses the search type "date".
    - uses "file" instead of "filename".
    """
    try:
        query = translator.query_from_mpd_search_format(mpd_query)
    except ValueError:
        return
    results = context.core.library.search(**query).get()
    artists = [_artist_as_track(a) for a in _get_artists(results)]
    albums = [_album_as_track(a) for a in _get_albums(results)]
    tracks = _get_tracks(results)
    return translator.tracks_to_mpd_format(artists + albums + tracks)
Esempio n. 20
0
 def mpd_format(self, *args, **kwargs):
     """Not a part of the generic backend API."""
     kwargs["cpids"] = [ct[0] for ct in self._cp_tracks]
     return translator.tracks_to_mpd_format(self.tracks, *args, **kwargs)