0

这里的代码

import subprocess,os
import xbmcgui
import xbmc
import xbmcaddon
import urllib2
import re
import string

#Initialize value for ref.
menu          = 0
video         = 0
audio         = 0
music_title   = 0
music_title1  = 1

#Initialize ADDON
settings = xbmcaddon.Addon(id='micasaverde.addon')

#Initialize ADDON INFORMATION
ip  =  settings.getSetting( "vera_ip" )
dev  =  settings.getSetting( "vera_dev" )

while (not xbmc.abortRequested):
    win   = (xbmcgui.getCurrentWindowId())

    if xbmc.Player().isPlayingAudio():
        tag = xbmc.Player().getMusicInfoTag()
        music_title = tag.getTitle()
        music_title = music_title.replace(' ', '_')
        if music_title != music_title1:
            urllib2('http://%s:3480/data_request?id=variableset&DeviceNum=%s&serviceId=urn:upnp-org:serviceId:XBMCState1&Variable=IdleTime&Value=%s' % (ip, dev, music_title))
        music_title1 = music_title

问题是它有时会发送命令,但在 url 的末尾没有值(music_title),它会使代码崩溃。只有在里面有东西的情况下,我怎么能发送 url。我尝试在网上搜索但没有任何成功谢谢 Mike

4

1 回答 1

1

改变:

if music_title != music_title1:

至:

if music_title.strip() and music_title != music_title1:
于 2013-02-09T02:01:55.197 回答