本文整理汇总了Python中sickbeard.common.XML_NSMAP类的典型用法代码示例。如果您正苦于以下问题:Python XML_NSMAP类的具体用法?Python XML_NSMAP怎么用?Python XML_NSMAP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XML_NSMAP类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildNFOXML
def buildNFOXML(myShow):
'''
Build an etree.Element of the root node of an NFO file with the
data from `myShow`, a TVDB show object.
>>> from collections import defaultdict
>>> from xml.etree.cElementTree import tostring
>>> show = defaultdict(lambda: None, _actors=[])
>>> tostring(buildNFOXML(show))
'<tvshow xsd="http://www.w3.org/2001/XMLSchema" xsi="http://www.w3.org/2001/XMLSchema-instance"><title /><rating /><plot /><episodeguide><url /></episodeguide><mpaa /><id /><genre /><premiered /><studio /></tvshow>'
>>> show['seriesname'] = 'Peaches'
>>> tostring(buildNFOXML(show))
'<tvshow xsd="http://www.w3.org/2001/XMLSchema" xsi="http://www.w3.org/2001/XMLSchema-instance"><title>Peaches</title><rating /><plot /><episodeguide><url /></episodeguide><mpaa /><id /><genre /><premiered /><studio /></tvshow>'
>>> show['contentrating'] = 'PG'
>>> tostring(buildNFOXML(show))
'<tvshow xsd="http://www.w3.org/2001/XMLSchema" xsi="http://www.w3.org/2001/XMLSchema-instance"><title>Peaches</title><rating /><plot /><episodeguide><url /></episodeguide><mpaa>PG</mpaa><id /><genre /><premiered /><studio /></tvshow>'
>>> show['genre'] = 'Fruit|Edibles'
>>> tostring(buildNFOXML(show))
'<tvshow xsd="http://www.w3.org/2001/XMLSchema" xsi="http://www.w3.org/2001/XMLSchema-instance"><title>Peaches</title><rating /><plot /><episodeguide><url /></episodeguide><mpaa>PG</mpaa><id /><genre>Fruit / Edibles</genre><premiered /><studio /></tvshow>'
'''
tvNode = etree.Element( "tvshow" )
for ns in XML_NSMAP.keys():
tvNode.set(ns, XML_NSMAP[ns])
title = etree.SubElement( tvNode, "title" )
if myShow["seriesname"] != None:
title.text = myShow["seriesname"]
rating = etree.SubElement( tvNode, "rating" )
if myShow["rating"] != None:
rating.text = myShow["rating"]
plot = etree.SubElement( tvNode, "plot" )
if myShow["overview"] != None:
plot.text = myShow["overview"]
episodeguide = etree.SubElement( tvNode, "episodeguide" )
episodeguideurl = etree.SubElement( episodeguide, "url" )
if myShow["id"] != None:
showurl = sickbeard.TVDB_BASE_URL + '/series/' + myShow["id"] + '/all/en.zip'
episodeguideurl.text = showurl
mpaa = etree.SubElement( tvNode, "mpaa" )
if myShow["contentrating"] != None:
mpaa.text = myShow["contentrating"]
tvdbid = etree.SubElement( tvNode, "id" )
if myShow["id"] != None:
tvdbid.text = myShow["id"]
genre = etree.SubElement( tvNode, "genre" )
if myShow["genre"] != None:
genre.text = " / ".join([x for x in myShow["genre"].split('|') if x != ''])
premiered = etree.SubElement( tvNode, "premiered" )
if myShow["firstaired"] != None:
premiered.text = myShow["firstaired"]
studio = etree.SubElement( tvNode, "studio" )
if myShow["network"] != None:
studio.text = myShow["network"]
for actor in myShow['_actors']:
cur_actor = etree.SubElement( tvNode, "actor" )
cur_actor_name = etree.SubElement( cur_actor, "name" )
cur_actor_name.text = actor['name']
cur_actor_role = etree.SubElement( cur_actor, "role" )
cur_actor_role_text = actor['role']
if cur_actor_role_text != None:
cur_actor_role.text = cur_actor_role_text
cur_actor_thumb = etree.SubElement( cur_actor, "thumb" )
cur_actor_thumb_text = actor['image']
if cur_actor_thumb_text != None:
cur_actor_thumb.text = cur_actor_thumb_text
return tvNode
示例2: _show_data
def _show_data(self, show_obj):
"""
Creates an elementTree XML structure for an XBMC-style tvshow.nfo and
returns the resulting data object.
show_obj: a TVShow instance to create the NFO for
"""
show_ID = show_obj.tvdbid
tvdb_lang = show_obj.lang
# There's gotta be a better way of doing this but we don't wanna
# change the language value elsewhere
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if tvdb_lang and not tvdb_lang == 'en':
ltvdb_api_parms['language'] = tvdb_lang
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
tv_node = etree.Element("tvshow")
for ns in XML_NSMAP.keys():
tv_node.set(ns, XML_NSMAP[ns])
try:
myShow = t[int(show_ID)]
except tvdb_exceptions.tvdb_shownotfound:
logger.log(u"Unable to find show with id " + str(show_ID) + " on tvdb, skipping it", logger.ERROR)
raise
except tvdb_exceptions.tvdb_error:
logger.log(u"TVDB is down, can't use its data to add this show", logger.ERROR)
raise
# check for title and id
try:
if myShow["seriesname"] == None or myShow["seriesname"] == "" or myShow["id"] == None or myShow["id"] == "":
logger.log(u"Incomplete info for show with id " + str(show_ID) + " on tvdb, skipping it", logger.ERROR)
return False
except tvdb_exceptions.tvdb_attributenotfound:
logger.log(u"Incomplete info for show with id " + str(show_ID) + " on tvdb, skipping it", logger.ERROR)
return False
title = etree.SubElement(tv_node, "title")
if myShow["seriesname"] != None:
title.text = myShow["seriesname"]
rating = etree.SubElement(tv_node, "rating")
if myShow["rating"] != None:
rating.text = myShow["rating"]
plot = etree.SubElement(tv_node, "plot")
if myShow["overview"] != None:
plot.text = myShow["overview"]
episodeguide = etree.SubElement(tv_node, "episodeguide")
episodeguideurl = etree.SubElement( episodeguide, "url")
episodeguideurl2 = etree.SubElement(tv_node, "episodeguideurl")
if myShow["id"] != None:
showurl = sickbeard.TVDB_BASE_URL + '/series/' + myShow["id"] + '/all/en.zip'
episodeguideurl.text = showurl
episodeguideurl2.text = showurl
mpaa = etree.SubElement(tv_node, "mpaa")
if myShow["contentrating"] != None:
mpaa.text = myShow["contentrating"]
tvdbid = etree.SubElement(tv_node, "id")
if myShow["id"] != None:
tvdbid.text = myShow["id"]
genre = etree.SubElement(tv_node, "genre")
if myShow["genre"] != None:
genre.text = " / ".join([x for x in myShow["genre"].split('|') if x])
premiered = etree.SubElement(tv_node, "premiered")
if myShow["firstaired"] != None:
premiered.text = myShow["firstaired"]
studio = etree.SubElement(tv_node, "studio")
if myShow["network"] != None:
studio.text = myShow["network"]
for actor in myShow['_actors']:
cur_actor = etree.SubElement(tv_node, "actor")
cur_actor_name = etree.SubElement( cur_actor, "name")
cur_actor_name.text = actor['name']
cur_actor_role = etree.SubElement( cur_actor, "role")
cur_actor_role_text = actor['role']
if cur_actor_role_text != None:
cur_actor_role.text = cur_actor_role_text
cur_actor_thumb = etree.SubElement( cur_actor, "thumb")
cur_actor_thumb_text = actor['image']
#.........这里部分代码省略.........
示例3: len
try:
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
myShow = t[ep_obj.show.tvdbid]
except tvdb_exceptions.tvdb_shownotfound, e:
raise exceptions.ShowNotFoundException(e.message)
except tvdb_exceptions.tvdb_error, e:
logger.log(u"Unable to connect to TVDB while creating meta files - skipping - "+e.message.decode('utf-8'), logger.ERROR)
return
if len(eps_to_write) > 1:
rootNode = etree.Element( "xbmcmultiepisode" )
else:
rootNode = etree.Element( "episodedetails" )
# Set our namespace correctly
for ns in XML_NSMAP.keys():
rootNode.set(ns, XML_NSMAP[ns])
# write an NFO containing info for all matching episodes
for curEpToWrite in eps_to_write:
try:
myEp = myShow[curEpToWrite.season][curEpToWrite.episode]
except (tvdb_exceptions.tvdb_episodenotfound, tvdb_exceptions.tvdb_seasonnotfound):
logger.log(u"Unable to find episode " + str(curEpToWrite.season) + "x" + str(curEpToWrite.episode) + " on tvdb... has it been removed? Should I delete from db?")
return None
if not myEp["firstaired"]:
myEp["firstaired"] = str(datetime.date.fromordinal(1))
if not myEp["episodename"]:
示例4: _show_data
def _show_data(self, show_obj):
"""
Creates an elementTree XML structure for a MediaBrowser-style series.xml
returns the resulting data object.
show_obj: a TVShow instance to create the NFO for
"""
tvdb_lang = show_obj.lang
# There's gotta be a better way of doing this but we don't wanna
# change the language value elsewhere
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if tvdb_lang and not tvdb_lang == 'en':
ltvdb_api_parms['language'] = tvdb_lang
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
tv_node = etree.Element("Series")
for ns in XML_NSMAP.keys():
tv_node.set(ns, XML_NSMAP[ns])
try:
myShow = t[int(show_obj.tvdbid)]
except tvdb_exceptions.tvdb_shownotfound:
logger.log("Unable to find show with id " + str(show_obj.tvdbid) + " on tvdb, skipping it", logger.ERROR)
raise
except tvdb_exceptions.tvdb_error:
logger.log("TVDB is down, can't use its data to make the NFO", logger.ERROR)
raise
# check for title and id
try:
if myShow["seriesname"] == None or myShow["seriesname"] == "" or myShow["id"] == None or myShow["id"] == "":
logger.log("Incomplete info for show with id " + str(show_obj.tvdbid) + " on tvdb, skipping it", logger.ERROR)
return False
except tvdb_exceptions.tvdb_attributenotfound:
logger.log("Incomplete info for show with id " + str(show_obj.tvdbid) + " on tvdb, skipping it", logger.ERROR)
return False
tvdbid = etree.SubElement(tv_node, "id")
if myShow["id"] != None:
tvdbid.text = myShow["id"]
Actors = etree.SubElement(tv_node, "Actors")
if myShow["actors"] != None:
Actors.text = myShow["actors"]
ContentRating = etree.SubElement(tv_node, "ContentRating")
if myShow["contentrating"] != None:
ContentRating.text = myShow["contentrating"]
premiered = etree.SubElement(tv_node, "FirstAired")
if myShow["firstaired"] != None:
premiered.text = myShow["firstaired"]
genre = etree.SubElement(tv_node, "genre")
if myShow["genre"] != None:
genre.text = myShow["genre"]
IMDBId = etree.SubElement(tv_node, "IMDBId")
if myShow["imdb_id"] != None:
IMDBId.text = myShow["imdb_id"]
IMDB_ID = etree.SubElement(tv_node, "IMDB_ID")
if myShow["imdb_id"] != None:
IMDB_ID.text = myShow["imdb_id"]
Overview = etree.SubElement(tv_node, "Overview")
if myShow["overview"] != None:
Overview.text = myShow["overview"]
Network = etree.SubElement(tv_node, "Network")
if myShow["network"] != None:
Network.text = myShow["network"]
Runtime = etree.SubElement(tv_node, "Runtime")
if myShow["runtime"] != None:
Runtime.text = myShow["runtime"]
Rating = etree.SubElement(tv_node, "Rating")
if myShow["rating"] != None:
Rating.text = myShow["rating"]
SeriesID = etree.SubElement(tv_node, "SeriesID")
if myShow["seriesid"] != None:
SeriesID.text = myShow["seriesid"]
SeriesName = etree.SubElement(tv_node, "SeriesName")
if myShow["seriesname"] != None:
SeriesName.text = myShow["seriesname"]
rating = etree.SubElement(tv_node, "Status")
if myShow["status"] != None:
rating.text = myShow["status"]
helpers.indentXML(tv_node)
#.........这里部分代码省略.........
示例5: makeShowNFO
def makeShowNFO(showID, showDir):
logger.log("Making NFO for show "+str(showID)+" in dir "+showDir, logger.DEBUG)
if not makeDir(showDir):
logger.log("Unable to create show dir, can't make NFO", logger.ERROR)
return False
t = tvdb_api.Tvdb(actors=True, **sickbeard.TVDB_API_PARMS)
tvNode = etree.Element( "tvshow" )
for ns in XML_NSMAP.keys():
tvNode.set(ns, XML_NSMAP[ns])
try:
myShow = t[int(showID)]
except tvdb_exceptions.tvdb_shownotfound:
logger.log("Unable to find show with id " + str(showID) + " on tvdb, skipping it", logger.ERROR)
raise
except tvdb_exceptions.tvdb_error:
logger.log("TVDB is down, can't use its data to add this show", logger.ERROR)
raise
# check for title and id
try:
if myShow["seriesname"] == None or myShow["seriesname"] == "" or myShow["id"] == None or myShow["id"] == "":
logger.log("Incomplete info for show with id " + str(showID) + " on tvdb, skipping it", logger.ERROR)
return False
except tvdb_exceptions.tvdb_attributenotfound:
logger.log("Incomplete info for show with id " + str(showID) + " on tvdb, skipping it", logger.ERROR)
return False
title = etree.SubElement( tvNode, "title" )
if myShow["seriesname"] != None:
title.text = myShow["seriesname"]
rating = etree.SubElement( tvNode, "rating" )
if myShow["rating"] != None:
rating.text = myShow["rating"]
plot = etree.SubElement( tvNode, "plot" )
if myShow["overview"] != None:
plot.text = myShow["overview"]
episodeguideurl = etree.SubElement( tvNode, "episodeguideurl" )
episodeguide = etree.SubElement( tvNode, "episodeguide" )
if myShow["id"] != None:
showurl = sickbeard.TVDB_BASE_URL + '/series/' + myShow["id"] + '/all/en.zip'
episodeguideurl.text = showurl
episodeguide.text = showurl
mpaa = etree.SubElement( tvNode, "mpaa" )
if myShow["contentrating"] != None:
mpaa.text = myShow["contentrating"]
tvdbid = etree.SubElement( tvNode, "id" )
if myShow["id"] != None:
tvdbid.text = myShow["id"]
genre = etree.SubElement( tvNode, "genre" )
if myShow["genre"] != None:
genre.text = " / ".join([x for x in myShow["genre"].split('|') if x != ''])
premiered = etree.SubElement( tvNode, "premiered" )
if myShow["firstaired"] != None:
premiered.text = myShow["firstaired"]
studio = etree.SubElement( tvNode, "studio" )
if myShow["network"] != None:
studio.text = myShow["network"]
for actor in myShow['_actors']:
cur_actor = etree.SubElement( tvNode, "actor" )
cur_actor_name = etree.SubElement( cur_actor, "name" )
cur_actor_name.text = actor['name']
cur_actor_role = etree.SubElement( cur_actor, "role" )
cur_actor_role_text = actor['role']
if cur_actor_role_text != None:
cur_actor_role.text = cur_actor_role_text
cur_actor_thumb = etree.SubElement( cur_actor, "thumb" )
cur_actor_thumb_text = actor['image']
if cur_actor_thumb_text != None:
cur_actor_thumb.text = cur_actor_thumb_text
logger.log("Writing NFO to "+os.path.join(showDir, "tvshow.nfo"), logger.DEBUG)
# Make it purdy
indentXML( tvNode )
nfo_fh = open(os.path.join(showDir, "tvshow.nfo"), 'w')
nfo = etree.ElementTree( tvNode )
#.........这里部分代码省略.........
示例6: _show_data
def _show_data(self, show_obj):
"""
Creates an elementTree XML structure for a Mede8er-style Series.xml
returns the resulting data object.
show_obj: a TVShow instance to create the XML-NFO for
"""
logger.log("Mede8er: Starting Mede8er _show_data method", logger.MESSAGE)
tvdb_lang = show_obj.lang
# There's gotta be a better way of doing this but we don't wanna
# change the language value elsewhere
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if tvdb_lang and not tvdb_lang == "en":
ltvdb_api_parms["language"] = tvdb_lang
t = tvdb_api.Tvdb(actors=True, **ltvdb_api_parms)
rootNode = etree.Element("details")
tv_node = etree.SubElement(rootNode, "movie")
# tv_node = etree.Element("movie")
tv_node.attrib["isExtra"] = "false"
tv_node.attrib["isSet"] = "false"
tv_node.attrib["isTV"] = "true"
for ns in XML_NSMAP.keys():
tv_node.set(ns, XML_NSMAP[ns])
try:
myShow = t[int(show_obj.tvdbid)]
except tvdb_exceptions.tvdb_shownotfound:
logger.log(
"Mede8er: Unable to find show with id " + str(show_obj.tvdbid) + " on tvdb, skipping it", logger.ERROR
)
raise
except tvdb_exceptions.tvdb_error:
logger.log("Mede8er: TVDB is down, can't use its data to make the XML-NFO", logger.ERROR)
raise
# check for title and id
try:
if myShow["seriesname"] == None or myShow["seriesname"] == "" or myShow["id"] == None or myShow["id"] == "":
logger.log(
"Mede8er: Incomplete info for show with id " + str(show_obj.tvdbid) + " on tvdb, skipping it",
logger.ERROR,
)
return False
except tvdb_exceptions.tvdb_attributenotfound:
logger.log(
"Mede8er: Incomplete info for show with id " + str(show_obj.tvdbid) + " on tvdb, skipping it",
logger.ERROR,
)
return False
title = etree.SubElement(tv_node, "title")
if myShow["seriesname"] != None:
title.text = myShow["seriesname"]
tvdbid = etree.SubElement(tv_node, "tvdbid")
if myShow["id"] != None:
tvdbid.text = myShow["id"]
seriesID = etree.SubElement(tv_node, "seriesID")
if myShow["seriesid"] != None:
seriesID.text = myShow["seriesid"]
imdbid = etree.SubElement(tv_node, "imdbid")
if myShow["imdb_id"] != None:
imdbid.text = myShow["imdb_id"]
zap2id = etree.SubElement(tv_node, "zap2itid")
if myShow["zap2it_id"] != None:
zap2id.text = myShow["zap2it_id"]
premiered = etree.SubElement(tv_node, "releasedate")
if myShow["firstaired"] != None:
premiered.text = myShow["firstaired"]
rating = etree.SubElement(tv_node, "rating")
if myShow["rating"] != None:
rating.text = myShow["rating"]
ratingcount = etree.SubElement(tv_node, "ratingcount")
if myShow["ratingcount"] != None:
ratingcount.text = myShow["ratingcount"]
network = etree.SubElement(tv_node, "network")
if myShow["network"] != None:
network.text = myShow["network"]
Runtime = etree.SubElement(tv_node, "runtime")
if myShow["runtime"] != None:
Runtime.text = myShow["runtime"]
genre = etree.SubElement(tv_node, "genre")
if myShow["genre"] != None:
#.........这里部分代码省略.........