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


Python MPDClient.addid方法代码示例

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


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

示例1: add_track

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import addid [as 别名]
def add_track(name):
	client = MPDClient()
	client.connect("localhost",6600)
	try:
		client.addid(name)
		response = True
	except:	
		response = False
	client.close()
	client.disconnect()
	return response
开发者ID:matveevfedor,项目名称:collective_player,代码行数:13,代码来源:add.py

示例2: MusicPlayer

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

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

    def _do_play(self, command):
        return self.mpd.play()

    def _do_add(self, command):
        canco = " ".join(command[1:])
        return self.mpd.addid(canco)

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

    def _do_songs(self, command):
        llista = self.mpd.list('file')
        print llista
        if len(llista) > 0:
            return '\n'.join(llista)
        else:
            return 'Llista buida'

    def do(self, command):
        print "Will play music ", " ".join(command)
        print command
        if command[0] == "update":
            self._do_update(command)
        elif command[0] == "songs":
            return self._do_songs(command)
        elif command[0] == "add":
            return self._do_add(command)
        elif command[0] == "play":
            return self._do_play(command)
        elif command[0] == "queue":
            return self._do_queue(command)
        else:
            return "Que?!?!?"


    def is_for_you(self, word):
        if word in self.triggers:
            return True
        return False
开发者ID:carlesm,项目名称:ambrosio,代码行数:52,代码来源:MusicPlayer.py

示例3: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import addid [as 别名]
class Player:
    
    def __init__(self, host="localhost", port=6600):
        self._host = host
        self._port = port
        self._client = MPDClient()
        
    def _connect(self):
        self._client.connect(self._host, self._port)
    
    def _disconnect(self):
        try:
            self._client.disconnect()           
        except:
            pass

    def _ensure__connection(self):
        try:
            self._client.ping()
        except (MPDError, ConnectionError, IOError):
            self._disconnect()
            self._connect()
        
    def play(self, stream):
        self._ensure__connection()
            
        songId = self._client.addid(stream, 0)
        self._client.playid(songId)
        
    def stop(self):
        self._ensure__connection()
        
        self._client.stop()
        
    def status(self):
        self._ensure__connection()
        
        return self._client.status()
        
    def currentsong(self):
        self._ensure__connection()
        
        return self._client.currentsong()
        
    def is_playing(self):
        status = self.status()
        
        return status['state'] == 'play'
开发者ID:n3rd,项目名称:StreamPi,代码行数:50,代码来源:Player.py

示例4: with_mpd

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import addid [as 别名]
def with_mpd(client, id, host, port):
    track = client.get('/tracks/{id}'.format(id=id))

    if track.streamable:
        stream_url = client.get(track.stream_url, allow_redirects=False)

        mpdcli = MPDClient()

        mpdcli.connect(host, port)
        ls = mpdcli.playlist()
        n = len(ls)
        id = mpdcli.addid(stream_url.location, n)
        mpdcli.addtagid(id, 'Title', track.title)
        mpdcli.addtagid(id, 'Artist', track.user['username'])

        mpdcli.close()
        mpdcli.disconnect()

        return stream_url
    else:
        return None
开发者ID:uemurax,项目名称:scc,代码行数:23,代码来源:play.py

示例5: addSong

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import addid [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

示例6: MPDWrapper

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import addid [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

示例7: __init__

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

	def __init__(self, db = '/home/pi/radiator/radiator.sqlite3'):
		
		self.conf		= {}
		self.stations	= []
		self.homeDir	= "/home/pi/radiator"	
		
		#DB SETUP
		self.db = sqlite3.connect(db)
		self.c = self.db.cursor()
		
		#GET CONFIG
		self.c.execute('SELECT key, value FROM conf')
		for row in self.c:
			self.conf[row[0]] = row[1]

		#MPD SETUP
		self.mpd = MPDClient()
		self.mpd.connect("/var/run/mpd/socket", 6600)
		
		#SET STATIONS
		self.c.execute('SELECT id, name, url FROM stations ORDER BY stations.id DESC')
		for row in self.c: 
			self.stations.append({'id': row[0], 'name': row[1], 'url': row[2]})

		if self.conf['stationsV'] != self.conf['stationsU'] or len(self.mpd.playlistinfo()) != len(self.stations):
			self.mpd.clear()
			for st in self.stations:
				print st['url']
				st['pl_id'] = self.mpd.addid(st['url'])

			self.c.execute("UPDATE conf SET value = '%s' WHERE key = 'stationsU'" % self.conf['stationsV'])
			self.db.commit()
		else:
			for st in self.stations:
				st['pl_id'] = self.getPlStationByUrl(st['url'])['id']

		#AUTO PLAY!
		self.play()

		#SET BUTTONS AND LED
		GPIO.setwarnings(False)
		GPIO.setmode(GPIO.BCM)
		#button[0] - pin, button[1] - last state
		self.buttons = [[18, 0], [23, 0], [24, 0]]
		self.LED = 4;
		GPIO.setup(self.LED,GPIO.OUT)
		GPIO.output(self.LED, False)
		for button in self.buttons:
			GPIO.setup(button[0],GPIO.IN)
		


	def pressed(self):
		for button in self.buttons:
			input = GPIO.input(button[0])
			if ((not button[1]) and input):
				pressed = button[0]
			else:
				pressed = False;
			
			button[1] = input
			time.sleep(0.05)
			if pressed:
				return pressed
		return False

	def play(self):
		self.mpd.play();

	def next(self):
		playlist = self.mpd.playlistinfo();
		if self.mpd.currentsong()['id'] == playlist[len(playlist) - 1]['id']:
			self.mpd.playid(playlist[0]['id'])
		else:
			self.mpd.next()

	def previous(self):
		playlist = self.mpd.playlistinfo();
		if self.mpd.currentsong()['id'] == playlist[0]['id']:
			self.mpd.playid(playlist[len(playlist) - 1]['id'])
		else:
			self.mpd.previous()


	def getStByPl_id(self, id):
		for st in self.stations:
			if st['pl_id'] == id:
				return st;
		return False

	def getPlStationByUrl(self, url):
		plStations = self.mpd.playlistinfo()
		for st in plStations:
			if st['file'] == url:
				return st;
		return False

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


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