Ejemplo n.º 1
0
    def from_id(cls, tv_id):
        result = sql_to_dict(cls.__database__,
                             "select * from tv_shows where id=?", (tv_id, ))
        if result:
            return cls(**result[0])

        raise exceptions.EpisodeNotFound("ID not found in TV shows table")
Ejemplo n.º 2
0
    def from_query(cls, query: str):
        """Find a TV Show by query (fuzzy search).

        :param query:
        :type query: str
        :param raise_resting: raise exceptions.RestingMovie or not
        :raises:
            exceptions.EpisodeNotFound
        """
        query = query.lower().strip()
        item_list = sql_to_dict(cls.__database__, "select * from tv_shows")

        # We use loops for year and og_title matching
        initial = 0
        final_list = []
        for item in item_list:
            fuzzy = fuzz.ratio(query, item["name"].lower())

            if fuzzy > initial:
                initial = fuzzy
                final_list.append(item)

        item = final_list[-1]

        if initial < 77:
            raise exceptions.EpisodeNotFound(
                f'TV Show not found: "{query}". Maybe you meant "{item["name"]}"? '
                f"Explore the collection: {WEBSITE}.")

        return cls(**item)
Ejemplo n.º 3
0
    def from_id(cls, id_: int):
        episode = sql_to_dict(cls.__database__,
                              "select * from episodes where id=?", (id_, ))
        if not episode:
            raise exceptions.EpisodeNotFound(
                f"ID not found in database: {id_}")

        return cls(**episode[0])
Ejemplo n.º 4
0
    def from_query(cls, query: str):
        """
        :param query:
        :type query: str
        :raises exceptions.EpisodeNotFound
        """
        season, episode = get_episode_tuple(query)
        tv_show = TVShow.from_query(query[:-6])
        result = sql_to_dict(
            cls.__database__,
            "select * from episodes where (tv_show_id=? and season=? and episode=?)",
            (
                tv_show.id,
                season,
                episode,
            ),
        )
        if result:
            return cls(_tv_show=tv_show, **result[0])

        raise exceptions.EpisodeNotFound(f"Episode not found: {query}")