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


Python SoCo.get_current_track_info方法代码示例

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


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

示例1: say

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
def say(text):
    ok, file_name =  text2mp3(text, PATH, LANGUAGE)
    if ok:
        zp = SoCo(IP)
        cur_info = zp.get_current_track_info()
        state = zp.get_current_transport_info()
        zp.play_uri("http://{0}:5000/static/speech.mp3".format(LAN_IP))
        if (state['current_transport_state'] == 'PLAYING'):
            audio = MP3("./static/speech.mp3")
            speech_info = zp.get_current_track_info()
            duration = speech_info['duration']
            Timer(audio.info.length, resume_queue, (zp, cur_info)).start()
    return "OK!"
开发者ID:r0stig,项目名称:say,代码行数:15,代码来源:server.py

示例2: now_playing

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
	def now_playing(self):
		my_zone = SoCo('192.168.86.225')
		
		status = my_zone.get_current_transport_info()
		
		track = my_zone.get_current_track_info()
		
		artist = ''
		title = ''
		if(track['artist'] == '' and track['title'] == ''):
			return "Stopped - Playlist Empty"
		elif (track['artist'] == '' and track['title'] != ''):
			title = track['title']
			parts = title.split('|')
			for part in parts:
				if(part[:7] == 'ARTIST '):
					artist = part[7:]
				elif(part[:6] == 'TITLE '):
					title = part[6:]
		else:
			artist = track['artist']
			title = track['title']
			
		state = "Now Playing: "
		if(status['current_transport_state'] == 'STOPPED'):
			state = "Up Next"
			
		return state + artist + ' - ' + title
开发者ID:bgriffiths,项目名称:ledsign,代码行数:30,代码来源:sonos.py

示例3: Sonos

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
class Sonos(AbstractJob):

    def __init__(self, conf):
        self.interval = conf['interval']
        self.sonos = SoCo(conf['ip'])

    def get(self):
        zone_name = self.sonos.get_speaker_info()['zone_name']
        np = self.sonos.get_current_track_info()

        current_track = np if np['playlist_position'] != '0' else None
        queue = self.sonos.get_queue(int(np['playlist_position']), 1)
        next_item = queue.pop() if len(queue) > 0 else None
        next_track = {}
        if next_item is not None:
            next_track = {
                'artist': next_item.creator,
                'title': next_item.title,
                'album': next_item.album
            }

        state = self.sonos.get_current_transport_info()[
            'current_transport_state']

        return {
            'room': zone_name,
            'state': state,
            'current': current_track,
            'next': next_track
        }
开发者ID:COLABORATI,项目名称:jarvis2,代码行数:32,代码来源:sonos.py

示例4: GET

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
	def GET(self, ipadress):
		web.header('Content-Type', 'application/json')
		web.header('Access-Control-Allow-Origin', '*')
		web.header('Access-Control-Allow-Credentials', 'true')

		sonos = SoCo(ipadress)
		track = sonos.get_current_track_info()

		return json.dumps(track)
开发者ID:oyvindmal,项目名称:DigitalHomeWebApi,代码行数:11,代码来源:code.py

示例5: GET

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
	def GET(self):
		web.header('Access-Control-Allow-Origin', '*')
                web.header('Access-Control-Allow-Credentials', 'true')

		data = web.input(uri="no", player="no")
		sonos = SoCo('192.168.1.105')
                sonos.play_uri(data.uri)
		track = sonos.get_current_track_info()
                return track['title'] + " - " + data.player
开发者ID:oyvindmal,项目名称:SocoWebService,代码行数:11,代码来源:WebService.py

示例6: index

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
    def index(self):
        """sonos_menu, menu om commando's aan sonos te geven en info op te halen
        """

        # verbinding maken met sonos
        sonos = SoCo(COORDINATOR)

        # wat speelt er nu, als het nummer niet uit playlist komt, is current_track niet gevuld
        current_song = sonos.get_current_track_info()
        current_track = int(current_song['playlist_position'])

        # haal queue uit database op
        self._db = MyDB()
        query = """select * from queue order by queue_id"""
        records = self._db.dbGetData(query)
        # print 'queue records', records

        # haal pagina op
        h = queuebeheer_temp.sonos_playmenu(records, sonos, current_track)

        return h
开发者ID:dirk2011,项目名称:mymc_git,代码行数:23,代码来源:queuebeheer.py

示例7: SoCo

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
if __name__ == '__main__':
    if (len(sys.argv) != 3):
        print "Usage: sonoshell.py [speaker's IP] [cmd]"
        print ""
        print "Valid commands: play, pause, stop, next, previous, current, and partymode"
        sys.exit()

    speaker_ip = sys.argv[1]
    cmd = sys.argv[2].lower()

    sonos = SoCo(speaker_ip)

    if (cmd == 'partymode'):
        print sonos.partymode()
    elif (cmd == 'play'):
        print sonos.play()
    elif (cmd == 'pause'):
        print sonos.pause()
    elif (cmd == 'stop'):
        print sonos.stop()
    elif (cmd == 'next'):
        print sonos.next()
    elif (cmd == 'previous'):
        print sonos.previous()
    elif (cmd == 'current'):
        track = sonos.get_current_track_info()

        print 'Current track: ' + track['artist'] + ' - ' + track['title'] + '. From album ' + track['album'] + '. This is track number ' + track['playlist_position'] + ' in the playlist. It is ' + track['duration'] + ' minutes long.'
    else:
        print "Valid commands: play, pause, stop, next, previous, current, and partymode"
开发者ID:DonGar,项目名称:SoCo,代码行数:32,代码来源:sonoshell.py

示例8: printlog

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
hipChatRoom = None
currentTrackInfo = None

needToQuit = False

##list all available hipchat rooms
##and connect to the one specified in config.txt
for room in hipchat.rooms()['items']:
    printlog(room['name'])
    if(room['name'] == hipChatRoomName):
        hipChatRoom = room
printlog('joined room: ' + hipChatRoom['name'])

while not needToQuit:
    try:
        newTrackInfo = zone.get_current_track_info()
##        only procede if the player is playing
        if zone.get_current_transport_info()['current_transport_state'] == 'PLAYING':
##              if the current track exists and is different from the last we found procede
            if(currentTrackInfo == None or newTrackInfo['title'] != currentTrackInfo['title']):
                #format a cool hipchat message containing a search link an album image and the track info
                #put together a google search url
                searchStr = unicode(newTrackInfo['title']) +' ' + unicode(newTrackInfo['artist']) + ' ' +unicode(newTrackInfo['album'])
                searchStr = searchStr.replace(' ','+')
                printlog(searchStr)
                
                noteStr = '<a href="http://www.google.com/search?q='+searchStr + '">'
                #only include the album image if this track has a different album from the last one
                if(currentTrackInfo == None or newTrackInfo['album'] != currentTrackInfo['album']):
                    noteStr += '<img style="float:left; width:50px;height:50px;" src="' + unicode(newTrackInfo['album_art'])+ '">'
                noteStr += '<p >'
开发者ID:BenVanCitters,项目名称:Sonos-HipChat,代码行数:33,代码来源:roomSonos.py

示例9: connect

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]
class SonosController:

    _device = None

    def connect(self):
	ips = []
	while (len(ips) == 0):
	    print "No Sonos found"
	    sonos_devices = SonosDiscovery()
	    ips = sonos_devices.get_speaker_ips()
	
        print "Found {0} device(s)".format(len(ips))

	for ip in ips:
	    self._device = SoCo(ip)
	    zone_name = self._device.get_speaker_info()['zone_name']
	    print "IP of {0} is {1}".format(zone_name, ip)

    def get_current_song(self):
	if self._device == None:
	    self.connect()

	now_playing = self._device.get_current_track_info()
	return now_playing

    def play_pandora_station(self, code):
	if self._device == None:
	    self.connect()
	
	PLAY_STATION_ACTION ='"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"'
	TRANSPORT_ENDPOINT = '/MediaRenderer/AVTransport/Control'
	JOIN_RESPONSE = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetAVTransportURIResponse xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"></u:SetAVTransportURIResponse></s:Body></s:Envelope>'
	PLAY_STATION_BODY_TEMPLATE ='"<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>pndrradio:{music_service_station_id}</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>'
	
	body = PLAY_STATION_BODY_TEMPLATE.format(music_service_station_id = code)
	response = self._device.send_command(TRANSPORT_ENDPOINT, PLAY_STATION_ACTION, body)
	
	if (response == JOIN_RESPONSE):
	    self._device.play()
	    return True
	else:
	    return self._device.parse_error(response)

    def pause(self):
	if self._device == None:
	    connect()

	try:
	    self._device.pause()
	except:
            print "Error trying to pause music: there is probably nothing playing right now."
	    return False
	
	return True

    def get_volume(self):
        if self._device == None:
            self.connect()

        current_volume = self._device.volume()
        return current_volume

    def set_volume(self, volume):
        if self._device == None:
            self.connect()

        result = self._device.volume(volume)
        return result
