Exemple #1
0
    def update(self, metadata, media, lang, force=False):
        Log.Debug(
            "--- Update Begin -------------------------------------------------------------------------------------------"
        )
        if force:
            HTTP.ClearCache()
        logging.New_Milestones()
        logging.New_AniDB()
        logging.Log_Milestone("WholeUpdate")
        common.RefreshData()
        source, id = metadata.id.split("-")
        Log("Source: %s, ID: %s" % (source, id))
        #filename = ""
        #for sea_item in media.seasons:
        #    Log("FileName1: %s" % (sea_item))
        #    for eps_item in media.seasons[sea_item].episodes:
        #        Log("FileName2: %s" % (eps_item))
        #        for media_item in media.seasons[sea_item].episodes[eps_item].items:
        #            for item_part in media_item.parts:
        #                filename = item_part.file.lower()
        #                Log("FileName: %s" % (filename))
        #functions.downloadfile("test.webm", "https://my.mixtape.moe/sovrtq.webm")

        mappingData = None
        if source in ["anidb", "anidb2"]:
            mappingData = scudlee.ScudLee(id)
        if source in ["tvdb", "tvdb2", "tvdb3", "tvdb4", "tvdb5"]:
            mappingData = scudlee.ScudLee(None, id)
        Log.Debug(
            "Init - Update() - source: '%s', anidbid: '%s', tvdbid: '%s'" %
            (source, mappingData.AnidbId, mappingData.TvdbId))

        if mappingData != None:
            map = common.MapSeries(mappingData)
            #functions.SaveFile(etree.tostring(map, pretty_print=True, xml_declaration=True, encoding="UTF-8"), mappingData.FirstSeries + ".bundle.xml", "Bundles")
            #common.MapLocal(media, map, mappingData.AnidbId)
            common.MapLocal(map, media)
            common.MapMeta(map)
            functions.SaveFile(
                etree.tostring(map,
                               pretty_print=True,
                               xml_declaration=True,
                               encoding="UTF-8"),
                mappingData.FirstSeries + ".bundle.xml", "Bundles")
            if constants.ExportBundles:
                common.ExportMap(map, mappingData.FirstSeries + ".bundle.xml")
            common.MapMedia(map, metadata, mappingData.AnidbId,
                            mappingData.TvdbId)
        logging.Log_Milestone("WholeUpdate")
        logging.Log_AniDB(None, True)
Exemple #2
0
 def scoreTitle(anime=anime,
                maxi=maxi,
                anidb=anidb,
                perfectScore=perfectScore):
     logging.Log_Milestone("Title")
     anime = Titles(anime, orig_title)
     logging.Log_Milestone("Title")
     isValid = True
     if (anime.Id in maxi
             and maxi[anime.Id] <= anime.Score) or (not anime.Id
                                                    in maxi):
         maxi[anime.Id] = anime.Score
     else:
         isValid = False
     if isValid:
         startdate = None
         if (media.year and anime.Score >= 90):
             show = anidb.AniDB(anime.Id)
             if show:
                 try:
                     startdate = dateParse(
                         show.Originally_Available_At).year
                 except:
                     pass
                 if str(startdate) != str(media.year):
                     isValid = False
                 Log.Debug(
                     "Init - Search() - date: '%s', aired: '%s'"
                     % (media.year, startdate))
             elite.append(isValid)
         elif anime.Score >= 90:
             elite.append(isValid)
         if isValid:
             if anime.Score == 100:
                 perfectScore.append(anime.Id)
             Log.Debug(
                 "Init - Search() - find - id: '%s-%s', title: '%s', score: '%s'"
                 %
                 ("anidb", anime.Id, anime.Title, anime.Score))
             results.Append(
                 MetadataSearchResult(
                     id="%s-%s" % ("anidb", anime.Id),
                     name="%s [%s-%s]" %
                     (anime.Title, "anidb", anime.Id),
                     year=startdate,
                     lang=Locale.Language.English,
                     score=anime.Score))
Exemple #3
0
def SearchMap(root, media, anidbId, tvdbId):
    logging.Log_Milestone("SearchMap")
    streamTag = []
    seasonNo = 0
    seasonMap = root.xpath("""./Season[@AnidbId="%s" and @num!="0"]""" %
                           (anidbId))
    if not seasonMap:
        seasonMap = root.xpath("""./Season[@TvdbId="%s" and @num!="0"]""" %
                               (tvdbId))
    if seasonMap:
        seasonMap = seasonMap[0]
        seasonNo = int(seasonMap.get("num"))

    season = str(int(map.getparent().get('num')) - seasonNo + 1)

    for seasonNo in media.seasons:
        for episodeNo in media.seasons[seasonNo].episodes:
            map = root.xpath("""./Season[@num>=%s]/Episode""" % (seasonNo))

    logging.Log_Milestone("SearchMap")
