From 569f24ee7c2c88fdd1910d5b407cd988424e5456 Mon Sep 17 00:00:00 2001 From: Origami Official <64251776+origamiofficial@users.noreply.github.com> Date: Thu, 19 May 2022 13:48:30 +0600 Subject: [PATCH 1/2] Instructions Update A simple instruction update to make the script more user friendly. --- utility/refresh_next_episode.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utility/refresh_next_episode.py b/utility/refresh_next_episode.py index fe03868..581ad87 100644 --- a/utility/refresh_next_episode.py +++ b/utility/refresh_next_episode.py @@ -5,14 +5,14 @@ Check Tautulli's Watched Percent in Tautulli > Settings > General -1. Tautulli > Settings > Notification Agents > Scripts > Bell icon: - [X] Notify on watched -2. Tautulli > Settings > Notification Agents > Scripts > Gear icon: - Enter the "Script folder" where you save the script. - Watched: refresh_next_episode.py +1. Tautulli > Settings > Notification Agents > Script > Script Triggers: + [√] watched +2. Tautulli > Settings > Notification Agents > Script > Gear icon: + Enter the "Script Folder" where you save the script. + Select "refresh_next_episode.py" in "Script File". Save -3. Tautulli > Settings > Notifications > Script > Script Arguments: - {show_name} {episode_num00} {season_num00} +3. Tautulli > Settings > Notification Agents > Script > Script Arguments > Watched: + {show_name} {episode_num00} {season_num00} """ from __future__ import print_function From 3a2f9d5b1222d6eb69060c43720b291443459d5f Mon Sep 17 00:00:00 2001 From: Pranjal <{ID}+{username}@users.noreply.github.com> Date: Sun, 21 Aug 2022 11:50:55 -0500 Subject: [PATCH 2/2] Added feature filters based on audience rating --- utility/media_manager.py | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/utility/media_manager.py b/utility/media_manager.py index a9235f2..f369ca0 100644 --- a/utility/media_manager.py +++ b/utility/media_manager.py @@ -25,6 +25,9 @@ Enabling Scripts in Tautulli: Find library items that were last played before 2021-01-01 python media_manger.py --libraries "Movies --select lastPlayed --date 2021-01-01 --action show + Find library items that have audience rating less than 6 + python3 media_manager.py --libraries "Movies 2022" --select rating --selectValue "<_6" --action show + """ from __future__ import print_function @@ -128,6 +131,7 @@ class Metadata(object): self.video_resolution = d.get('video_resolution') self.video_codec = d.get('video_codec') self.media_info = d.get('media_info') + self.audience_rating= d.get('audience_rating') if self.media_info: self.parts = self.media_info[0].get('parts') self.file = self.parts[0].get('file') @@ -480,6 +484,39 @@ def watched_work(user, sectionID=None, ratingKey=None): break start += count +def rating_work(sectionID, operator, value): + """ + Parameters + ---------- + sectionID (int): Library key + value (str): audience rating criteria + Returns + ------- + rating_lst (list): List of Metdata objects of items matching audience rating + """ + count = 25 + start = 0 + rating_lst = [] + while True: + tt_size = tautulli_server.get_library_media_info(section_id=sectionID, + start=start, length=count) + if all([tt_size]): + start += count + for item in tt_size: + _meta = tautulli_server.get_metadata(item['rating_key']) + metadata = Metadata(_meta) + try: + if metadata.audience_rating: + audience_rating = float(metadata.audience_rating) + if operator(audience_rating, float(value)): + rating_lst.append(metadata) + except AttributeError: + print("Metadata error found with rating_key: ({})".format(item['rating_key'])) + continue + elif not all([tt_size]): + break + start += count + return rating_lst def transcode_work(sectionID, operator, value): """ @@ -540,6 +577,8 @@ def action_show(items, selector, date, users=None): print("The following items were watched by {}".format(", ".join([user.name for user in users]))) elif selector == 'unwatched': print("The following items were added before {} and are unwatched".format(date)) + elif selector == 'rating': + print("The following item(s) meet the criteria") else: print("The following items were added before {}".format(date)) @@ -555,6 +594,10 @@ def action_show(items, selector, date, users=None): last_played = datetime.datetime.utcfromtimestamp(float(item.last_played)).strftime("%Y-%m-%d") print(u"\t{} added {} and last played {}\tSize: {}\n\t\tFile: {}".format( item.title, added_at, last_played, sizeof_fmt(size), item.file)) + + elif selector == 'rating': + print(u"\t{} added {}\tSize: {}\tRating: {}\n\t\tFile: {}".format( + item.title, added_at, sizeof_fmt(size), item.audience_rating, item.file)) elif selector == 'transcoded': print(u"\t{} added {}\tSize: {}\tTransocded: {} time(s)\n\t\tFile: {}".format( @@ -635,6 +678,7 @@ if __name__ == '__main__': last_played_lst = [] size_lst = [] user_lst = [] + rating_lst = [] transcode_lst = [] date_format = '' @@ -760,7 +804,16 @@ if __name__ == '__main__': print("Size must end with one of these notations: {}".format(", ".join(UNTIS.keys()))) pass elif opts.select == "rating": - pass + if libraries: + for _library in libraries: + print("Checking library: '{}' items with {}{} rating...".format( + _library.title, operator, value)) + rating_lst += rating_work(sectionID=_library.key, operator=op, value=value) + + if opts.action == "show": + action_show(rating_lst, opts.select, None) + elif opts.action == 'delete': + plex_deletion(rating_lst, libraries, opts.toggleDeletion) elif opts.select == "transcoded": if libraries: for _library in libraries: