Esempio n. 1
0
 def add_edit(name,
              current_item,
              group,
              alias,
              key=None,
              value=None,
              var_type="str"):
     if value or name in alias:
         if value or group[alias[name]]:
             if key is None: key = name
             if value is None: value = group[alias[name]]
             try:
                 current = str(getattr(current_item, key, ""))
                 if var_type == "date":
                     final_value = util.validate_date(
                         value, name, return_as="%Y-%m-%d")
                     current = current[:-9]
                 elif var_type == "float":
                     final_value = util.parse(name,
                                              value,
                                              datatype="float",
                                              minimum=0,
                                              maximum=10)
                 else:
                     final_value = value
                 if current != str(final_value):
                     edits[f"{key}.value"] = final_value
                     edits[f"{key}.locked"] = 1
                     logger.info(
                         f"Detail: {name} updated to {final_value}")
             except Failed as ee:
                 logger.error(ee)
         else:
             logger.error(
                 f"Metadata Error: {name} attribute is blank")
Esempio n. 2
0
 def _discover(self, attrs, amount, is_movie):
     ids = []
     for date_attr in discover_dates:
         if date_attr in attrs:
             attrs[date_attr] = util.validate_date(
                 attrs[date_attr],
                 f"tmdb_discover attribute {date_attr}",
                 return_as="%Y-%m-%d")
     if self.config.trace_mode:
         logger.debug(f"Params: {attrs}")
     self.Discover.discover_movies(
         attrs) if is_movie else self.Discover.discover_tv_shows(attrs)
     total_pages = int(self.TMDb.total_pages)
     total_results = int(self.TMDb.total_results)
     amount = total_results if amount == 0 or total_results < amount else amount
     for x in range(total_pages):
         attrs["page"] = x + 1
         tmdb_items = self.Discover.discover_movies(
             attrs) if is_movie else self.Discover.discover_tv_shows(attrs)
         for tmdb_item in tmdb_items:
             try:
                 ids.append(
                     (tmdb_item.id, "tmdb" if is_movie else "tmdb_show"))
             except Failed as e:
                 logger.error(e)
             if len(ids) == amount: break
         if len(ids) == amount: break
     return ids, amount
Esempio n. 3
0
 def _search(self, **kwargs):
     media_vars = f"sort: {sort_options[kwargs['sort_by']]}, type: ANIME"
     variables = {"sort": sort_options[kwargs['sort_by']]}
     for key, value in kwargs.items():
         if key not in ["sort_by", "limit"]:
             if "." in key:
                 attr, mod = key.split(".")
             else:
                 attr = key
                 mod = ""
             ani_attr = attr_translation[
                 attr] if attr in attr_translation else attr
             final = ani_attr if attr in no_mod_searches else f"{ani_attr}_{mod_translation[mod]}"
             if attr in ["start", "end"]:
                 value = int(
                     util.validate_date(value,
                                        f"anilist_search {key}",
                                        return_as="%Y%m%d"))
             elif attr in [
                     "format", "status", "genre", "tag", "tag_category"
             ]:
                 temp_value = [
                     self.options[attr.replace(
                         '_', ' ').title()][v.lower().replace(
                             ' / ', '-').replace(' ', '-')] for v in value
                 ]
                 if attr in ["format", "status"]:
                     value = f"[{', '.join(temp_value)}]"
                 else:
                     temp = '", "'.join(temp_value)
                     value = f'["{temp}"]'
             elif attr in ["season", "source", "country"]:
                 value = self.options[attr.replace("_", " ").title()][value]
             if mod == "gte":
                 value -= 1
             elif mod == "lte":
                 value += 1
             media_vars += f", {final}: {value}"
     query = f"query ($page: Int) {{Page(page: $page){{pageInfo {{hasNextPage}}media({media_vars}){{id}}}}}}"
     logger.debug(query)
     return self._pagenation(query,
                             limit=kwargs["limit"],
                             variables=variables)
