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


Python MPDClient.consume方法代码示例

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


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

示例1: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
class MPDCli:
    def __init__(self, ipaddress):
        self.client = MPDClient()
        self.client.timeout = 10
        self.client.idletimeout = None
        self.client.connect(ipaddress, 6600)
        self.client.consume(0)

        self.ip = ipaddress

    def close(self):
        self.client.close()
        self.client.disconnect()

    def __tryConnect(self):
        try:
            self.client.update()
        except ConnectionError:
            self.client.connect(self.ip, 6600)
            self.client.update()

    def getNowPlaying(self):
        self.__tryConnect()
        return self.client.currentsong()

    def getCurrentStatus(self):
        self.__tryConnect()
        return self.client.status()

    def play(self):
        self.__tryConnect()

        currentState = self.client.status()['state']

        if currentState == 'stop':
            self.client.play(int(self.client.status()['song']))
        else:
            self.client.pause()

        return self.client.status()

    def stop(self):
        self.__tryConnect()
        self.client.stop()
        return self.client.status()

    def prev(self):
        self.__tryConnect()
        self.client.previous()
        return self.client.status()

    def next(self):
        self.__tryConnect()
        self.client.next()
        return self.client.status()

    def idle(self):
        self.__tryConnect()
        self.client.idle()
开发者ID:mikdsouza,项目名称:PyPiMPD,代码行数:61,代码来源:MPDC.py

示例2: drawSongs

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
def drawSongs(stdscr):
	logging.debug("Drawing Songs" + "\n")
	client = MPDClient()               # create client object
	client.timeout = 10                # network timeout in seconds (floats allowed), default: None
	client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
	client.connect("localhost", 6600)  # connect to localhost:6600
	client.consume(1)

	if x=='blank':
		blankLine="                                                                                                                                                                                     "

		# print("Max Height", maxHeight)
		# print("Max Width", maxWidth)
		#Clear Song lines
		stdscr.move(maxHeight-2,0)
		stdscr.clrtoeol()
		stdscr.move(maxHeight-3,0)
		stdscr.clrtoeol()
		# stdscr.addstr(maxHeight-2,0,blankLine[:maxWidth-5])
		# stdscr.addstr(maxHeight-3,0,blankLine[:maxWidth-5])

		songList=[]
		try:
			currentPlaylist=client.playlistinfo()
			for playlistSong in currentPlaylist:
				songList.append(playlistSong['title'])
			stdscr.addstr(maxHeight-2,5,"Up Next: " + str(songList))
		except:
			pass

		try:
			currentSong=client.currentsong()
			stdscr.addstr(maxHeight-3,5,"Now Playing: " + str(currentSong['title']) + " (" + str(currentSong['artist']) + ")", curses.A_BOLD)
		except:
			stdscr.addstr(maxHeight-3,5,"Now Playing: ", curses.A_BOLD)
			pass

		client.close()                     # send the close command
		client.disconnect()
		stdscr.refresh()
开发者ID:DigitalHarborFoundation,项目名称:piJukebox,代码行数:42,代码来源:piJukebox.py

示例3: addSong

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
def addSong(stdscr, selectedSongNumber):
	client = MPDClient()               # create client object
	client.timeout = 10                # network timeout in seconds (floats allowed), default: None
	client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
	client.connect("localhost", 6600)  # connect to localhost:6600
	songs=client.listplaylistinfo("TC Jukebox")
	client.consume(1)

	if selectedSongNumber==30:
		selectedSong=songs[selectedSongNumber]
		songid=client.addid(selectedSong['file'], 0)
		client.play(0)
		drawRick(stdscr)
	elif selectedSongNumber==98:
		client.clear()

	elif selectedSongNumber<100:
		selectedSong=songs[selectedSongNumber]
		#stdscr.addstr(50,5,str(selectedSong['file']))
		client.add(selectedSong['file'])
		drawScreen(stdscr)

	client.close()                     # send the close command
	client.disconnect()
开发者ID:DigitalHarborFoundation,项目名称:piJukebox,代码行数:26,代码来源:piJukebox.py

