コード例 #1
0
ファイル: current_playlist.py プロジェクト: ruudud/mopidy
def addid(context, uri, songpos=None):
    """
    *musicpd.org, current playlist section:*

        ``addid {URI} [POSITION]``

        Adds a song to the playlist (non-recursive) and returns the song id.

        ``URI`` is always a single file or URL. For example::

            addid "foo.mp3"
            Id: 999
            OK

    *Clarifications:*

    - ``addid ""`` should return an error.
    """
    if not uri:
        raise MpdNoExistError(u'No such song', command=u'addid')
    if songpos is not None:
        songpos = int(songpos)
    track = context.backend.library.lookup(uri).get()
    if track is None:
        raise MpdNoExistError(u'No such song', command=u'addid')
    if songpos and songpos > len(
            context.backend.current_playlist.tracks.get()):
        raise MpdArgError(u'Bad song index', command=u'addid')
    cp_track = context.backend.current_playlist.add(track,
                                                    at_position=songpos).get()
    return ('Id', cp_track.cpid)
コード例 #2
0
ファイル: current_playlist.py プロジェクト: qls0ulp/mopidy
def addid(context, uri, songpos=None):
    """
    *musicpd.org, current playlist section:*

        ``addid {URI} [POSITION]``

        Adds a song to the playlist (non-recursive) and returns the song id.

        ``URI`` is always a single file or URL. For example::

            addid "foo.mp3"
            Id: 999
            OK

    *Clarifications:*

    - ``addid ""`` should return an error.
    """
    if not uri:
        raise MpdNoExistError('No such song', command='addid')
    if songpos is not None:
        songpos = int(songpos)
    if songpos and songpos > context.core.tracklist.length.get():
        raise MpdArgError('Bad song index', command='addid')
    tl_tracks = context.core.tracklist.add(uri=uri, at_position=songpos).get()
    if not tl_tracks:
        raise MpdNoExistError('No such song', command='addid')
    return ('Id', tl_tracks[0].tlid)
コード例 #3
0
def playid(context, cpid):
    """
    *musicpd.org, playback section:*

        ``playid [SONGID]``

        Begins playing the playlist at song ``SONGID``.

    *Clarifications:*

    - ``playid "-1"`` when playing is ignored.
    - ``playid "-1"`` when paused resumes playback.
    - ``playid "-1"`` when stopped with a current track starts playback at the
      current track.
    - ``playid "-1"`` when stopped without a current track, e.g. after playlist
      replacement, starts playback at the first track.
    """
    cpid = int(cpid)
    if cpid == -1:
        return _play_minus_one(context)
    try:
        cp_track = context.backend.current_playlist.get(cpid=cpid).get()
        return context.backend.playback.play(cp_track).get()
    except LookupError:
        raise MpdNoExistError(u'No such song', command=u'playid')
コード例 #4
0
def load(context, name, start=None, end=None):
    """
    *musicpd.org, stored playlists section:*

        ``load {NAME} [START:END]``

        Loads the playlist into the current queue. Playlist plugins are
        supported. A range may be specified to load only a part of the
        playlist.

    *Clarifications:*

    - ``load`` appends the given playlist to the current playlist.

    - MPD 0.17.1 does not support open-ended ranges, i.e. without end
      specified, for the ``load`` command, even though MPD's general range docs
      allows open-ended ranges.

    - MPD 0.17.1 does not fail if the specified range is outside the playlist,
      in either or both ends.
    """
    playlists = context.core.playlists.filter(name=name).get()
    if not playlists:
        raise MpdNoExistError('No such playlist', command='load')
    if start is not None:
        start = int(start)
    if end is not None:
        end = int(end)
    context.core.tracklist.add(playlists[0].tracks[start:end])
コード例 #5
0
ファイル: audio_output.py プロジェクト: eisnerd/mopidy
def disableoutput(context, outputid):
    """
    *musicpd.org, audio output section:*

        ``disableoutput``

        Turns an output off.
    """
    if int(outputid) == 0:
        context.core.playback.set_mute(False)
    else:
        raise MpdNoExistError('No such audio output', command='disableoutput')
