Exemple #1
0
    def __init__(self):
        self.access_token = None
        self.refresh_token = None
        self.token_expires = 0
        self.username = None
        self._load_settings()
        self.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
        self.try_refresh_token()
        self.language = g.get_language_code()
        self.country = g.get_language_code(True).split("-")[-1].lower()

        self.TranslationNormalization = [
            ("title", ("title", "originaltitle", "sorttitle"), None),
            ("language", "language", None),
            ("overview", ("plot", "plotoutline"), None),
        ]

        self.UserRatingNormalization = [(
            "rating",
            "user_rating",
            lambda t: tools.safe_round(tools.get_clean_number(t), 2),
        ), ("rated_at", "rated_at", lambda t: g.validate_date(t))]

        self.PlayBackNormalization = [("progress", "percentplayed", None),
                                      ("paused_at", "paused_at",
                                       lambda t: g.validate_date(t)),
                                      ("id", "playback_id", None)]

        self.PlayBackHistoryNormalization = [("action", "action", None),
                                             ("watched_at", "watched_at",
                                              lambda t: g.validate_date(t)),
                                             ("id", "playback_id", None)]

        self.CalendarNormalization = [("first_aired", "first_aired",
                                       lambda t: g.validate_date(t))]

        self.Normalization = tools.extend_array(
            [("certification", "mpaa", None), ("genres", "genre", None),
             (("ids", "imdb"), ("imdbnumber", "imdb_id"), None),
             (("ids", "trakt"), "trakt_id", None),
             (("ids", "slug"), "trakt_slug", None),
             (("ids", "tvdb"), "tvdb_id", None),
             (("ids", "tmdb"), "tmdb_id", None),
             ("playback_id", "playback_id", None),
             (("show", "ids", "trakt"), "trakt_show_id", None),
             ("network", "studio", lambda n: [n]),
             ("runtime", "duration", lambda d: d * 60),
             ("progress", "percentplayed", None),
             ("percentplayed", "percentplayed", None),
             ("updated_at", "dateadded", lambda t: g.validate_date(t)),
             ("last_updated_at", "dateadded", lambda t: g.validate_date(t)),
             ("last_watched_at", "last_watched_at",
              lambda t: g.validate_date(t)),
             ("watched_at", "watched_at", lambda t: g.validate_date(t)),
             ("paused_at", "paused_at", lambda t: g.validate_date(t)),
             (
                 "rating",
                 "rating",
                 lambda t: tools.safe_round(tools.get_clean_number(t), 2),
             ), ("votes", "votes", lambda t: tools.get_clean_number(t)),
             (
                 None,
                 "rating.trakt",
                 (
                     ("rating", "votes"),
                     lambda r, v: {
                         "rating": tools.safe_round(tools.get_clean_number(r),
                                                    2),
                         "votes": tools.get_clean_number(v),
                     },
                 ),
             ), ("tagline", "tagline", None),
             (
                 "trailer",
                 "trailer",
                 lambda t: tools.youtube_url.format(t.split("?v=")[-1])
                 if t else None,
             ),
             ("type", "mediatype", lambda t: t
              if "show" not in t else "tvshow"),
             ("available_translations", "available_translations", None),
             ("score", "score", None), ("action", "action", None),
             ("added", "added", None), ("rank", "rank", None),
             ("listed_at", "listed_at", None),
             (
                 "country",
                 "country_origin",
                 lambda t: t.upper() if t is not None else None,
             ), ("user_rating", "user_rating", None),
             ("rated_at", "rated_at", None)],
            self.TranslationNormalization,
        )

        self.MoviesNormalization = tools.extend_array(
            [
                ("plays", "playcount", None),
                ("year", "year", None),
                ("released",
                 ("premiered", "aired"), lambda t: g.validate_date(t)),
                ("collected_at", "collected_at", lambda t: g.validate_date(t)),
            ],
            self.Normalization,
        )

        self.ShowNormalization = tools.extend_array(
            [("status", "status", None),
             ("status", "is_airing", lambda t: not t == "ended"),
             ("title", "tvshowtitle", None),
             ("first_aired", "year", lambda t: g.validate_date(t)[:4]
              if g.validate_date(t) else None),
             (
                 "first_aired",
                 ("premiered", "aired"),
                 lambda t: g.validate_date(t),
             ),
             ("last_collected_at", "last_collected_at",
              lambda t: g.validate_date(t))], self.Normalization)

        self.SeasonNormalization = tools.extend_array(
            [("number", ("season", "sortseason"), None),
             ("episode_count", "episode_count", None),
             ("aired_episodes", "aired_episodes", None),
             ("first_aired", "year", lambda t: g.validate_date(t)[:4]
              if g.validate_date(t) else None),
             (
                 "first_aired",
                 ("premiered", "aired"),
                 lambda t: g.validate_date(t),
             ),
             ("last_collected_at", "last_collected_at",
              lambda t: g.validate_date(t))],
            self.Normalization,
        )

        self.EpisodeNormalization = tools.extend_array(
            [("number", ("episode", "sortepisode"), None),
             ("season", ("season", "sortseason"), None),
             ("collected_at", "collected", lambda t: 1),
             ("plays", "playcount", None),
             ("first_aired", "year", lambda t: g.validate_date(t)[:4]
              if g.validate_date(t) else None),
             (
                 "first_aired",
                 ("premiered", "aired"),
                 lambda t: g.validate_date(t),
             ),
             ("collected_at", "collected_at", lambda t: g.validate_date(t))],
            self.Normalization,
        )

        self.ListNormalization = [
            ("updated_at", "dateadded", lambda t: g.validate_date(t)),
            (("ids", "trakt"), "trakt_id", None),
            (("ids", "slug"), "slug", None),
            ("sort_by", "sort_by", None),
            ("sort_how", "sort_how", None),
            (("user", "ids", "slug"), "username", None),
            ("name", ("name", "title"), None),
            ("type", "mediatype", None),
        ]

        self.MixedEpisodeNormalization = [
            (("show", "ids", "trakt"), "trakt_show_id", None),
            (("episode", "ids", "trakt"), "trakt_id", None)
        ]

        self.MixedSeasonNormalization = [
            (("show", "ids", "trakt"), "trakt_show_id", None),
            (("season", "ids", "trakt"), "trakt_id", None)
        ]

        self.MetaNormalization = {
            "movie": self.MoviesNormalization,
            "list": self.ListNormalization,
            "show": self.ShowNormalization,
            "season": self.SeasonNormalization,
            "episode": self.EpisodeNormalization,
            "mixedepisode": self.MixedEpisodeNormalization,
            "mixedseason": self.MixedSeasonNormalization,
            "playback": self.PlayBackNormalization,
            "playbackhistory": self.PlayBackHistoryNormalization,
            "user_rating": self.UserRatingNormalization,
            "calendar": self.CalendarNormalization
        }

        self.MetaObjects = ("movie", "tvshow", "show", "season", "episode",
                            "list")

        self.MetaCollections = ("movies", "shows", "seasons", "episodes",
                                "cast")
Exemple #2
0
    def __init__(self):
        self.api_key = g.get_setting("omdb.apikey", None)
        self.omdb_support = False if not self.api_key else True
        self.meta_hash = tools.md5_hash((self.omdb_support, self.ApiUrl))

        self.normalization = [
            (
                "@title",
                ("title", "sorttitle"),
                lambda d: d if not self._is_value_none(d) else None,
            ),
            ("@rated", "mpaa", lambda d: d
             if not self._is_value_none(d) else None),
            (
                "@released",
                ("premiered", "aired"),
                lambda d: g.validate_date(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@runtime",
                "duration",
                lambda d: int(d[:-4]) * 60 if not self._is_value_none(d) and
                len(d) > 4 and d[:-4].isdigit() else None,
            ),
            (
                "@genre",
                "genre",
                lambda d: sorted(
                    OrderedDict.fromkeys({x.strip()
                                          for x in d.split(",")}))
                if not self._is_value_none(d) else None,
            ),
            (
                "@director",
                "director",
                lambda d: sorted(
                    OrderedDict.fromkeys({
                        re.sub(r"\(.*?\)", "", x).strip()
                        for x in d.split(",")
                    })) if not self._is_value_none(d) else None,
            ),
            (
                "@writer",
                "writer",
                lambda d: sorted(
                    OrderedDict.fromkeys({
                        re.sub(r"\(.*?\)", "", x).strip()
                        for x in d.split(",")
                    })) if not self._is_value_none(d) else None,
            ),
            ("@plot", ("plot", "overview", "plotoutline"), None),
            (
                "@country",
                "country",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            ("@imdbID", ("imdbnumber", "imdb_id"), None),
            (
                None,
                "rating.imdb",
                (
                    ("@imdbRating", "@imdbVotes"),
                    lambda a, c: {
                        "rating": tools.safe_round(tools.get_clean_number(a), 2
                                                   ),
                        "votes": tools.get_clean_number(c),
                    } if not self._is_value_none(a) and not self.
                    _is_value_none(c) else None,
                ),
            ),
            (
                "@Production",
                "studio",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            ("@awards", "awards", lambda d: d
             if not self._is_value_none(d) else None),
            (
                "@awards",
                "oscar_wins",
                lambda d: self._extract_awards(d, ("Won", "Oscar")),
            ),
            (
                "@awards",
                "oscar_nominations",
                lambda d: self._extract_awards(d, ("Nominated for", "Oscar")),
            ),
            (
                "@awards",
                "award_wins",
                lambda d: self._extract_awards(d, ("Another", "wins"),
                                               ("", "wins")),
            ),
            (
                "@awards",
                "award_nominations",
                lambda d: self._extract_awards(d, ("wins &", "nominations"),
                                               ("", "nominations")),
            ),
            (
                "@metascore",
                "metacritic_rating",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoMeter",
                "rottentomatoes_rating",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoImage",
                "rottentomatoes_image",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoReviews",
                "rottentomatoes_reviewstotal",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoFresh",
                "rottentomatoes_reviewsfresh",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoRotten",
                "rottentomatoes_reviewsrotten",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoConsensus",
                "rottentomatoes_consensus",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoUserMeter",
                "rottentomatoes_usermeter",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoUserReviews",
                "rottentomatoes_userreviews",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
        ]

        self.session = requests.Session()
        retries = Retry(
            total=5,
            backoff_factor=0.1,
            status_forcelist=[500, 503, 504, 520, 521, 522, 524],
        )
        self.session.mount("https://", HTTPAdapter(max_retries=retries))
Exemple #3
0
    def __init__(self):
        self.api_key = g.get_setting("omdb.apikey", None)
        self.omdb_support = False if not self.api_key else True

        self.normalization = [
            (
                "@title",
                ("title", "sorttitle"),
                lambda d: d if not self._is_value_none(d) else None,
            ),
            ("@rated", "mpaa", lambda d: d
             if not self._is_value_none(d) else None),
            (
                "@released",
                ("premiered", "aired"),
                lambda d: g.validate_date(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@runtime",
                "duration",
                lambda d: int(d[:-4]) * 60 if not self._is_value_none(d) and
                len(d) > 4 and d[:-4].isdigit() else None,
            ),
            (
                "@genre",
                "genre",
                lambda d: sorted(set(x.strip() for x in d.split(",")))
                if not self._is_value_none(d) else None,
            ),
            (
                "@director",
                "director",
                lambda d: sorted(
                    set(
                        re.sub(r"\(.*?\)", "", x).strip()
                        for x in d.split(",")))
                if not self._is_value_none(d) else None,
            ),
            (
                "@writer",
                "writer",
                lambda d: sorted(
                    set(
                        re.sub(r"\(.*?\)", "", x).strip()
                        for x in d.split(",")))
                if not self._is_value_none(d) else None,
            ),
            ("@plot", ("plot", "overview", "plotoutline"), None),
            (
                "@country",
                "country",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            ("@imdbID", ("imdbnumber", "imdb_id"), None),
            (
                None,
                "rating.imdb",
                (
                    ("@imdbRating", "@imdbVotes"),
                    lambda a, c: {
                        "rating": tools.safe_round(tools.get_clean_number(a), 2
                                                   ),
                        "votes": tools.get_clean_number(c),
                    } if not self._is_value_none(a) and not self.
                    _is_value_none(c) else None,
                ),
            ),
            (
                "@Production",
                "studio",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            ("@awards", "awards", lambda d: d
             if not self._is_value_none(d) else None),
            (
                "@awards",
                "oscar_wins",
                lambda d: self._extract_awards(d, ("Won", "Oscar")),
            ),
            (
                "@awards",
                "oscar_nominations",
                lambda d: self._extract_awards(d, ("Nominated for", "Oscar")),
            ),
            (
                "@awards",
                "award_wins",
                lambda d: self._extract_awards(d, ("Another", "wins"),
                                               ("", "wins")),
            ),
            (
                "@awards",
                "award_nominations",
                lambda d: self._extract_awards(d, ("wins &", "nominations"),
                                               ("", "nominations")),
            ),
            (
                "@metascore",
                "metacritic_rating",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoMeter",
                "rottentomatoes_rating",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoImage",
                "rottentomatoes_image",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoReviews",
                "rottentomatoes_reviewstotal",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoFresh",
                "rottentomatoes_reviewsfresh",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoRotten",
                "rottentomatoes_reviewsrotten",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoConsensus",
                "rottentomatoes_consensus",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoUserMeter",
                "rottentomatoes_usermeter",
                lambda d: d if not self._is_value_none(d) else None,
            ),
            (
                "@tomatoUserReviews",
                "rottentomatoes_userreviews",
                lambda d: tools.get_clean_number(d)
                if not self._is_value_none(d) else None,
            ),
        ]