示例4: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
class TestBookmark:
    
    def __init__(self):
        #Fill there
        self.testHost="localhost"
        self.testPort=6600
        self.testPass=None
        self.testMotif=""
        self.testField="file"
        #Test songs must last more than 30s
        self.song1="Jacques Brel/Album/11-Vierson.mp3"
        self.song2="Cream/Cream - 2000 - The Millenium Collection - [V2]/07 - Tales Of Brave Ulysses.mp3"

    #Before every test
    def setup(self):
        print "Connection to MPD .........",
        self.client=MPDClient()
        self.client.connect(self.testHost,self.testPort)
        if self.testPass:
            self.client.password(self.testPass)
        print "Done"
        self.client.clear()
        self.volume=self.client.status()['volume']
        self.client.setvol(0)
        self.client.consume(0)
        self.client.sticker_set('song', self.song1, 
                                'last_up', 0)
        self.client.sticker_set('song', self.song2, 
                                'last_up', 0)
        self.launch_bookmark()


    #After every test
    def teardown(self):
        self.client.clear()
        self.client.setvol(self.volume)
        print "Disconect MPD .............",
        self.client.disconnect() 
        print "Done"
        self.kill_bookmark()
       

    def launch_bookmark(self):
        self._thread=threading.Thread(None, MPDBookmark, None, (),
                                      {'host':self.testHost,
                                       'port':self.testPort,
                                       'password':self.testPass,
                                       'motif':self.testMotif,
                                       'field':self.testField})
        self._thread.start()
        print "Launch done"

    def kill_bookmark(self):
        self._thread._Thread__stop()
        print "kill done"

    def test_Version(self):
        print "Version :    ",
        print self.client.mpd_version
        #assert self.client.mpd_version=='0.18.0'
 
        
    def test_cold_start(self):
        print "cold start"
        self.client.add(self.song1)
        Ti=time.time()
        self.client.play()
        time.sleep(6)
        self.client.pause()
        Tf=time.time()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song',  self.song1, 'last_up'))
        real_time=Tf-Ti
        print "abs(read_time-real_time) ",
        print "read time :", read_time,
        print "real time :", real_time,
        print "  = ",abs(read_time-real_time)
        assert abs(read_time-6)<=2.
        assert abs(read_time-real_time)<=2.



    def test_pause(self):
        p1=5
        p2=2
        print "pause"
        self.client.add(self.song1)
        self.client.play()
        time.sleep(p1)
        self.client.pause()
        time.sleep(2)
        self.client.play()
        time.sleep(p2)
        self.client.stop()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song',  self.song1, 'last_up'))
        print read_time, "vs", p1+p2
        assert abs(read_time-(p1+p2))<=2.

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

示例5: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
client = MPDClient()

try:
    client.connect(host=HOST, port=PORT)
except SocketError:
    exit(1)

if PASSWORD:
    try:
        client.password(PASSWORD)
    except CommandError:
        exit(1)
client.clear()
client.random(1)
client.add(uri)
client.consume(0)
# client.crossfade(3)
# print(client.playlist())
client.play()
time.sleep(5)
'''
print(client.currentsong())
for x in range(1, 10):
    client.next()
    time.sleep(0.2)
    print(client.currentsong())
    time.sleep(5)
'''

while True:
    try:
开发者ID:bornhack,项目名称:baconfy,代码行数:33,代码来源:run.py

示例6: myMPD

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

#.........这里部分代码省略.........
                #                  "password commmand failed: %s" %
                #                  (self._host, e))
                #db.write_log_to_db_a(ac, "MPD-PW-Error: %s" % str(e), "x",
                #                             "write_also_to_console")
                return None

            # Catch all other possible errors
            except (MPDError, IOError) as e:
                #raise RunError("Could not connect to '%s': "
                #                  "error with password command: %s" %
                #                  (self._host, e))
                db.write_log_to_db_a(ac, "MPD-Error-2: %s" % str(e), "x",
                                             "write_also_to_console")
            return None

    def disconnect(self):
        # Try to tell MPD we're closing the connection first
        try:
            self._client.close()

        # If that fails, don't worry, just ignore it and disconnect
        except (MPDError, IOError):
            pass

        try:
            self._client.disconnect()

        # Disconnecting failed, so use a new client object instead
        # This should never happen.  If it does, something is seriously broken,
        # and the client object shouldn't be trusted to be re-used.
        except (MPDError, IOError):
            self._client = MPDClient()

    def exec_command(self, db, ac, command, value):
        """spread out exec commands"""
        result = None
        try:
            if command == "access":
                result = self.mpd_access(db, ac)
            if command == "play":
                result = self._client.play()
            if command == "update":
                result = self._client.update()
            if command == "song":
                result = self._client.currentsong()
            if command == "status":
                result = self._client.status()
            if command == "add":
                result = self._client.add(value)
            if command == "consume":
                result = self._client.consume(value)
            if command == "crossfade":
                result = self._client.crossfade(value)
            if command == "seek":
                result = self._client.seek(value)
            if command == "repeat":
                result = self._client.repeat(value)
            if command == "random":
                result = self._client.random(value)
            if command == "single":
                result = self._client.single(value)
            if command == "replay_gain_mode":
                result = self._client.replay_gain_mode(value)
            if command == "next":
                result = self._client.next()
            if command == "setvol":
                result = self._client.setvol(value)
            # via mpc-client
            if command == "crop":
                result = mpc_client(db, ac, "crop", value)
            if command == "vol":
                result = mpc_client(db, ac, "volume", value)
            # via os
            if command == "reload-1":
                result = run_cmd(db, ac, "killall", value)
            if command == "reload-2":
                result = run_cmd(db, ac, "mpd", value)
            return result

        # Couldn't get the current cmd, so try reconnecting and retrying
        except (MPDError, IOError) as e:
            # No error handling required here
            # Our disconnect function catches all exceptions, and therefore
            # should never raise any.
            error_msg = "MPD-Error-3: %s" % str(e)

            if value is not None:
                error_msg = error_msg + ", cmd: " + value
                #db.write_log_to_db_a(ac, "MPD-E-3 cmd-value: " + value, "x",
                #                             "write_also_to_console")
            if str(e) == "Not connected":
                error_msg = error_msg + ", try recon.:"
                db.write_log_to_db_a(ac, error_msg, "x",
                                                "write_also_to_console")
                self.connect(db, ac)
                self.exec_command(db, ac, command, value)
            else:
                db.write_log_to_db_a(ac, error_msg, "x",
                                                "write_also_to_console")
            return None
开发者ID:srb-fm,项目名称:admin-srb,代码行数:104,代码来源:lib_mpd.py

示例7: declarative_base

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, Column, Integer, String
import soundcloud
from mpd import MPDClient

Base = declarative_base()
yt = YouTube()
engine = create_engine('sqlite:///sj.db', echo=True)
Session = sessionmaker(bind=engine)

started = False
app = Flask(__name__)

media_player = MPDClient()
media_player.connect('localhost', 6600)
media_player.consume(1)
media_player.single(1)


class SongPlayer():

    def __init__(self, session, media_player, event):
        self.Session = session
        self.media_player = media_player
        self.playing = False
        self.current_url = None
        self.current_title = None
        self.current_ourl = None
        self.event = event

    def run(self):
开发者ID:Daegalus,项目名称:SocialJukebox,代码行数:33,代码来源:social_jukebox.py

示例8: MusicPlayer

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
class MusicPlayer(Action):
    """MusicPlayer for Alfred"""
    def __init__(self, cfg):
        super(MusicPlayer, self).__init__(cfg)
        self.triggers = ["music","audio"]
        self.mpd = MPDClient()
        self.mpd.connect("localhost", "6600")
        self.mpd.consume(0)

    def _do_update(self, command):
        self.mpd.update()

    def _do_list(self, command):
        llista = self.mpd.list('file')
        print llista
        if len(llista) > 0:
            return "\n".join(llista)
        else:
            return "Empty List SIR"

    def _do_add(self, command):
        song = " ".join(command[1:])
        self.mpd.add(song)
        return "Song %s Added SIR" % (song)

    def _do_queue(self,command):
        return "list: %s" % (self.mpd.playlist())

    def _do_clear(self, command):
        self.mpd.clear()
        return "Clear Done SIR"

    def _do_next(self, command):
        self.mpd.next()
        return "Next Song Done SIR"

    def _do_previous(self, command):
        self.mpd.previous()
        return "Previous Song Done SIR"

    def _do_pause(self, command):
        self.mpd.pause()
        return "Music Paused SIR"

    def _do_shuffle(self, command):
        self.mpd.shuffle()
        return "Music shuffled SIR"

    def _do_repeat(self, command):
        try:
            if command[1] == "on":
                self.mpd.repeat(1)
                return "Repeat Set On SIR"
            elif command[1] == "off":
                self.mpd.repeat(0)
                return "Repeat Set Off SIR"
            else:
                return "Error SIR"
        except:
            return "Error SIR"

    def _do_play(self, command):
        try:
            songpos = command[1]
            self.mpd.play(int(songpos))
            return "Playing %s Song Done SIR" % (songpos)
        except:
            self.mpd.play()
            return "Music Playing SIR"

    def _do_stop(self, command):
        self.mpd.stop()
        return "Music Stoped SIR"

    def do(self, command):
        print "Will", " ".join(command), "music"
        print command
        if command[0] == "update":
            self._do_update(command)
        elif command[0] == "list":
            return self._do_list(command)
        elif command[0] == "add":
            return self._do_add(command)
        elif command[0] == "queue":
            return self._do_queue(command)
        elif command[0] == "play":
            return self._do_play(command)
        elif command[0] == "stop":
            return self._do_stop(command)
        elif command[0] == "clear":
            return self._do_clear(command)
        elif command[0] == "next":
            return self._do_next(command)
        elif command[0] == "previous":
            return self._do_previous(command)
        elif command[0] == "pause":
            return self._do_pause(command)
        elif command[0] == "repeat":
            return self._do_repeat(command)
        elif command[0] == "shuffle":