Exemple #4
0
def GetAnimeTitleByName(Tree, Name):
    logging.Log_Milestone("GetAnimeTitleByName_" + Name)
    Name = Name.lower()

    #Log("Name: %s" % (Name))
    result = []

    logging.Log_Milestone("GetAnimeTitleByName_Xpath_" + Name)
    result = Tree.xpath(u"""./anime/title
                [@type='main' or @type='official' or @type='syn' or @type='short']
                [lower-case(string(clean-title(string(text()))))="%s"
                or contains(lower-case(string(clean-title(string(text())))), "%s")]"""
                        % (Name, Name))
    logging.Log_Milestone("GetAnimeTitleByName_Xpath_" + Name)

    if not result:
        logging.Log_Milestone("GetAnimeTitleByName_DiffLib_" + Name)
        result = Tree.xpath(u"""./anime/title
                [@type='main' or @type='official' or @type='syn' or @type='short']
                [is-match("%s", lower-case(string(clean-title(string(text())))))]"""
                            % (Name))
        logging.Log_Milestone("GetAnimeTitleByName_DiffLib_" + Name)
    logging.Log_Milestone("GetAnimeTitleByName_" + Name)
    return result
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
            def Episode_Task(map=map,
                             metadata=metadata,
                             anidbId=anidbId,
                             tvdbId=tvdbId,
                             seasonNo=seasonNo):
                season = str(int(map.getparent().get('num')) - seasonNo + 1)
                #Log("SeasonNumber: %s, %s, %s" % (seasonNo, map.getparent().get('num'), str(int(map.getparent().get('num')) - seasonNo + 1)))
                episode = map.get('num')
                #Log("Episode: '%s', '%s', %s, %s" % (season, episode, anidbId, map.getparent().get('AnidbId')))

                logging.Log_Milestone("MapMedia_Episode_S" + season + "E" +
                                      episode)
                metadata.seasons[season].episodes[
                    episode].title = functions.PopulateMetadata(
                        map.xpath("""./Title/*[node()]"""), str,
                        constants.EPISODE_TITLE_PRIORITY, None, "EpisodeTitle")
                metadata.seasons[season].episodes[
                    episode].summary = functions.PopulateMetadata(
                        map.xpath("""./Summary/*[node()]"""), str,
                        constants.EPISODE_SUMMARY_PRIORITY)
                metadata.seasons[season].episodes[
                    episode].originally_available_at = functions.PopulateMetadata(
                        map.xpath("""./Originally_Available_At/*[node()]"""),
                        datetime.date,
                        constants.EPISODE_ORIGINALLYAVAILABLEAT_PRIORITY)
                metadata.seasons[season].episodes[
                    episode].rating = functions.PopulateMetadata(
                        map.xpath("""./Rating/*[node()]"""), float,
                        constants.EPISODE_RATING_PRIORITY)
                metadata.seasons[season].episodes[
                    episode].absolute_index = functions.PopulateMetadata(
                        map.xpath("""./Absolute_Index/*[node()]"""), int,
                        constants.EPISODE_ABSOLUTE_INDEX_PRIORITY)

                functions.PopulateMetadata(
                    map.xpath("""./Writers/*[node()]"""),
                    Framework.modelling.attributes.SetObject,
                    constants.EPISODE_WRITERS_PRIORITY,
                    metadata.seasons[season].episodes[episode].writers)
                functions.PopulateMetadata(
                    map.xpath("""./Directors/*[node()]"""),
                    Framework.modelling.attributes.SetObject,
                    constants.EPISODE_DIRECTORS_PRIORITY,
                    metadata.seasons[season].episodes[episode].directors)
                functions.PopulateMetadata(
                    map.xpath("""./Producers/*[node()]"""),
                    Framework.modelling.attributes.SetObject,
                    constants.EPISODE_PRODUCERS_PRIORITY,
                    metadata.seasons[season].episodes[episode].producers)
                functions.PopulateMetadata(
                    map.xpath("""./Thumbs//Image"""),
                    Framework.modelling.attributes.ProxyContainerObject,
                    constants.EPISODE_THUMBS_PRIORITY,
                    metadata.seasons[season].episodes[episode].thumbs,
                    "Images")
                if map.xpath(
                        """count(./Streams/Stream[@type="%s"][@lang="%s"])""" %
                    ("audio", "eng")
                ) > 0 and not "English Dubbed" in metadata.collections:
                    metadata.collections.add("English Dubbed")
                    streamTag.append("English Dubbed")
                if map.xpath(
                        """count(./Streams/Stream[@type="%s"][@lang="%s"])""" %
                    ("audio", "jpn")) > 0 and map.xpath(
                        """count(./Streams/Stream[@type="%s"][@lang="%s"])""" %
                        ("subtitle", "eng")
                    ) > 0 and not "English Subbed" in metadata.collections:
                    metadata.collections.add("English Subbed")
                    streamTag.append("English Subbed")
                logging.Log_Milestone("MapMedia_Episode_S" + season + "E" +
                                      episode)
Exemple #8
0
def MapMedia(root, metadata, anidbId, tvdbId):
    logging.Log_Milestone("MapMedia")
    streamTag = []
    seasonNo = 0
    seasonMap = root.xpath("""./Season[@AnidbId="%s" and @num!="0"]""" %
                           (anidbId))
    if not seasonMap:
        seasonMap = root.xpath("""./Season[@TvdbId="%s" and @num!="0"]""" %
                               (tvdbId))
    if seasonMap:
        seasonMap = seasonMap[0]
        seasonNo = int(seasonMap.get("num"))

    #Log("Populate Season")
    logging.Log_Milestone("MapMedia_Season")
    metadata.title = functions.PopulateMetadata(
        seasonMap.xpath("""./Title/*[node()]"""), str,
        constants.SERIES_TITLE_PRIORITY)
    metadata.summary = functions.PopulateMetadata(
        seasonMap.xpath("""./Summary/*[node()]"""), str,
        constants.SERIES_SUMMARY_PRIORITY)
    metadata.originally_available_at = functions.PopulateMetadata(
        seasonMap.xpath("""./Originally_Available_At/*[node()]"""),
        datetime.date, constants.SERIES_ORIGINALLYAVAILABLEAT_PRIORITY)
    metadata.rating = functions.PopulateMetadata(
        seasonMap.xpath("""./Rating/*[node()]"""), float,
        constants.SERIES_RATING_PRIORITY)
    metadata.studio = functions.PopulateMetadata(
        seasonMap.xpath("""./Studio/*[node()]"""), str,
        constants.SERIES_STUDIO_PRIORITY)
    functions.PopulateMetadata(seasonMap.xpath("""./Countries/*[node()]"""),
                               list, constants.SERIES_COUNTRIES_PRIORITY,
                               metadata.countries)
    metadata.duration = functions.PopulateMetadata(
        seasonMap.xpath("""./Duration/*[node()]"""), int,
        constants.SERIES_DURATION_PRIORITY)
    functions.PopulateMetadata(seasonMap.xpath("""./Genres/*[node()]"""), list,
                               constants.SERIES_GENRES_PRIORITY,
                               metadata.genres)
    functions.PopulateMetadata(seasonMap.xpath("""./Tags/*[node()]"""), list,
                               constants.SERIES_TAGS_PRIORITY, metadata.tags)
    functions.PopulateMetadata(seasonMap.xpath("""./Collections/*[node()]"""),
                               list, constants.SERIES_COLLECTIONS_PRIORITY,
                               metadata.collections)
    metadata.content_rating = functions.PopulateMetadata(
        seasonMap.xpath("""./Content_Rating/*[node()]"""), str,
        constants.SERIES_CONTENTRATING_PRIORITY)
    functions.PopulateMetadata(seasonMap.xpath("""./Roles/*[node()]"""),
                               Framework.modelling.attributes.SetObject,
                               constants.SERIES_ROLES_PRIORITY, metadata.roles)
    functions.PopulateMetadata(
        seasonMap.xpath("""./Posters//Image"""),
        Framework.modelling.attributes.ProxyContainerObject,
        constants.SERIES_IMAGES_PRIORITY, metadata.posters, "Images")
    functions.PopulateMetadata(
        seasonMap.xpath("""./Art//Image"""),
        Framework.modelling.attributes.ProxyContainerObject,
        constants.SERIES_IMAGES_PRIORITY, metadata.art, "Images")
    functions.PopulateMetadata(
        seasonMap.xpath("""./Banners//Image"""),
        Framework.modelling.attributes.ProxyContainerObject,
        constants.SERIES_IMAGES_PRIORITY, metadata.banners, "Images")
    functions.PopulateMetadata(
        seasonMap.xpath("""./Season//Image"""),
        Framework.modelling.attributes.ProxyContainerObject,
        constants.SERIES_IMAGES_PRIORITY, metadata.seasons, "Images")
    functions.PopulateMetadata(
        seasonMap.xpath("""./Themes//Theme"""),
        Framework.modelling.attributes.ProxyContainerObject,
        constants.SERIES_THEMES_PRIORITY, metadata.themes, "Themes")
    logging.Log_Milestone("MapMedia_Season")

    @parallelize
    def Episode_Par():
        for map in sorted(root.xpath(
                """./Season[@num>=%s or @num=0]/Episode""" % (seasonNo)),
                          key=lambda x: x.getparent().get("num"),
                          reverse=False):

            @task
            def Episode_Task(map=map,
                             metadata=metadata,
                             anidbId=anidbId,
                             tvdbId=tvdbId,
                             seasonNo=seasonNo):
                season = str(int(map.getparent().get('num')) - seasonNo + 1)
                #Log("SeasonNumber: %s, %s, %s" % (seasonNo, map.getparent().get('num'), str(int(map.getparent().get('num')) - seasonNo + 1)))
                episode = map.get('num')
                #Log("Episode: '%s', '%s', %s, %s" % (season, episode, anidbId, map.getparent().get('AnidbId')))

                logging.Log_Milestone("MapMedia_Episode_S" + season + "E" +
                                      episode)
                metadata.seasons[season].episodes[
                    episode].title = functions.PopulateMetadata(
                        map.xpath("""./Title/*[node()]"""), str,
                        constants.EPISODE_TITLE_PRIORITY, None, "EpisodeTitle")
                metadata.seasons[season].episodes[
                    episode].summary = functions.PopulateMetadata(
                        map.xpath("""./Summary/*[node()]"""), str,
                        constants.EPISODE_SUMMARY_PRIORITY)
                metadata.seasons[season].episodes[
                    episode].originally_available_at = functions.PopulateMetadata(
                        map.xpath("""./Originally_Available_At/*[node()]"""),
                        datetime.date,
                        constants.EPISODE_ORIGINALLYAVAILABLEAT_PRIORITY)
                metadata.seasons[season].episodes[
                    episode].rating = functions.PopulateMetadata(
                        map.xpath("""./Rating/*[node()]"""), float,
                        constants.EPISODE_RATING_PRIORITY)
                metadata.seasons[season].episodes[
                    episode].absolute_index = functions.PopulateMetadata(
                        map.xpath("""./Absolute_Index/*[node()]"""), int,
                        constants.EPISODE_ABSOLUTE_INDEX_PRIORITY)

                functions.PopulateMetadata(
                    map.xpath("""./Writers/*[node()]"""),
                    Framework.modelling.attributes.SetObject,
                    constants.EPISODE_WRITERS_PRIORITY,
                    metadata.seasons[season].episodes[episode].writers)
                functions.PopulateMetadata(
                    map.xpath("""./Directors/*[node()]"""),
                    Framework.modelling.attributes.SetObject,
                    constants.EPISODE_DIRECTORS_PRIORITY,
                    metadata.seasons[season].episodes[episode].directors)
                functions.PopulateMetadata(
                    map.xpath("""./Producers/*[node()]"""),
                    Framework.modelling.attributes.SetObject,
                    constants.EPISODE_PRODUCERS_PRIORITY,
                    metadata.seasons[season].episodes[episode].producers)
                functions.PopulateMetadata(
                    map.xpath("""./Thumbs//Image"""),
                    Framework.modelling.attributes.ProxyContainerObject,
                    constants.EPISODE_THUMBS_PRIORITY,
                    metadata.seasons[season].episodes[episode].thumbs,
                    "Images")
                if map.xpath(
                        """count(./Streams/Stream[@type="%s"][@lang="%s"])""" %
                    ("audio", "eng")
                ) > 0 and not "English Dubbed" in metadata.collections:
                    metadata.collections.add("English Dubbed")
                    streamTag.append("English Dubbed")
                if map.xpath(
                        """count(./Streams/Stream[@type="%s"][@lang="%s"])""" %
                    ("audio", "jpn")) > 0 and map.xpath(
                        """count(./Streams/Stream[@type="%s"][@lang="%s"])""" %
                        ("subtitle", "eng")
                    ) > 0 and not "English Subbed" in metadata.collections:
                    metadata.collections.add("English Subbed")
                    streamTag.append("English Subbed")
                logging.Log_Milestone("MapMedia_Episode_S" + season + "E" +
                                      episode)

    logging.Log_Milestone("MapMedia")