Esempio n. 4
0
 def get_tmdb_ids(self, method, data, is_movie):
     pretty = method.replace("_", " ").title().replace("Tmdb", "TMDb")
     media_type = "Movie" if is_movie else "Show"
     result_type = "tmdb" if is_movie else "tmdb_show"
     ids = []
     if method in ["tmdb_network", "tmdb_company", "tmdb_keyword"]:
         if method == "tmdb_company":
             item = self._company(int(data))
         elif method == "tmdb_network":
             item = self._network(int(data))
         else:
             item = self._keyword(int(data))
         results = item.movies if is_movie else item.tv_shows
         ids = [(i.id, result_type)
                for i in results.get_results(results.total_results)]
         logger.info(
             f"Processing {pretty}: ({data}) {item.name} ({len(results)} {media_type}{'' if len(results) == 1 else 's'})"
         )
     elif method == "tmdb_discover":
         attrs = data.copy()
         limit = int(attrs.pop("limit"))
         for date_attr in discover_dates:
             if date_attr in attrs:
                 attrs[date_attr] = util.validate_date(
                     attrs[date_attr],
                     f"tmdb_discover attribute {date_attr}",
                     return_as="%Y-%m-%d")
         if self.config.trace_mode:
             logger.debug(f"Params: {attrs}")
         results = self.TMDb.discover_movies(
             **attrs) if is_movie else self.TMDb.discover_tv_shows(**attrs)
         amount = results.total_results if limit == 0 or results.total_results < limit else limit
         ids = [(i.id, result_type) for i in results.get_results(amount)]
         logger.info(
             f"Processing {pretty}: {amount} {media_type}{'' if amount == 1 else 's'}"
         )
         for attr, value in attrs.items():
             logger.info(f"           {attr}: {value}")
     elif method in [
             "tmdb_popular", "tmdb_top_rated", "tmdb_now_playing",
             "tmdb_trending_daily", "tmdb_trending_weekly"
     ]:
         if method == "tmdb_popular":
             results = self.TMDb.popular_movies(
             ) if is_movie else self.TMDb.popular_tv()
         elif method == "tmdb_top_rated":
             results = self.TMDb.top_rated_movies(
             ) if is_movie else self.TMDb.top_rated_tv()
         elif method == "tmdb_now_playing":
             results = self.TMDb.now_playing_movies()
         else:
             results = self.TMDb.trending(
                 "movie" if is_movie else "tv",
                 "day" if method == "tmdb_trending_daily" else "week")
         ids = [(i.id, result_type) for i in results.get_results(data)]
         logger.info(
             f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}"
         )
     else:
         tmdb_id = int(data)
         if method == "tmdb_list":
             results = self.get_list(tmdb_id)
             tmdb_name = results.name
             ids = [(i.id, result_type)
                    for i in results.get_results(results.total_results)]
         elif method == "tmdb_movie":
             tmdb_name = self.get_movie(tmdb_id).title
             ids.append((tmdb_id, "tmdb"))
         elif method == "tmdb_collection":
             collection = self.get_collection(tmdb_id)
             tmdb_name = collection.name
             ids = [(t.id, "tmdb") for t in collection.movies]
         elif method == "tmdb_show":
             tmdb_name = self.get_show(tmdb_id).name
             ids.append((tmdb_id, "tmdb_show"))
         else:
             person = self.get_person(tmdb_id,
                                      partial="movie_credits,tv_credits")
             tmdb_name = person.name
             if method == "tmdb_actor":
                 ids = [(i.movie.id, "tmdb") for i in person.movie_cast]
                 ids.extend([(i.tv_show.id, "tmdb_show")
                             for i in person.tv_cast])
             elif method == "tmdb_crew":
                 ids = [(i.movie.id, "tmdb") for i in person.movie_crew]
                 ids.extend([(i.tv_show.id, "tmdb_show")
                             for i in person.tv_crew])
             elif method == "tmdb_director":
                 ids = [(i.movie.id, "tmdb") for i in person.movie_crew
                        if i.department == "Directing"]
                 ids.extend([(i.tv_show.id, "tmdb_show")
                             for i in person.tv_crew
                             if i.department == "Directing"])
             elif method == "tmdb_writer":
                 ids = [(i.movie.id, "tmdb") for i in person.movie_crew
                        if i.department == "Writing"]
                 ids.extend([(i.tv_show.id, "tmdb_show")
                             for i in person.tv_crew
                             if i.department == "Writing"])
             elif method == "tmdb_producer":
                 ids = [(i.movie.id, "tmdb") for i in person.movie_crew
                        if i.department == "Production"]
                 ids.extend([(i.tv_show.id, "tmdb_show")
                             for i in person.tv_crew
                             if i.department == "Production"])
             else:
                 raise Failed(f"TMDb Error: Method {method} not supported")
         if len(ids) > 0:
             logger.info(
                 f"Processing {pretty}: ({tmdb_id}) {tmdb_name} ({len(ids)} Item{'' if len(ids) == 1 else 's'})"
             )
     return ids