#.........这里部分代码省略.........
开发者ID:Costar93,项目名称:Alfred,代码行数:103,代码来源:MusicPlayer.py

示例9: delete_event

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

#.........这里部分代码省略.........
        elif self.artist == True:
            artists = self.mclient.list("artist")
            artists.sort()
            self.tree.clear()
            for a in artists:
                if a != "":
                    self.tree.append([a])
                if self.hasFormer == True:
                    self.rbox.set_cursor(str(self.lartist), focus_column=None)
                    self.rbox.scroll_to_cell(str(lartist), column=None)
            self.rbox.scroll_to_cell('0', column=None)
        elif self.album == True:
            if self.nItr != None:
                #self.curartist = self.tree.get_value(self.nItr, 0)
                self.curartist = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
            albums = self.mclient.list("album", self.curartist)
            self.tree.clear()
            for al in albums:
                if al != "":
                    self.tree.append([al])
            self.rbox.scroll_to_cell('0', column=None)
        elif self.tracks == True:
            if self.nItr != None:
                #self.curalbum = self.tree.get_value(self.nItr, 0)
                self.curalbum = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
            tracks = self.mclient.find("album", self.curalbum)
            self.tree.clear()
            for t in tracks:
                self.tree.append([t['title']])
            self.rbox.scroll_to_cell('0', column=None)
        elif self.options == True:
            self.tree.clear()
            options = self.mclient.status()
            if options['consume'] == '0':
                self.tree.append(["Toggle consume [off]"])
            else:
                self.tree.append(["Toggle consume [on]"])
            if options['repeat'] == '0':
                self.tree.append(["Toggle repeat [off]"])
            else:
                self.tree.append(["Toggle repeat [on]"])
            if options['random'] == '0':
                self.tree.append(["Toggle random [off]"])
            else:
                self.tree.append(["Toggle random [on]"])
            if options['single'] == '0':
                self.tree.append(["Toggle single [off]"])
            else:
                self.tree.append(["Toggle single [on]"])
            self.rbox.scroll_to_cell('0', column=None)
        size = self.window.get_default_size()
        self.window.resize(size[0], size[1]+50)
        self.lbox.hide()
        self.scrollbox.show()
        self.window.set_focus(self.rbox)
        self.nItr = self.tree.get_iter_root()


    def mpdCmd(self):
        if self.current == True:
            songTitle = self.tree.get_value(self.tree.get_iter_from_string(str(self.rbox.get_cursor()[0][0])), 0)
            songTitle = songTitle.split("\t")[0]
            songid = self.list[songTitle]
            self.mclient.playid(songid)
            self.music = False
            #self.mclient.disconnect()
开发者ID:vincekd,项目名称:Pilaunch,代码行数:70,代码来源:pilaunch.py

示例10: Flask

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
from flask import Flask
app = Flask(__name__)
from app import views
from mpd import MPDClient

c = MPDClient()
c.timeout = 10
c.idletimeout = None
c.connect("localhost",6600)
c.random(0)
c.repeat(0)
c.consume(1)
#c.setvol(100)
c.close()   
开发者ID:ayypot,项目名称:ayydio,代码行数:16,代码来源:__init__.py

示例11: Controller

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
class Controller(object):
    class Mode:
        NONE = 0
        QUEUE = 1
        RANDOM = 2

    def __init__(self, host="/run/mpd/socket"):
        self.cli = MPDClient()
        self.cli.timeout = 10
        self.cli.idletimeout = None
        self.cli.connect(host, 0)
        log.info("Controller connected to MPD server version %s" % self.cli.mpd_version)

        self.mode = Controller.Mode.NONE
        self.switch_mode(Controller.Mode.RANDOM)

    def add_song(self, song):
        self.cli.add(song.as_mpd())

    def add_playlist(self, playlist):
        map(self.cli.add, playlist.as_mpd())

    def switch_mode(self, mode):
        self.mode = Controller.Mode.RANDOM

        if mode == Controller.Mode.RANDOM:
            self.cli.consume(0)
            self.cli.random(1)
            self.cli.repeat(1)
            self.cli.single(0)
            self.cli.clear()

            # Load up a ton of random songs
            playlist = Song.as_mpd_playlist(Song.select())
            map(self.cli.add, playlist)

        if mode == Controller.Mode.QUEUE:
            self.cli.consume(1)
            self.cli.random(0)
            self.cli.repeat(0)
            self.cli.single(0)
            self.cli.clear()

    def status(self):
      current_song = self.cli.currentsong()
      status = self.cli.status().items() + current_song.items()
      if 'title' in current_song:
          try:
              s = Song.get(Song.title == current_song['title'])
              status += s.to_dict().items()
          except Song.DoesNotExist: pass

      status = dict(status)
      status['playlist'] = self.cli.playlistinfo()
      return status

    def play(self):
      self.cli.play()

    def pause(self):
      self.cli.pause()

    def stop(self):
      self.cli.stop()

    def previous(self):
      self.cli.previous()

    def next(self):
      self.cli.next()


    def seek(self, ts):
      self.cli.seekcur(ts);
开发者ID:b1naryth1ef,项目名称:juicebox,代码行数:76,代码来源:controller.py

示例12: drawScreen

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
def drawScreen(stdscr):
	logging.debug("Drawing Screen\n")
	global maxHeight
	global maxWidth

	if x=='blank':
		stdscr.erase()

		client = MPDClient()               # create client object
		client.timeout = 10                # network timeout in seconds (floats allowed), default: None
		client.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
		client.connect("localhost", 6600)  # connect to localhost:6600
		client.consume(1)

		songs=client.listplaylistinfo(playlistName) # print result of the command find playlist

		stdscr.addstr(0,35," _______   __    __   _______           __   __    __   __  ___  _______    .______     ______   ___   ___ ")
		stdscr.addstr(1,35,"|       \ |  |  |  | |   ____|         |  | |  |  |  | |  |/  / |   ____|   |   _  \   /  __  \  \  \ /  / ")
		stdscr.addstr(2,35,"|  .--.  ||  |__|  | |  |__            |  | |  |  |  | |  '  /  |  |__      |  |_)  | |  |  |  |  \  V  /  ")
		stdscr.addstr(3,35,"|  |  |  ||   __   | |   __|     .--.  |  | |  |  |  | |    <   |   __|     |   _  <  |  |  |  |   >   <   ")
		stdscr.addstr(4,35,"|  '--'  ||  |  |  | |  |        |  `--'  | |  `--'  | |  .  \  |  |____    |  |_)  | |  `--'  |  /  .  \  ")
		stdscr.addstr(5,35,"|_______/ |__|  |__| |__|         \______/   \______/  |__|\__\ |_______|   |______/   \______/  /__/ \__\ ")

		curses.echo()            # Enable echoing of characters
		stdscr.addstr(2,3, "Enter 2 Digit Song Number: ")

		rectangle(stdscr, 1,0, 5, 30)


		maxHeight, maxWidth =stdscr.getmaxyx()

		colCount=1
		rowCount=1
		yStart=6
		xStart=2
		maxRows= ((maxHeight-5)) - yStart
		maxStringLength=(maxWidth/2 - 13) / 2

		songStart=0

		for song in songs:
			songStart+=1

			artist= song['artist']
			artist= (artist[:maxStringLength] + '...') if len(artist) > maxStringLength else artist

			songTitle=song['title']
			songTitle=(songTitle[:maxStringLength] + '...') if len(songTitle) > maxStringLength else songTitle

			if(rowCount < maxRows):
				# stdscr.addstr(yStart+rowCount,xStart,str(rowCount) + " of " + str(maxRows))
				# logging.debug(str(rowCount) + " of " + str(maxRows) + "\n")
				# logging.debug(str(songStart).zfill(2) + ". " +  songTitle + " (" + artist + ")")
				stdscr.addstr(yStart+rowCount,xStart,str(songStart).zfill(2) + ". " +  songTitle + " (" + artist + ")" )

			#stdscr.addstr(yStart+rowCount,xStart,str(song))

			rowCount+=1
			if rowCount > maxRows :
				rowCount=1
				xStart=maxWidth/2

		status=client.status()
		if status['state']=="stop":
			client.play()

		client.close()                     # send the close command
		client.disconnect()

		stdscr.refresh()

		drawSongs(stdscr)