Exemple #9
0
def MapMeta(root):
    logging.Log_Milestone("MapMeta")
    providerList = [["Anidb"], ["Tvdb", "Plex"]]

    @parallelize
    def Providers_Par():
        for providers in providerList:

            @task
            def Providers_Task(root=root, providers=providers):
                @parallelize
                def Provider_Par():
                    for provider in providers:

                        @task
                        def Provider_Task(root=root,
                                          providers=providers,
                                          provider=provider):
                            #Log("Provider: %s" %(providers))
                            data = None
                            for map in sorted(
                                    root.xpath(
                                        """./Season/Episode/Mapped/%s""" %
                                        (providers[0].lower())),
                                    key=lambda x: int(
                                        x.get("series") if x.get("series") and
                                        x.get("series") != "None" else 0)):
                                if map.get("series"):
                                    for existing in map.getparent().getparent(
                                    ).xpath(""".//%s""" % (providers[0])):
                                        if not existing.getparent(
                                        ).tag == "Mapped":
                                            existing.getparent().remove(
                                                existing)

                                    #Log("Provider: %s" %(provider))
                                    if data == None or data.ID != map.get(
                                            "series"
                                    ) or data.MetaType != provider:
                                        if provider == "Anidb":
                                            data = anidb.AniDB(
                                                map.get("series"))
                                        elif provider == "Tvdb":
                                            data = tvdb.TvDB(map.get("series"))
                                        elif provider == "Plex":
                                            data = plex.Plex(map.get("series"))
                                    if not map.getparent().getparent(
                                    ).getparent().get("%s" % provider + "Id"):
                                        map.getparent().getparent().getparent(
                                        ).attrib["%s" % provider +
                                                 "Id"] = map.get("series")

                                    for attrib in constants.SeriesAttribs:
                                        if not map.getparent().getparent(
                                        ).getparent().xpath(
                                                """./%s/%s""" %
                                            (attrib, provider)):
                                            #Log("Provider: %s %s" %(provider, attrib))
                                            if getattr(data, attrib):
                                                if type(getattr(
                                                        data, attrib)) is type(
                                                            Element("None")):
                                                    elementList = copy.deepcopy(
                                                        getattr(data, attrib))
                                                    SubElement(
                                                        map.getparent().
                                                        getparent().getparent(
                                                        ).find("""./%s""" %
                                                               (attrib)),
                                                        provider).extend(
                                                            elementList.
                                                            getchildren())
                                                else:
                                                    elementItem = copy.copy(
                                                        getattr(data, attrib))
                                                    SubElement(
                                                        map.getparent().
                                                        getparent().getparent(
                                                        ).find("""./%s""" %
                                                               (attrib)),
                                                        provider).text = (
                                                            u'%s' %
                                                            (elementItem))

                                    for episode in data.Episodes:
                                        if (
                                                providers[0] == "Anidb"
                                                and "%s" % (episode.Number)
                                                == map.get("episode")
                                        ) or (providers[0] == "Tvdb"
                                              and "S%sE%s" %
                                              (episode.Season, episode.Number)
                                              == map.get("episode")):
                                            for attrib in constants.EpisodeAttribs:
                                                #Log("Provider: %s %s" %(provider, attrib))
                                                if getattr(episode, attrib):
                                                    if type(
                                                            getattr(
                                                                episode,
                                                                attrib)
                                                    ) is type(Element("None")):
                                                        elementList = copy.deepcopy(
                                                            getattr(
                                                                episode,
                                                                attrib))
                                                        SubElement(
                                                            map.getparent(
                                                            ).getparent().find(
                                                                """./%s""" %
                                                                (attrib)),
                                                            provider).extend(
                                                                elementList)
                                                    else:
                                                        elementItem = copy.copy(
                                                            getattr(
                                                                episode,
                                                                attrib))
                                                        SubElement(
                                                            map.getparent(
                                                            ).getparent().find(
                                                                """./%s""" %
                                                                (attrib)),
                                                            provider).text = (
                                                                u'%s' %
                                                                (elementItem))

    logging.Log_Milestone("MapMeta")
