Plex-Meta-Manager/modules/flixpatrol.py

60 lines
2.4 KiB
Python
Raw Normal View History

2023-10-17 15:32:59 +00:00
from modules import util
from modules.util import Failed
logger = util.logger
2023-10-19 14:01:20 +00:00
base_url = "https://raw.githubusercontent.com/meisnate12/PMM-TOP10/master/"
2023-10-17 15:32:59 +00:00
builders = ["flixpatrol_top"]
class FlixPatrol:
def __init__(self, config):
self.config = config
self._platforms = None
self._locations = None
2023-10-19 14:01:20 +00:00
self.country_data = {}
2023-10-17 15:32:59 +00:00
2023-10-19 14:01:20 +00:00
def load_info(self):
info = self.config.load_yaml(f"{base_url}info.yml")
self._platforms = info["platforms"]
self._locations = info["locations"]
def get_country(self, country):
if country not in self.country_data:
self.country_data[country] = self.config.load_yaml(f"{base_url}lists/{country}.yml")
return self.country_data[country]
2023-10-17 15:32:59 +00:00
@property
def platforms(self):
if self._platforms is None:
2023-10-19 14:01:20 +00:00
self.load_info()
2023-10-17 15:32:59 +00:00
return self._platforms
@property
def locations(self):
if self._locations is None:
2023-10-19 14:01:20 +00:00
self.load_info()
2023-10-17 15:32:59 +00:00
return self._locations
def get_tmdb_ids(self, method, data, is_movie):
2023-10-17 18:45:54 +00:00
flix_items = []
2023-10-19 14:01:20 +00:00
media_type = "movies" if is_movie else "shows"
2023-10-17 15:32:59 +00:00
if method == "flixpatrol_top":
2023-10-19 14:01:20 +00:00
logger.info(f"Processing FlixPatrol Top {media_type.capitalize()}:")
2023-10-17 15:32:59 +00:00
logger.info(f"\tPlatform: {data['platform'].replace('_', ' ').title()}")
logger.info(f"\tLocation: {data['location'].replace('_', ' ').title()}")
2023-10-19 14:01:20 +00:00
logger.info(f"\tIn The Last: {data['in_the_last']}")
2023-10-17 15:32:59 +00:00
logger.info(f"\tLimit: {data['limit']}")
2023-10-19 14:01:20 +00:00
country_info = self.get_country(data["location"])
for key in [k for k in country_info][:data["in_the_last"]]:
if data["platform"] in country_info[key] and media_type in country_info[key][data["platform"]]:
for item in country_info[key][data["platform"]][media_type]:
if item not in flix_items and len(flix_items) < data["limit"]:
flix_items.append(item)
2023-10-17 18:45:54 +00:00
items = [(i, "tmdb" if is_movie else "tmdb_show") for i in flix_items]
2023-10-17 17:40:08 +00:00
if len(items) > 0:
logger.info(f"Processed {len(items)} TMDb IDs")
return items
2023-10-17 15:32:59 +00:00
else:
2023-10-19 14:01:20 +00:00
raise Failed(f"FlixPatrol Error: No {media_type.capitalize()} Found for {data['platform'].replace('_', ' ').title()} in {data['location'].replace('_', ' ').title()}")