开发者ID:DigitalHarborFoundation,项目名称:piJukebox,代码行数:74,代码来源:piJukebox.py

示例13: baconfyclient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
class baconfyclient(object):
    """docstring for  baconfyclient"""
    def __init__(self):
        super(baconfyclient, self).__init__()
        # self.arg = arg
        self.connect()

    def play(self):
        self.client.play()

    def chunks(self, l, n):
        n = max(1, n)
        return [l[i:i + n] for i in range(0, len(l), n)]

    def pause(self):
        self.client.pause()

    def prev(self):
        self.client.previous()

    def init1337(self):
        self.connect()
        self.client.clear()
        self.client.add('spotify:user:b584371:playlist:4PaYAhJ2xibbm5q69yXgI7')
        #self.client.add('spotify:user:b584371:playlist:06nxCXR3zlRAxwqAz6FfaD')

    def playlist(self):
        playlist = self.client.playlist()
        playlistd = self.chunks(playlist,11)
        #pprint.pprint(playlistd)
        playlistan = {}
        for lista in playlistd:
            #print(lista)
            playlistan[str(lista[0]).strip(' ')] = {
                'file': str(lista[0]).strip(' '),
                'time': int(str(lista[1]).strip(' ')),
                'artist': str(lista[2]).strip(' '),
                'album': str(lista[3]).strip(' '),
                'title': str(lista[4]).strip(' '),
                'date': int(str(lista[5]).strip(' ')),
                'track': str(lista[6]).strip(' '),
                'pos': int(str(lista[7]).strip(' ')),
                'id': int(str(lista[8]).strip(' ')),
                'albumartist': str(lista[9]).strip(' '),
                'x-albumuri': str(lista[10]).strip(' '),
            }
            #print(type(lista))
            # file, time, artist, album, title, date, track, ppos, pid, albumartist, albumuri = map(lambda x: 11, lista)
            #print(map(lambda x: 11, lista))
        # pprint.pprint(playlistan)
        # print(json.dumps(playlist))
        return(playlistan)

    def next(self):
        self.client.next()

    def seek(self):
        return self.client.status()

    def status(self):
        return self.client.status()

    def percentage(self, part, whole):
        return 100 * float(part)/float(whole)

    def connect(self):
        self.client = MPDClient()

        try:
            self.client.connect(host=HOST, port=PORT)
        except SocketError:
            exit(1)

        if PASSWORD:
            try:
                self.client.password(PASSWORD)
            except CommandError:
                exit(1)
        self.client.consume(0)
        self.client.random(1)

    def sec2min(self, seconds):
        res = time.strftime('%M:%S', time.gmtime(int(seconds)))
        return res

    def currentsong(self):
        # print('test')
        songInfo = self.client.currentsong()
        status = self.client.status()
        # print(type(songInfo))
        # print(songInfo['time'])
        # return('Currently Playing: %s - %s [%s] (%s)' % (
        #     songInfo['artist'],
        #     songInfo['title'],
        #     self.sec2min(songInfo['time']),
        #     songInfo['album']
        # ))
        return {'song': songInfo, 'status': status}

    def nextsong(self):
#.........这里部分代码省略.........
开发者ID:bornhack,项目名称:baconfy,代码行数:103,代码来源:baconfy.py

示例14: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import consume [as 别名]
app.debug = True

MUISC_ENABLED = True

VALID_MODES = xmasd.MODES
#["red_green_jump", "red_green_fade", "red_green_trail", "rainbow", "rainbow2", "red_blue_fade", "silver_twinkle"]

context = zmq.Context()
QUEUE = context.socket(zmq.PUB)

# connect to music deamon
music = MPDClient()               # create MPD client object
music.timeout = 10                # network timeout in seconds (floats allowed), default: None
music.idletimeout = None          # timeout for fetching the result of the idle command is handled seperately, default: None
music.connect("localhost", 6600)  # connect to localhost:6600
music.consume(1)  # make sure items fall out of queue when finished

# status file
statusfile = open('xmasd-status', 'r')

@app.route('/static/<path:path>')
def static_proxy(path):
    # send_static_file will guess the correct MIME type
    return app.send_static_file(os.path.join('static', path))

@app.route("/")
def default():
    #return "HELLO"
    return render_template('xmas.html')

@app.route("/quit")
开发者ID:danseagrave,项目名称:dans-xmas-lights,代码行数:33,代码来源:xmasweb.py


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