Exemple #10
0
def MapSeries(mappingData):
    #logging.Log_Milestone("MapSeries")
    root = None
    existing = None
    #existing = functions.LoadFile(mappingData.FirstSeries + ".bundle.xml", "Bundles")
    if existing:
        #for item in media.
        #SearchMap(season, episode, filename, root, anidbid=None)
        root = XML.ElementFromString(existing)

    if not root:
        root = etree.tostring(E.Series(),
                              pretty_print=True,
                              xml_declaration=True,
                              encoding="UTF-8")
        root = XML.ElementFromString(root)

    if not existing:
        Log.Debug("Common - MapSeries() - Generate Bundle %s" %
                  (len(mappingData.SeriesList)))
        mapping = SubElement(root, "Mapping")
        openingEpsNo = 101
        endingEpsNo = 151
        for item in mappingData.SeriesList if mappingData.SeriesList else []:
            ScudLee = scudlee.ScudLee()
            ScudLee.Load(item)
            AniDB = None
            AniDB = anidb.AniDB(ScudLee.AnidbId)
            Log.Debug(
                "Common - MapSeries() - AniDB ID: '%s', mappingcount: '%s', episodecount: '%s', specialCount: '%s', opCount: '%s', edCount: '%s'"
                % (AniDB.ID, len(ScudLee.MappingList), AniDB.EpisodeCount,
                   AniDB.SpecialCount, len(AniDB.OpList), len(AniDB.EdList)))

            seriesMap = SubElement(mapping,
                                   "Series",
                                   anidbid=str(ScudLee.AnidbId),
                                   tvdbid=str(ScudLee.TvdbId),
                                   episodeoffset=str(ScudLee.EpisodeOffset),
                                   absolute=str(ScudLee.Absolute))

            for season in ScudLee.MappingList:
                Log("Common - MapSeries() - Season - AniDB: '%s', TvDB: '%s', Text: '%s'"
                    % (season.AnidbSeason, season.TvdbSeason, season.Text))
                if season.Offset:
                    for i in range(season.Start, season.End + 1):
                        status = "scudlee missing"
                        tvdbParse = tvdb.ParseNoFromSeason(
                            0, 0, ScudLee.DefaultTvdbSeason)
                        if not mapping.xpath(
                                """./Series/Episode[@tvdb="S%sE%s"]""" %
                            (season.TvdbSeason, str(i + int(season.Offset)))):
                            status = ""
                            tvdbParse = tvdb.ParseNoFromSeason(
                                int(season.TvdbSeason), i + int(season.Offset),
                                ScudLee.DefaultTvdbSeason)
                        SubElement(seriesMap,
                                   "Episode",
                                   anidb="%s" % (anidb.ParseNoFromSeason(
                                       int(season.AnidbSeason), i)),
                                   tvdb=tvdbParse,
                                   status=status)
                        Log("Common - MapSeries() - Season - AniDB: '%s', TvDB: '%s'"
                            % (anidb.ParseNoFromSeason(int(season.AnidbSeason),
                                                       i), tvdbParse))

                if season.Text != None:
                    for string in filter(None, season.Text.split(";")):
                        for i in range(0,
                                       len(string.split("-")[1].split("+"))):
                            status = "scudlee missing"
                            tvdbParse = tvdb.ParseNoFromSeason(
                                0, 0, ScudLee.DefaultTvdbSeason)
                            if not mapping.xpath(
                                    """./Series/Episode[@tvdb="S%sE%s"]""" %
                                (season.TvdbSeason, string.split("-")
                                 [1].split("+")[i].zfill(2))) and "S%sE%s" % (
                                     season.TvdbSeason, string.split("-")
                                     [1].split("+")[i].zfill(2)) != "S00E00":
                                status = ""
                                tvdbParse = tvdb.ParseNoFromSeason(
                                    int(season.TvdbSeason),
                                    int(string.split("-")[1].split("+")[i]),
                                    ScudLee.DefaultTvdbSeason)
                            elif not mapping.xpath(
                                    """./Series/Episode[@tvdb="S%sE%s"]""" %
                                (season.TvdbSeason,
                                 string.split("-")[1].split("+")[i].zfill(2))):
                                status = "tvdb missing"
                            SubElement(seriesMap,
                                       "Episode",
                                       anidb="%s" % (anidb.ParseNoFromSeason(
                                           int(season.AnidbSeason),
                                           string.split("-")[0])),
                                       tvdb=tvdbParse,
                                       status=status)
                            Log("Common - MapSeries() - Season - AniDB: '%s', TvDB: '%s'"
                                % (anidb.ParseNoFromSeason(
                                    int(season.AnidbSeason),
                                    string.split("-")[0]), tvdbParse))

            if not ScudLee.Absolute:
                for i in range(1, AniDB.EpisodeCount + 1):
                    status = "scudlee missing"
                    tvdbParse = "S00E00"
                    if not seriesMap.xpath("""./Episode[@anidb="%s"]""" %
                                           (anidb.ParseNoFromSeason(1, i))):
                        if not mapping.xpath(
                                """./Series/Episode[@tvdb="S%sE%s"]""" %
                            (str(ScudLee.DefaultTvdbSeason).zfill(2),
                             'S' + str(i + ScudLee.EpisodeOffset).zfill(2))):
                            status = ""
                            tvdbParse = "S%sE%s" % (
                                str(ScudLee.DefaultTvdbSeason).zfill(2),
                                str(i + ScudLee.EpisodeOffset).zfill(2))
                        SubElement(seriesMap,
                                   "Episode",
                                   anidb="%s" %
                                   (anidb.ParseNoFromSeason(1, i)),
                                   tvdb=tvdbParse,
                                   status=status)
                        Log("Common - MapSeries() - Season - AniDB: '%s', TvDB: '%s'"
                            % (anidb.ParseNoFromSeason(1, i), tvdbParse))

                for i in range(1, AniDB.SpecialCount + 1):
                    status = "scudlee missing"
                    tvdbParse = "S00E00"
                    if not seriesMap.xpath("""./Episode[@anidb="%s"]""" %
                                           (anidb.ParseNoFromType(2, i))):
                        if not mapping.xpath(
                                """./Series/Episode[@tvdb="S%sE%s"]""" %
                            ("00", str(i + ScudLee.EpisodeOffset).zfill(2))):
                            status = ""
                            tvdbParse = "S%sE%s" % (
                                "00", str(i + ScudLee.EpisodeOffset).zfill(2))
                        SubElement(seriesMap,
                                   "Episode",
                                   anidb="%s" % (anidb.ParseNoFromType(2, i)),
                                   tvdb=tvdbParse,
                                   status=status)
                        Log("Common - MapSeries() - Season - AniDB: '%s', TvDB: '%s'"
                            % (anidb.ParseNoFromType(2, i), tvdbParse))

                for opening in AniDB.OpList:
                    if not seriesMap.xpath("""./Episode[@anidb="%s"]""" %
                                           (opening)):
                        SubElement(seriesMap,
                                   "Episode",
                                   anidb="%s" % (opening),
                                   tvdb="%s" % (anidb.ParseLocalNoFromType(
                                       3, openingEpsNo, "op")),
                                   status="")
                        openingEpsNo = openingEpsNo + 1

                for ending in AniDB.EdList:
                    if not seriesMap.xpath("""./Episode[@anidb="%s"]""" %
                                           (ending)):
                        SubElement(
                            seriesMap,
                            "Episode",
                            anidb="%s" % (ending),
                            tvdb="%s" %
                            (anidb.ParseLocalNoFromType(3, endingEpsNo, "ed")),
                            status="")
                        endingEpsNo = endingEpsNo + 1
            else:
                TvDB = tvdb.TvDB(ScudLee.TvdbId)
                for episode in TvDB.Episodes if TvDB.Episodes else []:
                    if episode.Absolute_Index:
                        if episode.Absolute_Index > ScudLee.EpisodeOffset and episode.Absolute_Index <= AniDB.EpisodeCount + ScudLee.EpisodeOffset:
                            SubElement(seriesMap,
                                       "Episode",
                                       anidb="%s" % (anidb.ParseNoFromSeason(
                                           1, episode.Absolute_Index -
                                           ScudLee.EpisodeOffset)),
                                       tvdb="S%sE%s" %
                                       (episode.Season, episode.Number),
                                       status="")
                        Log("Common - MapSeries() - Season - AniDB: '%s', TvDB: 'S%sE%s'"
                            % (anidb.ParseNoFromSeason(
                                1, episode.Absolute_Index -
                                ScudLee.EpisodeOffset), episode.Season,
                               episode.Number))

            seriesMap[:] = sorted(
                seriesMap,
                key=lambda x: (0
                               if re.sub('[^A-Z]', '', x.get("anidb")) else 1,
                               int(re.sub('[^0-9]', '', x.get("anidb")))))

        unmappedlist = sorted(mapping.xpath(
            """./Series/Episode[@tvdb="S00E00" and @missing!=""]"""),
                              key=lambda x: x.getparent().get("anidbid"))
        if unmappedlist:
            unmapped = SubElement(mapping, "Unmapped")
            i = 1
            for episode in unmappedlist:
                Log("Common - MapSeries() - Unmapped: '%s', '%s' , '%s'" %
                    (episode.getparent().get("anidbid"), episode.get("anidb"),
                     episode.get("missing")))
                SubElement(unmapped,
                           "Episode",
                           anidbid=episode.getparent().get("anidbid"),
                           anidb=episode.get("anidb"),
                           missing=episode.get("missing"),
                           id=str(i))
                i = i + 1
    logging.Log_Milestone("MapSeries")
    return root