开发者ID:pierreca,项目名称:Tyler,代码行数:70,代码来源:sonos.py

示例10: __init__

# 需要导入模块: from soco import SoCo [as 别名]
# 或者: from soco.SoCo import get_current_track_info [as 别名]

#.........这里部分代码省略.........
                return
            self.sonos.play_from_queue(queue_pos)
            self.sonos.seek(self.track_info_to_return_to["position"])
        if self.state_info_to_return_to["current_transport_state"] == "PAUSED_PLAYBACK" or self.state_info_to_return_to["current_transport_state"] == "STOPPED":
            self.changeState(SONOS_RESTORE_PEND)
            self.time_out = 3
            self.retry_count = 2
        else:
            self.completed()

    def abort(self):
        self.logState("Aborting")
        self.play_pending = False
        self.abort_pending = True
        self.restore()

    def completed(self):
        if self.abort_pending:
            self.logState("Finished - ABORTED")
        else:
            self.logState("Finished - OK")
        self.play_pending = False
        self.abort_pending = False
        self.changeState(SONOS_IDLE)

    def logState(self, info):
        if self.state_var == SONOS_IDLE:
            if self.logged_idle:
                return
            self.logged_idle = True
        else:
            self.logged_idle = False
        transp_info = self.sonos.get_current_transport_info()
        track_info = self.sonos.get_current_track_info()
        print ("StateNow: ", self.state_var, " PrevState", self.prev_state, " TimeOut: ", self.time_out, " Elapsed: ", self.elapsedTime(), "RetryCount: ", self.retry_count, " TranspState: ", transp_info["current_transport_state"], " PlaylistPos: ", track_info["playlist_position"], "Info: ", info)

    def handleState(self):
        # Handle idle
        if self.state_var == SONOS_IDLE:
            if self.play_pending:
                self.changeState(SONOS_PLAY_REQ)
            return
        # Get current state information from sonos unit
        transp_info = self.sonos.get_current_transport_info()
        track_info = self.sonos.get_current_track_info()
        cur_transp_state = transp_info['current_transport_state']
        self.logState("handleStateEntry")
        # Handle other states
        if self.state_var == SONOS_PLAY_REQ:
            self.vol_to_return_to = self.sonos.volume
            self.track_info_to_return_to = track_info
            self.state_info_to_return_to = transp_info
            self.retry_count = 2
            self.changeState(SONOS_PAUSE_TRY)
        elif self.state_var == SONOS_PAUSE_TRY:
            self.time_out = 10
            if cur_transp_state == "PLAYING":
                self.sonos.pause()
            self.changeState(SONOS_PAUSE_PEND)
        elif self.state_var == SONOS_PAUSE_PEND:
            if cur_transp_state == "PAUSED_PLAYBACK" or cur_transp_state == "STOPPED":
                self.changeState(SONOS_PLAY_START)
            elif cur_transp_state == "PLAYING":
                if self.elapsedTime() > self.time_out:
                    self.retry_count -= 1
                    if self.retry_count > 0:
开发者ID:robdobsn,项目名称:RdHomeServer,代码行数:70,代码来源:SonosDevice.py


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