def __init__(self, data, id): ##--------------------------------Title--------------------------------## if data.xpath("""./title"""): self.Title = functions.GetPreferedTitleNoType(data.xpath("""./title""")).encode('utf-8').strip().translate(constants.ReplaceChars) ##--------------------------------Summary------------------------------## ##--------------------------------Originally_Available_At--------------## if GetElementText(data, "airdate"): self.Originally_Available_At = GetElementText(data, "airdate") ##--------------------------------Rating-------------------------------## if GetElementText(data, "rating"): self.Rating = GetElementText(data, "rating") ##--------------------------------Absolute_Index-----------------------## if GetElementText(data, "epno") and GetElementText(data, "epno").isdigit(): self.Absolute_Index = GetElementText(data, "epno") ##--------------------------------Writers------------------------------## ##--------------------------------Directors----------------------------## ##--------------------------------Producers----------------------------## ##--------------------------------Thumbs-------------------------------## ##--------------------------------Number-------------------------------## if GetElementText(data, "epno"): self.Number = str(GetElementText(data, "epno")) ##--------------------------------Season-------------------------------## if data.xpath("""./epno""")[0].get("type"): if data.xpath("""./epno""")[0].get("type") == "1": self.Season = "01" else: self.Season = "00"
def __init__(self, data, id): ##--------------------------------Title--------------------------------## if GetElementText(data, "EpisodeName"): self.Title = str(GetElementText( data, "EpisodeName")).encode('utf-8').strip().translate( constants.ReplaceChars) ##--------------------------------Summary------------------------------## if GetElementText(data, "Overview"): self.Summary = GetElementText(data, "Overview") ##--------------------------------Originally_Available_At--------------## if GetElementText(data, "FirstAired"): self.Originally_Available_At = GetElementText( data, "FirstAired") ##--------------------------------Rating-------------------------------## if GetElementText(data, "Rating"): self.Rating = GetElementText(data, "Rating") ##--------------------------------Absolute_Index-----------------------## if GetElementText(data, "absolute_number"): self.Absolute_Index = int( GetElementText(data, "absolute_number")) ##--------------------------------Writers------------------------------## if GetElementText(data, "Writer"): if self.Writers is None: self.Writers = [] self.Writers.append(GetElementText(data, "Writer")) ##--------------------------------Directors----------------------------## if GetElementText(data, "Director"): if self.Directors is None: self.Directors = [] self.Directors.append(GetElementText(data, "Director")) ##--------------------------------Producers----------------------------## ##--------------------------------Thumbs-------------------------------## if GetElementText(data, "filename"): root = etree.tostring(E.Images(), pretty_print=True, xml_declaration=True, encoding="UTF-8") root = XML.ElementFromString(root) bannerPath = GetElementText(data, "filename") bannerThumb = "_cache" + "/" + bannerPath mainUrl, thumbUrl, mainLocalPath, thumbLocalPath = functions.ParseImage( bannerPath, constants.TVDB_IMAGES_URL, os.path.join("TvDB", id, "thumbs"), bannerThumb) SubElement(root, "Image", id="1", mainUrl=mainUrl, thumbUrl=thumbUrl, mainLocalPath=mainLocalPath, thumbLocalPath=thumbLocalPath) self.Thumbs = root ##--------------------------------Number-------------------------------## if GetElementText(data, "EpisodeNumber"): self.Number = str(GetElementText(data, "EpisodeNumber")).zfill(2) ##--------------------------------Season-------------------------------## if GetElementText(data, "SeasonNumber"): self.Season = str(GetElementText(data, "SeasonNumber")).zfill(2)
def __init__(self, id): logging.Log_Milestone("TvDB" + "_" + id) self.ID = id self.MetaType = "Tvdb" data = XMLFromURL(constants.TVDB_HTTP_API_URL % id, id + ".xml", os.path.join("TvDB", id), CACHE_1HOUR * 24).xpath("""/Data""")[0] ##--------------------------------Title--------------------------------## if GetElementText(data, "Series/SeriesName"): self.Title = str(GetElementText( data, "Series/SeriesName")).encode('utf-8').strip().translate( constants.ReplaceChars) ##--------------------------------Summary------------------------------## if GetElementText(data, "Series/Overview"): self.Summary = GetElementText(data, "Series/Overview") ##--------------------------------Originally_Available_At--------------## if GetElementText(data, "Series/FirstAired"): self.Originally_Available_At = GetElementText( data, "Series/FirstAired") ##--------------------------------Rating-------------------------------## if GetElementText(data, "Series/Rating"): self.Rating = GetElementText(data, "Series/Rating") ##--------------------------------Studio-------------------------------## if GetElementText(data, "Series/Network"): self.Studio = GetElementText(data, "Series/Network") ##--------------------------------Countries----------------------------## ##--------------------------------Genres-------------------------------## if GetElementText(data, "Series/Genre"): self.Genres = filter( None, GetElementText(data, "Series/Genre").split("|")) ##--------------------------------Tags---------------------------------## ##--------------------------------Collections--------------------------## ##--------------------------------Content_Rating-----------------------## if GetElementText(data, "Series/ContentRating"): self.Content_Rating = GetElementText(data, "Series/ContentRating") ##--------------------------------Writers------------------------------## ##--------------------------------Directors----------------------------## ##--------------------------------Producers----------------------------## ##--------------------------------Roles--------------------------------## self.Roles = [] ##--------------------------------Images-------------------------------## banners = [] bannersXml = XMLFromURL(constants.TVDB_BANNERS_URL % id, id + "_banners.xml", os.path.join("TvDB", id), CACHE_1HOUR * 24) if bannersXml: art = etree.tostring(E.Images(), pretty_print=True, xml_declaration=True, encoding="UTF-8") art = XML.ElementFromString(art) artCount = 2 posters = etree.tostring(E.Images(), pretty_print=True, xml_declaration=True, encoding="UTF-8") posters = XML.ElementFromString(posters) postersCount = 2 banners = etree.tostring(E.Images(), pretty_print=True, xml_declaration=True, encoding="UTF-8") banners = XML.ElementFromString(banners) bannersCount = 2 season = etree.tostring(E.Images(), pretty_print=True, xml_declaration=True, encoding="UTF-8") season = XML.ElementFromString(season) seasonCount = [] for banner in sorted( bannersXml.xpath("./Banner"), key=lambda x: float(GetElementText(x, "Rating", 0)), reverse=True): bannerType = GetElementText(banner, "BannerType") bannerType2 = GetElementText(banner, "BannerType2") bannerPath = GetElementText(banner, "BannerPath") bannerThumb = GetElementText(banner, "ThumbnailPath") if bannerThumb == None or bannerThumb == "": bannerThumb = "_cache" + "/" + bannerPath metatype = ("art" if bannerType == "fanart" else \ "posters" if bannerType == "poster" else \ "banners" if bannerType == "series" or bannerType2=="seasonwide" else \ "season" if bannerType == "season" and bannerType2=="680x1000" else \ "season" if bannerType == "season" and bannerType2=="season" else None) #Log("Images: %s, %s, %s, %s, %s" % (bannerPath, constants.TVDB_IMAGES_URL, id, metatype, bannerThumb)) mainUrl, thumbUrl, mainLocalPath, thumbLocalPath = functions.ParseImage( bannerPath, constants.TVDB_IMAGES_URL, os.path.join("TvDB", id, metatype), bannerThumb) if metatype == "art": SubElement(art, "Image", id=str(1 if bannerPath == GetElementText( data, "Series/fanart") else artCount), mainUrl=mainUrl, thumbUrl=thumbUrl, mainLocalPath=mainLocalPath, thumbLocalPath=thumbLocalPath) artCount = artCount + 1 if metatype == "posters": SubElement(posters, "Image", id=str(1 if bannerPath == GetElementText( data, "Series/poster") else postersCount), mainUrl=mainUrl, thumbUrl=thumbUrl, mainLocalPath=mainLocalPath, thumbLocalPath=thumbLocalPath) postersCount = postersCount + 1 if metatype == "banners": SubElement(banners, "Image", id=str(1 if bannerPath == GetElementText( data, "Series/banner") else bannersCount), mainUrl=mainUrl, thumbUrl=thumbUrl, mainLocalPath=mainLocalPath, thumbLocalPath=thumbLocalPath) bannersCount = bannersCount + 1 if metatype == "season": seasonCount.append(GetElementText(banner, "Season")) SubElement(season, "Image", id=str( seasonCount.count( GetElementText(banner, "Season"))), mainUrl=mainUrl, thumbUrl=thumbUrl, mainLocalPath=mainLocalPath, thumbLocalPath=thumbLocalPath, season=str(GetElementText(banner, "Season"))) self.Art = art self.Posters = posters self.Banners = banners self.Season = season ##--------------------------------Themes-------------------------------## self.Themes = [] ##--------------------------------EpisodeCount-------------------------## self.EpisodeCount = len( data.xpath("""./Episode/SeasonNumber[text()>0]""")) ##--------------------------------SpecialCount-------------------------## self.SpecialCount = len( data.xpath("""./Episode/SeasonNumber[text()=0]""")) ##--------------------------------Duration-----------------------------## if GetElementText(data, "Series/Runtime"): self.Duration = int( int(self.EpisodeCount) * int(GetElementText(data, "Series/Runtime"))) ##--------------------------------OP/ED_List---------------------------## self.OpList = [] self.EdList = [] ##--------------------------------Episodes-----------------------------## if len(data.xpath("""./Episode""")) > 0: self.Episodes = [] for item in data.xpath("""./Episode"""): self.Episodes.append(self.Episode(item, id)) #Log("AniDB - __init__() - Populate Title: '%s', Network: '%s', Overview: '%s', FirstAired: '%s', Genre: '%s', ContentRating: '%s', Rating: '%s', Episodes: '%s', EpisodeCount: '%s', SpecialCount: '%s', OpedCount: '%s', Posters: '%s'" #% (self.Title, self.Network, self.Overview, self.FirstAired, self.Genre, self.ContentRating, self.Rating, self.Episodes, self.EpisodeCount, self.SpecialCount, self.OpedCount, self.Posters) ) logging.Log_Milestone("TvDB" + "_" + id)
def __init__(self, id): logging.Log_Milestone("AniDB" + "_" + id) data = XMLFromURL(constants.ANIDB_HTTP_API_URL + id, id + ".xml", os.path.join("AniDB", id), CACHE_1HOUR * 24).xpath("""/anime""")[0] ##--------------------------------ID-----------------------------------## self.ID = id self.MetaType = "Anidb" self.Type = GetElementText(data, "type") ##--------------------------------Title--------------------------------## if data.xpath("""./titles"""): self.Title = functions.GetPreferedTitle( data.xpath("""./titles/title""")).encode( 'utf-8').strip().translate(constants.ReplaceChars) ##--------------------------------Summary------------------------------## if GetElementText(data, "description"): description = re.sub( r'(?m)^\*.*\n?', '', GetElementText(data, "description").replace("`", "'")).strip() self.Summary = re.sub( r"http://anidb\.net/[a-z]{2}[0-9]+ \[(.+?)\]", r"\1", description) ##--------------------------------Originally_Available_At--------------## if GetElementText(data, "startdate"): self.Originally_Available_At = GetElementText(data, "startdate") ##--------------------------------Rating-------------------------------## if GetElementText(data, "ratings/permanent") and GetElementText( data, "ratings/temporary"): self.Rating = ( float(GetElementText(data, "ratings/permanent")) + float(GetElementText(data, "ratings/temporary"))) / 2 elif GetElementText(data, "ratings/permanent"): self.Rating = float(GetElementText(data, "ratings/permanent")) elif GetElementText(data, "ratings/temporary"): self.Rating = float(GetElementText(data, "ratings/temporary")) ##--------------------------------Studio-------------------------------## for creator in data.xpath( """./creators/name[@type="Animation Work"]"""): self.Studio = creator.text ##--------------------------------Countries----------------------------## for setting in data.xpath("""./tags/tag/name[text()="setting"]/.."""): for place in data.xpath("""./tags/tag[@parentid="%s"]""" % (setting.get("id"))): for planet in data.xpath("""./tags/tag[@parentid="%s"]""" % (place.get("id"))): for continent in data.xpath( """./tags/tag[@parentid="%s"]""" % (planet.get("id"))): for country in data.xpath( """./tags/tag[@parentid="%s" and @weight>="%s"]/name""" % (continent.get("id"), constants.MINIMUM_WEIGHT)): if self.Countries is None: self.Countries = [] self.Countries.append(country.text) ##--------------------------------Duration-----------------------------## for length in data.xpath("""./episodes/episode/epno[@type="1"]/.."""): if GetElementText(length, "length"): if self.Duration is None: self.Duration = 0 self.Duration = self.Duration + int( GetElementText(length, "length")) ##--------------------------------Genres-------------------------------## for element in data.xpath("""./tags/tag/name[text()="elements"]/.."""): for genre in data.xpath( """./tags/tag[@parentid="%s" and @weight>="%s"]/name""" % (element.get("id"), constants.MINIMUM_WEIGHT)): if self.Genres is None: self.Genres = [] self.Genres.append(str(genre.text).title()) ##--------------------------------Tags---------------------------------## for tag in data.xpath("""./tags/tag[@infobox="true"]/name"""): if self.Tags is None: self.Tags = [] self.Tags.append(str(tag.text).title()) ##--------------------------------Collections--------------------------## for collection in data.xpath( """./relatedanime/anime[(@type="Prequel") or (@type="Sequel")]""" ): if self.Collections is None: self.Collections = [] self.Collections.append(collection.text) ##--------------------------------Content_Rating-----------------------## for indicators in data.xpath( """./tags/tag/name[text()="content indicators"]/.."""): ratingInt = 0 for tag in data.xpath( """./tags/tag[(@parentid="%s") and (@weight>="%s")]/name""" % (indicators.get("id"), constants.MINIMUM_WEIGHT)): if tag.text == "nudity": 1 if ratingInt < 1 else ratingInt elif tag.text == "sex": 2 if ratingInt < 2 else ratingInt elif tag.text == "violence": 2 if ratingInt < 2 else ratingInt if ratingInt == 0: self.Content_Rating = "PG-13" elif ratingInt == 1: self.Content_Rating = "R" elif ratingInt == 2: self.Content_Rating = "NC-17" ##--------------------------------Writers------------------------------## for writer in data.xpath( """./creators/name[(@type="Original Work") or (@type="Script") or (@type="Screenplay")]""" ): if self.Writers is None: self.Writers = [] self.Writers.append(writer.text) ##--------------------------------Directors----------------------------## for director in data.xpath("""./creators/name[@type="Direction"]"""): if self.Directors is None: self.Directors = [] self.Directors.append(director.text) ##--------------------------------Producers----------------------------## for producer in data.xpath( """./creators/name[@type="Series Composition"]"""): if self.Producers is None: self.Producers = [] self.Producers.append(producer.text) ##--------------------------------Roles--------------------------------## roles = etree.tostring(E.Roles(), pretty_print=True, xml_declaration=True, encoding="UTF-8") roles = XML.ElementFromString(roles) for role in data.xpath( """./characters/character/charactertype[text()="Character"]/..""" ): character_name = "" seiyuu_name = "" seiyuu_pic = "" if GetElementText(role, "name"): character_name = str(GetElementText(role, "name")) if GetElementText(role, "seiyuu"): seiyuu_name = GetElementText(role, "seiyuu") seiyuu_pic = "" if role.find('seiyuu').get('picture'): seiyuu_pic = constants.ANIDB_PIC_BASE_URL + role.find( 'seiyuu').get('picture') SubElement(roles, "Role", character_name=character_name, seiyuu_name=seiyuu_name, seiyuu_pic=seiyuu_pic) if not roles is None: self.Roles = roles ##--------------------------------Images------------------------------## if GetElementText(data, "picture"): season = etree.tostring(E.Images(), pretty_print=True, xml_declaration=True, encoding="UTF-8") season = XML.ElementFromString(season) bannerPath = GetElementText(data, "picture") mainUrl, thumbUrl, mainLocalPath, thumbLocalPath = functions.ParseImage( bannerPath, constants.ANIDB_PIC_BASE_URL, os.path.join("AniDB", id, "season"), constants.ANIDB_PIC_THUMB_URL % os.path.splitext(bannerPath)[0]) SubElement(season, "Image", id="1", mainUrl=mainUrl, thumbUrl=thumbUrl, mainLocalPath=mainLocalPath, thumbLocalPath=thumbLocalPath, season="1") self.Season = season self.Posters = copy.deepcopy(season) ##--------------------------------Themes-------------------------------## self.Themes = [] ##--------------------------------Links--------------------------------## if GetElementText(data, "resources"): links = etree.tostring(E.Links(), pretty_print=True, xml_declaration=True, encoding="UTF-8") links = XML.ElementFromString(links) value = [] for externalentity in data.xpath("""./resources/resource/*"""): for identifier in externalentity.xpath("""./identifier"""): if externalentity.getparent().get("type") == "1": SubElement(links, "Link", type="ANN", url=constants.ANIDB_RESOURCES_ANN % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "2": SubElement(links, "Link", type="MAL", url=constants.ANIDB_RESOURCES_MAL % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "3": value.append(identifier.text) elif externalentity.getparent().get("type") == "4": SubElement(links, "Link", type="OfficialJP", url=identifier.text) elif externalentity.getparent().get("type") == "5": SubElement(links, "Link", type="OfficialEN", url=identifier.text) elif externalentity.getparent().get("type") == "6": SubElement(links, "Link", type="WikiEN", url=constants.ANIDB_RESOURCES_WIKIEN % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "7": SubElement(links, "Link", type="WikiJP", url=constants.ANIDB_RESOURCES_WIKIJP % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "8": SubElement(links, "Link", type="Schedule", url=constants.ANIDB_RESOURCES_SCHEDULE % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "9": SubElement(links, "Link", type="AllCinema", url=constants.ANIDB_RESOURCES_ALLCINEMA % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "10": SubElement(links, "Link", type="Anison", url=constants.ANIDB_RESOURCES_ANISON % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "11": SubElement(links, "Link", type="Lain", url=constants.ANIDB_RESOURCES_LAIN % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "14": SubElement(links, "Link", type="VNDB", url=constants.ANIDB_RESOURCES_VNDB % (identifier.text), value=identifier.text) elif externalentity.getparent().get("type") == "15": SubElement(links, "Link", type="Marumegane", url=constants.ANIDB_RESOURCES_MARUMEGANE % (identifier.text), value=identifier.text) if externalentity.getparent().get("type") == "3": SubElement(links, "Link", type="AnimeNfo", url=constants.ANIDB_RESOURCES_ANIMENFO % (u"%s" % value[0], u"%s" % value[1]), value=u"%s" % value) self.Links = links ##--------------------------------EpisodeCount-------------------------## self.EpisodeCount = int(GetElementText(data, "episodecount")) ##--------------------------------SpecialCount-------------------------## self.SpecialCount = len( data.xpath("""./episodes/episode/epno[@type="2"]""")) ##--------------------------------OP/ED_List---------------------------## self.OpList = [] self.EdList = [] for specials in data.xpath( """./episodes/episode/epno[@type="3"]/.."""): if functions.CleanTitle( functions.GetPreferedTitleNoType( specials.xpath("""./title"""))).startswith("Opening"): self.OpList.append(str(GetElementText(specials, "epno"))) if functions.CleanTitle( functions.GetPreferedTitleNoType( specials.xpath("""./title"""))).startswith("Ending"): self.EdList.append(str(GetElementText(specials, "epno"))) ##--------------------------------Episodes-----------------------------## if len(data.xpath("""./episodes/episode""")) > 0: self.Episodes = [] for item in data.xpath("""./episodes/episode"""): self.Episodes.append(self.Episode(item, id)) #Log("AniDB - __init__() - Populate Title: '%s', Network: '%s', Overview: '%s', FirstAired: '%s', Genre: '%s', ContentRating: '%s', Rating: '%s', Episodes: '%s', EpisodeCount: '%s', SpecialCount: '%s', OpCount: '%s', EdCount: '%s', Posters: '%s'" #% (self.Title, self.Network, self.Overview, self.FirstAired, self.Genre, self.ContentRating, self.Rating, self.Episodes, self.EpisodeCount, self.SpecialCount, len(self.OpList), len(self.EdList), self.Posters) ) logging.Log_Milestone("AniDB" + "_" + id)