当前位置: 首页>>代码示例>>Python>>正文


Python MPDClient.delete方法代码示例

本文整理汇总了Python中mpd.MPDClient.delete方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.delete方法的具体用法?Python MPDClient.delete怎么用?Python MPDClient.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpd.MPDClient的用法示例。


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

示例1: update_queue

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]
def update_queue():
	client = MPDClient()
	client.connect("localhost", 6600)
	status = client.status()
	if status['state'] == 'play':
		current_song = client.currentsong()
		current_song_position = current_song['pos']
		if int(current_song_position) > 0:
			client.delete('0:'+current_song_position)	
	try:
		response = json.dumps(client.playlistinfo())
	except:
		response = False
	client.close()
	client.disconnect()
	return response
开发者ID:matveevfedor,项目名称:collective_player,代码行数:18,代码来源:queue_update.py

示例2: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]
    s.bind("\0dadmusictv_shuffler")
except socket.error, e:
    print "An instance of this shuffler is already running. Aborting."
    import sys
    sys.exit(0)

import random
from mpd import MPDClient
client = MPDClient()
while 1:
    try:
        client.connect('localhost',6600)
        break
    except:
        print "Couldn't connect to music; waiting a bit and trying again"
        time.sleep(5)

# Read the whole library. Not a problem, because dadmusictv expects you
# to restart the Pi if you've added new songs anyway.
songs = [x["file"] for x in client.listall() if x.has_key("file")]

while 1:
    client.idle()
    s = client.status()
    if s.get("state") == "play" and s.get("nextsong") is None:
        # We are at the end of the playlist. Remove all previous songs...
        while len(client.playlistinfo()) > 2:
            client.delete(0)
        # ...and add a random song
        client.add(random.choice(songs))
开发者ID:stuartlangridge,项目名称:dadmusictv,代码行数:32,代码来源:mpd_shuffle.py

示例3: MPDWrapper

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]
class MPDWrapper():

    def __init__(self, host, port):
        self.mpd = MPDClient(use_unicode=True)
        self.changes = Changes()
        self.host = host
        self.port = port
        self.connected = False
        self.in_idle = False

    def auth(self, password):
        if self.connected:
            try:
                self.mpd.password(password)
            except CommandError:
                return False
        return True

    def connect(self):
        try:
            self.mpd.connect(self.host, self.port)
            self.connected = True
        except SocketError:
            self.connected = False
        return self.connected

    def disconnect(self):
        if self.connected:
            self.mpd.disconnect()
            self.connected = False

    def fileno(self):
        return self.mpd.fileno()

    def get_changes(self):
        return self.changes.get() if not self.in_idle else []

    def has_changes(self):
        return len(self.changes.changes)

    def idle(self):
        if self.connected and not self.in_idle:
            self.in_idle = True
            self.mpd.send_idle()
        return self.in_idle

    def noidle(self, block=False):
        if self.connected and self.in_idle:
            self.in_idle = False
            if not block:
                self.mpd.send_noidle()
            self.changes.add(*self.mpd.fetch_idle())

    def player(self, cmd, *args):
        if self.connected:
            self.changes.add("player")
            self.noidle()
            getattr(self.mpd, cmd)(*args)

    def option(self, cmd, *args):
        if self.connected:
            self.changes.add("options")
            self.noidle()
            getattr(self.mpd, cmd)(*args)

    def status(self):
        return self.mpd.status() if self.connected else None

    def ls(self, path):
        return self.mpd.lsinfo(path) if self.connected else []

    def plchanges(self, version):
        return self.mpd.plchanges(version) if self.connected else []

    def plchangesposid(self, version):
        return self.mpd.plchangesposid(version) if self.connected else []

    def add(self, path):
        if self.connected:
            self.changes.add("playlist")
            self.noidle()
            self.mpd.add(path)

    def add_and_play(self, path):
        if self.connected:
            self.changes.add("playlist", "player")
            self.noidle()
            self.mpd.playid(self.mpd.addid(path))

    def clear(self):
        if self.connected:
            self.changes.add("playlist", "player")
            self.noidle()
            self.mpd.clear()

    def delete(self, *poslist):
        if self.connected:
            self.changes.add("playlist", "player")
            self.noidle()
            self.mpd.command_list_ok_begin()
#.........这里部分代码省略.........
开发者ID:dstenb,项目名称:tbmpcpy,代码行数:103,代码来源:wrapper.py

示例4: Communicator

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]