Exemple #11
0
    def search(self, results, media, lang, manual=False):
        Log.Debug(
            "--- Search Begin -------------------------------------------------------------------------------------------"
        )
        logging.New_Milestones()
        logging.Log_Milestone("WholeSearch")
        common.RefreshData()
        orig_title = media.show
        if orig_title.startswith("clear-cache"): HTTP.ClearCache()
        Log.Info(
            "Init - Search() - Show: '%s', Title: '%s', name: '%s', filename: '%s', manual:'%s'"
            %
            (media.show, orig_title, media.name, urllib.unquote(media.filename)
             if media.filename else "", str(manual)))

        match = re.search(
            "(?P<show>.*?) ?\[(?P<source>(.*))-(tt)?(?P<id>[0-9]{1,7})\]",
            orig_title, re.IGNORECASE)
        if match:
            title = match.group("show")
            source = match.group("source").lower()
            if source in [
                    "anidb", "anidb2", "tvdb", "tvdb2", "tvdb3", "tvdb4",
                    "tvdb5"
            ]:
                id = match.group("id")
                startdate = None
                if source in ["anidb", "anidb2"]:
                    title = functions.GetPreferedTitle(
                        common.GetAnimeTitleByID(id))
                Log.Debug(
                    "Init - Search() - force - id: '%s-%s', title from id: '%s' provided in foldername: '%s'"
                    % (source, id, title, orig_title))
                results.Append(
                    MetadataSearchResult(id="%s-%s" % (source, id),
                                         name=title,
                                         year=startdate,
                                         lang=Locale.Language.English,
                                         score=100))
                return
            else:
                orig_title = functions.CleanTitle(title)

        maxi = {}
        elite = []
        perfectScore = []
        orig_title = functions.CleanTitle(orig_title)

        @parallelize
        def searchTitles():
            for anime in common.GetAnimeTitleByName(orig_title):

                @task
                def scoreTitle(anime=anime,
                               maxi=maxi,
                               anidb=anidb,
                               perfectScore=perfectScore):
                    logging.Log_Milestone("Title")
                    anime = Titles(anime, orig_title)
                    logging.Log_Milestone("Title")
                    isValid = True
                    if (anime.Id in maxi
                            and maxi[anime.Id] <= anime.Score) or (not anime.Id
                                                                   in maxi):
                        maxi[anime.Id] = anime.Score
                    else:
                        isValid = False
                    if isValid:
                        startdate = None
                        if (media.year and anime.Score >= 90):
                            show = anidb.AniDB(anime.Id)
                            if show:
                                try:
                                    startdate = dateParse(
                                        show.Originally_Available_At).year
                                except:
                                    pass
                                if str(startdate) != str(media.year):
                                    isValid = False
                                Log.Debug(
                                    "Init - Search() - date: '%s', aired: '%s'"
                                    % (media.year, startdate))
                            elite.append(isValid)
                        elif anime.Score >= 90:
                            elite.append(isValid)
                        if isValid:
                            if anime.Score == 100:
                                perfectScore.append(anime.Id)
                            Log.Debug(
                                "Init - Search() - find - id: '%s-%s', title: '%s', score: '%s'"
                                %
                                ("anidb", anime.Id, anime.Title, anime.Score))
                            results.Append(
                                MetadataSearchResult(
                                    id="%s-%s" % ("anidb", anime.Id),
                                    name="%s [%s-%s]" %
                                    (anime.Title, "anidb", anime.Id),
                                    year=startdate,
                                    lang=Locale.Language.English,
                                    score=anime.Score))

        if len(list(set(perfectScore))) > 1:
            for result in results:
                if result.score == 100:
                    show = anidb.AniDB(result.id.split("-")[1])
                    if show.Type != "TV Series":
                        result.score = result.score - 1

        if len(elite) > 0 and not True in elite: del results[:]
        results.Sort("score", descending=True)
        logging.Log_Milestone("WholeSearch")
        return