コード例 #6
0
ファイル: current_playlist.py プロジェクト: qls0ulp/mopidy
def deleteid(context, tlid):
    """
    *musicpd.org, current playlist section:*

        ``deleteid {SONGID}``

        Deletes the song ``SONGID`` from the playlist
    """
    tlid = int(tlid)
    tl_tracks = context.core.tracklist.remove(tlid=[tlid]).get()
    if not tl_tracks:
        raise MpdNoExistError('No such song', command='deleteid')
コード例 #7
0
ファイル: current_playlist.py プロジェクト: ruudud/mopidy
def deleteid(context, cpid):
    """
    *musicpd.org, current playlist section:*

        ``deleteid {SONGID}``

        Deletes the song ``SONGID`` from the playlist
    """
    try:
        cpid = int(cpid)
        if context.backend.playback.current_cpid.get() == cpid:
            context.backend.playback.next()
        return context.backend.current_playlist.remove(cpid=cpid).get()
    except LookupError:
        raise MpdNoExistError(u'No such song', command=u'deleteid')
コード例 #8
0
ファイル: stored_playlists.py プロジェクト: gnil/mopidy
def load(context, name):
    """
    *musicpd.org, stored playlists section:*

        ``load {NAME}``

        Loads the playlist ``NAME.m3u`` from the playlist directory.

    *Clarifications:*

    - ``load`` appends the given playlist to the current playlist.
    """
    playlists = context.core.playlists.filter(name=name).get()
    if not playlists:
        raise MpdNoExistError('No such playlist', command='load')
    context.core.tracklist.add(playlists[0].tracks)
コード例 #9
0
ファイル: current_playlist.py プロジェクト: qls0ulp/mopidy
def moveid(context, tlid, to):
    """
    *musicpd.org, current playlist section:*

        ``moveid {FROM} {TO}``

        Moves the song with ``FROM`` (songid) to ``TO`` (playlist index) in
        the playlist. If ``TO`` is negative, it is relative to the current
        song in the playlist (if there is one).
    """
    tlid = int(tlid)
    to = int(to)
    tl_tracks = context.core.tracklist.filter(tlid=[tlid]).get()
    if not tl_tracks:
        raise MpdNoExistError('No such song', command='moveid')
    position = context.core.tracklist.index(tl_tracks[0]).get()
    context.core.tracklist.move(position, position + 1, to)
コード例 #10
0
ファイル: current_playlist.py プロジェクト: qls0ulp/mopidy
def swapid(context, tlid1, tlid2):
    """
    *musicpd.org, current playlist section:*

        ``swapid {SONG1} {SONG2}``

        Swaps the positions of ``SONG1`` and ``SONG2`` (both song ids).
    """
    tlid1 = int(tlid1)
    tlid2 = int(tlid2)
    tl_tracks1 = context.core.tracklist.filter(tlid=[tlid1]).get()
    tl_tracks2 = context.core.tracklist.filter(tlid=[tlid2]).get()
    if not tl_tracks1 or not tl_tracks2:
        raise MpdNoExistError('No such song', command='swapid')
    position1 = context.core.tracklist.index(tl_tracks1[0]).get()
    position2 = context.core.tracklist.index(tl_tracks2[0]).get()
    swap(context, position1, position2)
コード例 #11
0
ファイル: stored_playlists.py プロジェクト: ruudud/mopidy
def load(context, name):
    """
    *musicpd.org, stored playlists section:*

        ``load {NAME}``

        Loads the playlist ``NAME.m3u`` from the playlist directory.

    *Clarifications:*

    - ``load`` appends the given playlist to the current playlist.
    """
    try:
        playlist = context.backend.stored_playlists.get(name=name).get()
        context.backend.current_playlist.append(playlist.tracks)
    except LookupError:
        raise MpdNoExistError(u'No such playlist', command=u'load')
コード例 #12
0
ファイル: stored_playlists.py プロジェクト: gnil/mopidy
def listplaylistinfo(context, name):
    """
    *musicpd.org, stored playlists section:*

        ``listplaylistinfo {NAME}``

        Lists songs in the playlist ``NAME.m3u``.

    Output format:

        Standard track listing, with fields: file, Time, Title, Date,
        Album, Artist, Track
    """
    playlists = context.core.playlists.filter(name=name).get()
    if not playlists:
        raise MpdNoExistError('No such playlist', command='listplaylistinfo')
    return playlist_to_mpd_format(playlists[0])
コード例 #13
0
ファイル: stored_playlists.py プロジェクト: ruudud/mopidy
def listplaylistinfo(context, name):
    """
    *musicpd.org, stored playlists section:*

        ``listplaylistinfo {NAME}``

        Lists songs in the playlist ``NAME.m3u``.

    Output format:

        Standard track listing, with fields: file, Time, Title, Date,
        Album, Artist, Track
    """
    try:
        playlist = context.backend.stored_playlists.get(name=name).get()
        return playlist.mpd_format()
    except LookupError:
        raise MpdNoExistError(u'No such playlist', command=u'listplaylistinfo')
コード例 #14
0
ファイル: current_playlist.py プロジェクト: qls0ulp/mopidy
def add(context, uri):
    """
    *musicpd.org, current playlist section:*

        ``add {URI}``

        Adds the file ``URI`` to the playlist (directories add recursively).
        ``URI`` can also be a single file.

    *Clarifications:*

    - ``add ""`` should add all tracks in the library to the current playlist.
    """
    if not uri:
        return
    tl_tracks = context.core.tracklist.add(uri=uri).get()
    if not tl_tracks:
        raise MpdNoExistError('directory or file not found', command='add')
コード例 #15
0
ファイル: stored_playlists.py プロジェクト: gnil/mopidy
def listplaylist(context, name):
    """
    *musicpd.org, stored playlists section:*

        ``listplaylist {NAME}``

        Lists the files in the playlist ``NAME.m3u``.

    Output format::

        file: relative/path/to/file1.flac
        file: relative/path/to/file2.ogg
        file: relative/path/to/file3.mp3
    """
    playlists = context.core.playlists.filter(name=name).get()
    if not playlists:
        raise MpdNoExistError('No such playlist', command='listplaylist')
    return ['file: %s' % t.uri for t in playlists[0].tracks]
コード例 #16
0
ファイル: stored_playlists.py プロジェクト: ruudud/mopidy
def listplaylist(context, name):
    """
    *musicpd.org, stored playlists section:*

        ``listplaylist {NAME}``

        Lists the files in the playlist ``NAME.m3u``.

    Output format::

        file: relative/path/to/file1.flac
        file: relative/path/to/file2.ogg
        file: relative/path/to/file3.mp3
    """
    try:
        playlist = context.backend.stored_playlists.get(name=name).get()
        return ['file: %s' % t.uri for t in playlist.tracks]
    except LookupError:
        raise MpdNoExistError(u'No such playlist', command=u'listplaylist')
コード例 #17
0
ファイル: current_playlist.py プロジェクト: qls0ulp/mopidy
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())
コード例 #18
0
ファイル: current_playlist.py プロジェクト: xim/mopidy
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())
コード例 #19
0
ファイル: current_playlist.py プロジェクト: ruudud/mopidy
def add(context, uri):
    """
    *musicpd.org, current playlist section:*

        ``add {URI}``

        Adds the file ``URI`` to the playlist (directories add recursively).
        ``URI`` can also be a single file.

    *Clarifications:*

    - ``add ""`` should add all tracks in the library to the current playlist.
    """
    if not uri:
        return
    for uri_scheme in context.backend.uri_schemes.get():
        if uri.startswith(uri_scheme):
            track = context.backend.library.lookup(uri).get()
            if track is not None:
                context.backend.current_playlist.add(track)
                return
    raise MpdNoExistError(u'directory or file not found', command=u'add')
コード例 #20
0
ファイル: playback.py プロジェクト: eisnerd/mopidy
def playid(context, tlid):
    """
    *musicpd.org, playback section:*

        ``playid [SONGID]``

        Begins playing the playlist at song ``SONGID``.

    *Clarifications:*

    - ``playid "-1"`` when playing is ignored.
    - ``playid "-1"`` when paused resumes playback.
    - ``playid "-1"`` when stopped with a current track starts playback at the
      current track.
    - ``playid "-1"`` when stopped without a current track, e.g. after playlist
      replacement, starts playback at the first track.
    """
    tlid = int(tlid)
    if tlid == -1:
        return _play_minus_one(context)
    tl_tracks = context.core.tracklist.filter(tlid=tlid).get()
    if not tl_tracks:
        raise MpdNoExistError('No such song', command='playid')
    return context.core.playback.play(tl_tracks[0]).get()