#.........这里部分代码省略.........
        """
        try:
            self.__disconnect()
        except ConnectionError:
            pass

    def __connect(self, hostname,port):
        """
        Connect to MPD-server.
        Args:
            hostname: Hostname of MPD-server.
            port: Port of MPD-Server
        """
        self.__client.connect(hostname,port)
        
    @remoteAccess
    def __disconnect(self):
        """
        Disconnect from server.
        """
        self.__client.disconnect()

    @remoteAccess('Getting status not possible')
    def get_status(self):
        """
        Returns status of MPD-daemon.
        """
        return self.__client.status()

    @remoteAccess('Error updating playlist')
    def get_playlist(self):
        """
        Returns the playlist from server.
        """
        return self.__client.playlistinfo()
        
    ###MPD CONTROL###
    @remoteAccess('Error during control access.')
    def play(self, songid):
        """
        Start playing the song with songid.
        Args:
            songid: Song ID in the current playlist.
        """
        self.__client.play(songid)

    @remoteAccess('Error during control access.')
    def pause(self):
        """
        Pause the currently playing song.
        """
        self.__client.pause(1)

    @remoteAccess('Error during control access.')
    def unpause(self):
        """
        Unpause the currently playing song.
        """
        self.__client.pause(0)

    @remoteAccess('Error during control access.')
    def stop(self):
        """
        Stop the currently playing song.
        """
        self.__client.stop()
 
    @remoteAccess('Error during control access.')
    def previous(self):
        """
        Jump to the previous song in the playlist.
        """
        self.__client.previous()

    @remoteAccess('Error during control access.')
    def next(self):
        """
        Jump to the next song in the playlist.
        """
        self.__client.next()

    @remoteAccess('Error during control access.')
    def set_volume(self, volume):
        """
        Raise the music volume 10%.
        """
        self.__client.setvol(volume)

    @remoteAccess('Error removing item from playlist.')
    def delete(self, songid):
        """
        Delete a song from the current playlist.
        Args:
            songid: The song id in the current playlist to be deleted.
        """
        try:
            self.__client.delete(songid)
        except CommandError:
            #TODO Error handling
            self.logger.exception("delete: CommandError")
开发者ID:merten,项目名称:controlpanel,代码行数:104,代码来源:commander.py

示例5: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]
class MPDApi:
    def __init__(self, host='localhost', port='6600'):
        self.__api = MPDClient()
        self.__api.connect(host, port)

        self.__song_db = {}
        # If there are songs in the MPD queue, rebuild their info.
        for file_ in self.__api.playlist():
            file_ = file_[6:]
            song = self.playlist_find(file_)
            song_dict = self.translate_song(song)
            self.__song_db[file_] = song_dict

    @property
    def queue(self):
        queue = []
        if self.__api.currentsong():
            current_pos = int(self.__api.currentsong()['pos'])
            queue = self.__api.playlist()[current_pos:]
        return map(lambda x: x[6:], queue)

    @property
    def current_song(self):
        track = self.__api.currentsong()
        if track:
            return self.song_db.get(track['file'])
        return None

    @property
    def song_db(self):
        return self.__song_db.copy()

    def __state(self):
        return self.__api.status()['state']

    def request_song_from_api(self, search):
        search_result = self.__api.search('title', search)
        result = None
        if search_result:
            result = self.translate_song(search_result[0])
            self.__song_db[result['SongID']] = result
        return result

    def queue_song(self, file_):
        if self.__state == 'stop' and len(self.queue) == 0:
            self.__api.playid(self.playlist_find(file_)['id'])
        else:
            self.__api.add(file_)

    def auto_play(self):
        if self.__state() == 'stop' and not len(self.queue) == 0:
            while True:
                random_song = 'file: %s' % choice(self.__api.list('file'))
                if random_song not in self.__api.playlist():
                    self.queue_song(random_song)
                    break

    def remove_queue(self, file_):
        song = self.playlist_find(file_)
        if song:
            self.__api.delete(song['pos'])
            return True
        return False

    def translate_song(self, song_dict):
        result = dict(SongID=song_dict['file'])
        for key, tag in dict(SongName='title', ArtistName='artist',
                AlbumName='album').items():
            try:
                result[key] = util.asciify(song_dict[tag])
            except:
                # This song does not have that key.  Probably a .wav
                pass
        return result

    def playlist_find(self, filename):
        song = self.__api.playlistfind('file', filename)
        if song:
            return song[0]
        return None

    ###### API CALLS #######
    def api_pause(self):
        """
        Pauses the current song
        Does nothing if no song is playing
        """
        self.__api.pause()

    def api_play(self):
        """
        Plays the current song
        If the current song is paused it resumes the song
        If no songs are in the queue, it does nothing
        """
        if self.__state() == 'pause':
            self.__api.play()
        else:
            self.auto_play()

#.........这里部分代码省略.........
开发者ID:Qalthos,项目名称:groovebot,代码行数:103,代码来源:MPDApi.py

示例6: playlist_vote

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]
def playlist_vote(request, up):
    c = MPDClient()
    c.connect("localhost", 6600)
    update_playlist(client=c)

    form = PlaylistVoteForm(request.POST or None)
    if not form.is_valid():
        for error in form.errors:
            messages.add_message(
                request, messages.ERROR,
                "{0}".format(form.errors[error][0])
            )
        return redirect(reverse(playlist))
    filename = form.cleaned_data['filename']

    pl = c.playlistid()
    track = get_track(filename, in_playlist=True, client=c)

    # track not in playlist
    if not track:
        return redirect(reverse(playlist))

    song_obj = get_song(filename, track['artist'], track['title'])
    pv = PlaylistVote(song=song_obj, value=+1 if up else -1)
    pv.save()

    if up:
        voted_text = "Voted up: {artist} - {title}"
    else:
        voted_text = "Voted down: {artist} - {title}"

    messages.add_message(
        request, messages.INFO, voted_text.format(
            artist=track.get("artist", "unknown artist"),
            title=track.get("title", "unknown title")
        )
    )

    votes = get_votes()
    song_votes = votes.get(filename, 0)
    songid = int(track['id'])
    pos = int(track['pos'])
    movepos = None

    # remove, if there are enough negative votes
    if song_votes <= REMOVE_FROM_PLAYLIST_VOTES:
        c.delete(pos)
        update_playlist(client=c)
        remove_text = "removed: {artist} - {title}"
        messages.add_message(
            request, messages.INFO, remove_text.format(
                artist=track.get("artist", "unknown artist"),
                title=track.get("title", "unknown title")
            )
        )
    elif up:
        # pos -1 .. 1 (never move before the first (playing) song)
        for plpos in xrange(pos-1, 0, -1):
            pl[plpos]['file'] = to_unicode(pl[plpos]['file'])
            if song_votes - MIN_MOVE_DIFFERENCE \
               >= votes.get(pl[plpos]['file'], 0):
                    movepos = plpos
    else:
        # pos+1 .. end
        for plpos in xrange(pos+1, len(pl)):
            pl[plpos]['file'] = to_unicode(pl[plpos]['file'])
            if song_votes + MIN_MOVE_DIFFERENCE \
               <= votes.get(pl[plpos]['file'], 0):
                    movepos = plpos
            else:
                break

    if movepos is not None:
        c.moveid(songid, movepos)
        if up:
            voted_text = "Moved up: {artist} - {title}"
        else:
            voted_text = "Moved down: {artist} - {title}"
        messages.add_message(
            request, messages.INFO, voted_text.format(
                artist=track.get("artist", "unknown artist"),
                title=track.get("title", "unknown title")
            )
        )

    c.disconnect()
    return redirect(reverse(playlist))
开发者ID:allo-,项目名称:mpdsongvote,代码行数:89,代码来源:views.py

示例7: Ajax

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import delete [as 别名]

#.........这里部分代码省略.........

    def ajax_mpd_add_dir(self, args):
        try:
            path = args.get('p')
        except ValueError:
            return
        path = re.sub(ur"/+", "/", path.rstrip('/'))
        rows = self.get_songs(args, path)
        files = [ os.path.join(r['path'], r['filename']) for r in rows ]

        try:
            pos,num  = mpdplay.main(files, self.con_id)
        except SocketError:
            return "Error: cannot connect to MPD"

        return "%d songs added at position %d" % (int(num), int(pos))

    def ajax_mpd_addstream(self, args):
        try:
            i = args.get('i')
        except ValueError:
            return "Missing parameter"
        try:
            url=self.config['streams'][i]['url'];
        except KeyError:
            return "Unknown stream"
        self.mpd_connect()
        self.client.add(url)
        status = self.client.status()
        if status['state'] == 'stop':
            self.client.play(int(status['playlistlength'])-1)
        return "Stream added at position %s" % status['playlistlength']

    def ajax_mpd_delete(self, args):
        try:
            i = int(args.get('i'))
        except ValueError:
            return "Unknown song"
        self.mpd_connect()
        self.client.delete(i)
        return "Song deleted"

    def ajax_mpd_skipto(self, args):
        try:
            i = int(args.get('i'))
        except ValueError:
            return "Unknown song"
        self.mpd_connect()
        self.client.play(i)
        st = self.get_state()
        return "Playback %s" % st

    def ajax_mpd_play(self, args):
        self.mpd_connect()
        self.client.play()
        st = self.get_state()
        return "Playback %s" % st

    def ajax_mpd_stop(self, args):
        self.mpd_connect()
        self.client.stop()
        st = self.get_state()
        return "Playback %s" % st

    def ajax_mpd_pause(self, args):
        self.mpd_connect()
开发者ID:tinuzz,项目名称:traxx,代码行数:70,代码来源:traxxjax.py


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