如果没有价值,别做什么

时间:2013-02-09 01:41:01

标签: python xbmc

这里是代码

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)并且它使代码崩溃。我怎么能只在有东西的时候发送网址。我尝试在网上搜索但没有任何成功 谢谢 麦克

1 个答案:

答案 0 :(得分:1)

变化:

if music_title != music_title1:

为:

if music_title.strip() and music_title != music_title1: