mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-22 04:23:08 +00:00
[41] update tautulli builders to only look at a single library
This commit is contained in:
parent
07c7e58c37
commit
0fbd026a3c
4 changed files with 36 additions and 18 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.19.0-develop40
|
||||
1.19.0-develop41
|
||||
|
|
|
@ -134,6 +134,8 @@ class AniDB:
|
|||
|
||||
def _request(self, url, params=None, data=None):
|
||||
logger.trace(f"URL: {url}")
|
||||
if params:
|
||||
logger.trace(f"Params: {params}")
|
||||
if data:
|
||||
return self.config.post_html(url, data=data, headers=util.header(self.language))
|
||||
else:
|
||||
|
|
|
@ -1664,13 +1664,19 @@ class CollectionBuilder:
|
|||
def _tautulli(self, method_name, method_data):
|
||||
for dict_data in util.parse(self.Type, method_name, method_data, datatype="listdict"):
|
||||
dict_methods = {dm.lower(): dm for dm in dict_data}
|
||||
self.builders.append((method_name, {
|
||||
final_dict = {
|
||||
"list_type": "popular" if method_name == "tautulli_popular" else "watched",
|
||||
"list_days": util.parse(self.Type, "list_days", dict_data, datatype="int", methods=dict_methods, default=30, parent=method_name),
|
||||
"list_size": util.parse(self.Type, "list_size", dict_data, datatype="int", methods=dict_methods, default=10, parent=method_name),
|
||||
"list_buffer": util.parse(self.Type, "list_buffer", dict_data, datatype="int", methods=dict_methods, default=20, parent=method_name),
|
||||
"list_minimum": util.parse(self.Type, "list_minimum", dict_data, datatype="int", methods=dict_methods, default=0, parent=method_name)
|
||||
}))
|
||||
}
|
||||
if self.library.Tautulli.has_section:
|
||||
final_dict["list_buffer"] = 0
|
||||
elif "list_buffer" in dict_methods:
|
||||
final_dict["list_buffer"] = util.parse(self.Type, "list_buffer", dict_data, datatype="int", methods=dict_methods, default=20, parent=method_name)
|
||||
else:
|
||||
final_dict["list_buffer"] = final_dict["list_size"] * 3
|
||||
self.builders.append((method_name, final_dict))
|
||||
|
||||
def _tmdb(self, method_name, method_data):
|
||||
if method_name == "tmdb_discover":
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from modules import util
|
||||
from modules.util import Failed
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
from plexapi.exceptions import BadRequest
|
||||
from plexapi.video import Movie, Show
|
||||
|
||||
logger = util.logger
|
||||
|
@ -13,22 +13,27 @@ class Tautulli:
|
|||
self.library = library
|
||||
self.url = params["url"]
|
||||
self.apikey = params["apikey"]
|
||||
self.api = f"{self.url}/api/v2"
|
||||
logger.secret(self.url)
|
||||
logger.secret(self.apikey)
|
||||
try:
|
||||
response = self._request(f"{self.url}/api/v2?apikey={self.apikey}&cmd=get_library_names")
|
||||
response = self._request("get_tautulli_info")
|
||||
except Exception:
|
||||
logger.stacktrace()
|
||||
raise Failed("Tautulli Error: Invalid url")
|
||||
if response["response"]["result"] != "success":
|
||||
raise Failed(f"Tautulli Error: {response['response']['message']}")
|
||||
self.has_section = True if int(response["response"]["data"]["tautulli_version"].split(".")[1]) > 11 else False
|
||||
self.section_id = self.library.Plex.key
|
||||
|
||||
def get_rating_keys(self, params, all_items):
|
||||
query_size = int(params["list_size"]) + int(params["list_buffer"])
|
||||
logger.info(f"Processing Tautulli Most {params['list_type'].capitalize()}: {params['list_size']} {'Movies' if self.library.is_movie else 'Shows'}")
|
||||
response = self._request(f"{self.url}/api/v2?apikey={self.apikey}&cmd=get_home_stats&time_range={params['list_days']}&stats_count={query_size}")
|
||||
stat_id = f"{'popular' if params['list_type'] == 'popular' else 'top'}_{'movies' if self.library.is_movie else 'tv'}"
|
||||
stat_type = "users_watched" if params['list_type'] == 'popular' else "total_plays"
|
||||
def get_rating_keys(self, data, all_items):
|
||||
logger.info(f"Processing Tautulli Most {data['list_type'].capitalize()}: {data['list_size']} {'Movies' if self.library.is_movie else 'Shows'}")
|
||||
params = {"time_range": data["list_days"], "stats_count": int(data["list_size"]) + int(data["list_buffer"])}
|
||||
if self.has_section and not all_items:
|
||||
params["section_id"] = self.section_id
|
||||
response = self._request("get_home_stats", params=params)
|
||||
stat_id = f"{'popular' if data['list_type'] == 'popular' else 'top'}_{'movies' if self.library.is_movie else 'tv'}"
|
||||
stat_type = "users_watched" if data['list_type'] == 'popular' else "total_plays"
|
||||
|
||||
items = None
|
||||
for entry in response["response"]["data"]:
|
||||
|
@ -38,11 +43,10 @@ class Tautulli:
|
|||
if items is None:
|
||||
raise Failed("Tautulli Error: No Items found in the response")
|
||||
|
||||
section_id = self.library.Plex.key
|
||||
rating_keys = []
|
||||
for item in items:
|
||||
if (all_items or item["section_id"] == section_id) and len(rating_keys) < int(params['list_size']):
|
||||
if int(item[stat_type]) < params['list_minimum']:
|
||||
if (all_items or item["section_id"] == self.section_id) and len(rating_keys) < int(data['list_size']):
|
||||
if int(item[stat_type]) < data['list_minimum']:
|
||||
continue
|
||||
try:
|
||||
plex_item = self.library.fetch_item(int(item["rating_key"]))
|
||||
|
@ -57,6 +61,12 @@ class Tautulli:
|
|||
logger.error(e)
|
||||
return rating_keys
|
||||
|
||||
def _request(self, url):
|
||||
logger.trace(f"Tautulli URL: {url}")
|
||||
return self.config.get_json(url)
|
||||
def _request(self, cmd, params=None):
|
||||
logger.trace(f"Tautulli CMD: {cmd}")
|
||||
if params:
|
||||
logger.trace(f"Tautulli Params: {params}")
|
||||
final_params = {"apikey": self.apikey, "cmd": cmd}
|
||||
if params:
|
||||
for k, v in params.items():
|
||||
final_params[k] = v
|
||||
return self.config.get_json(self.api, params=final_params)
|
||||
|
|
Loading…
Reference in a new issue