From dc6507ffed067c177a8a5bd7bae5d85d71a18121 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sat, 4 Jul 2020 13:23:47 -0700 Subject: [PATCH] Run futurize --stage2 --- fun/playlist_manager.py | 1 + killstream/kill_else_if_buffering.py | 9 ++++++--- killstream/kill_stream.py | 8 +++++--- killstream/limiterr.py | 1 + maps/ips_to_maps.py | 10 +++++++--- notify/find_unwatched_notify.py | 2 ++ notify/notify_delay.py | 4 +++- notify/notify_fav_tv_all_movie.py | 3 ++- notify/notify_newip.py | 1 + notify/notify_user_favorites.py | 1 + notify/notify_user_newip.py | 1 + reporting/added_to_plex.py | 2 ++ reporting/check_play.py | 1 + reporting/check_plex_log.py | 1 + reporting/library_play_days.py | 1 + reporting/plex_netflix_check.py | 1 + reporting/userplays_weekly_reporting.py | 1 + reporting/watched_percentages.py | 7 ++++--- reporting/weekly_stats_reporting.py | 6 ++++-- utility/delete_watched_TV.py | 1 + utility/find_unwatched.py | 5 ++++- utility/get_serial_transcoders.py | 4 +++- utility/grab_gdrive_media.py | 3 ++- utility/mark_multiepisode_watched.py | 1 + utility/media_manager.py | 5 +++-- utility/off_deck.py | 1 + utility/plex_api_poster_pull.py | 6 ++++-- utility/plex_imgur_dl.py | 7 +++++-- utility/plex_theme_songs.py | 6 ++++-- utility/remove_watched_movies.py | 4 +++- utility/stream_limiter_ban_email.py | 2 ++ utility/sync_watch_status.py | 7 ++++--- 32 files changed, 82 insertions(+), 31 deletions(-) diff --git a/fun/playlist_manager.py b/fun/playlist_manager.py index bc21980..8745746 100644 --- a/fun/playlist_manager.py +++ b/fun/playlist_manager.py @@ -99,6 +99,7 @@ optional arguments: """ +from builtins import str import sys import os import random diff --git a/killstream/kill_else_if_buffering.py b/killstream/kill_else_if_buffering.py index 14e51db..09bf083 100644 --- a/killstream/kill_else_if_buffering.py +++ b/killstream/kill_else_if_buffering.py @@ -16,7 +16,10 @@ Tautulli > Settings > Notification Agents > Scripts > Gear icon: """ from __future__ import print_function +from __future__ import division +from builtins import str +from past.utils import old_div import requests from operator import itemgetter import unicodedata @@ -44,7 +47,7 @@ def kill_session(sess_key, message): # Check for users stream username = session.usernames[0] if session.sessionKey == sess_key: - title = unicode(session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title + title = str(session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title title = unicodedata.normalize('NFKD', title).encode('ascii', 'ignore').translate(None, "'") session.stop(reason=message) print('Terminated {user}\'s stream of {title} to prioritize admin stream.'.format(user=username, @@ -68,8 +71,8 @@ def main(): if trans_dec == 'transcode' and username not in ADMIN_USER: sess_key = session.sessionKey percent_comp = int((float(session.viewOffset) / float(session.duration)) * 100) - time_to_comp = int(int(session.duration) - int(session.viewOffset)) / 1000 / 60 - title = unicode(session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title + time_to_comp = old_div(old_div(int(int(session.duration) - int(session.viewOffset)), 1000), 60) + title = str(session.grandparentTitle + ' - ' if session.type == 'episode' else '') + session.title title = unicodedata.normalize('NFKD', title).encode('ascii', 'ignore').translate(None, "'") add_to_dictlist(user_dict, username, [sess_key, percent_comp, title, username, time_to_comp]) diff --git a/killstream/kill_stream.py b/killstream/kill_stream.py index 59a0442..f99324d 100644 --- a/killstream/kill_stream.py +++ b/killstream/kill_stream.py @@ -48,6 +48,8 @@ Tautulli > Settings > Notification Agents > New Script > Script Arguments: from __future__ import print_function +from builtins import object +from builtins import str import os import sys import json @@ -236,7 +238,7 @@ def basic_notify(notifier_id, session_id, username=None, message=None, stream=No notification.send(SUBJECT_TEXT, body) -class Tautulli: +class Tautulli(object): def __init__(self, url, apikey, verify_ssl=False, debug=None): self.url = url self.apikey = apikey @@ -320,7 +322,7 @@ class Tautulli: return self._call_api('terminate_session', payload) -class Stream: +class Stream(object): def __init__(self, session_id=None, user_id=None, username=None, tautulli=None, session=None): self.state = None self.ip_address = None @@ -406,7 +408,7 @@ class Stream: return False -class Notification: +class Notification(object): def __init__(self, notifier_id, subject, body, tautulli, stream): self.notifier_id = notifier_id self.subject = subject diff --git a/killstream/limiterr.py b/killstream/limiterr.py index 5e16754..4eb4ba5 100644 --- a/killstream/limiterr.py +++ b/killstream/limiterr.py @@ -47,6 +47,7 @@ Taultulli > Settings > Notification Agents > New Script > Script Arguments: """ from __future__ import print_function +from builtins import range import requests import argparse from datetime import datetime, timedelta diff --git a/maps/ips_to_maps.py b/maps/ips_to_maps.py index 1109f55..9e11bb3 100644 --- a/maps/ips_to_maps.py +++ b/maps/ips_to_maps.py @@ -28,6 +28,10 @@ optional arguments: """ from __future__ import print_function +from builtins import zip +from builtins import str +from builtins import range +from builtins import object import requests import sys import json @@ -213,7 +217,7 @@ def get_geo_dict(length, users): def get_geojson_dict(user_locations): locs = [] - for username, locations in user_locations.iteritems(): + for username, locations in user_locations.items(): for location in locations: try: locs.append({ @@ -349,9 +353,9 @@ def draw_map(map_type, geo_dict, filename, headless, leg_choice): 0)) labels = labels[idx:] + labels[:idx] handles = handles[idx:] + handles[:idx] - by_label = OrderedDict(zip(labels, handles)) + by_label = OrderedDict(list(zip(labels, handles))) - leg = plt.legend(by_label.values(), by_label.keys(), fancybox=True, fontsize='x-small', + leg = plt.legend(list(by_label.values()), list(by_label.keys()), fancybox=True, fontsize='x-small', numpoints=1, title="Legend", labelspacing=1., borderpad=1.5, handletextpad=2.) if leg: lleng = len(leg.legendHandles) diff --git a/notify/find_unwatched_notify.py b/notify/find_unwatched_notify.py index 32ab1dd..0a9421d 100644 --- a/notify/find_unwatched_notify.py +++ b/notify/find_unwatched_notify.py @@ -8,6 +8,8 @@ TAUTULLI_URL + delete_media_info_cache?section_id={section_id} """ from __future__ import print_function +from builtins import object +from builtins import str import requests import sys import time diff --git a/notify/notify_delay.py b/notify/notify_delay.py index 9475b01..b6530a0 100644 --- a/notify/notify_delay.py +++ b/notify/notify_delay.py @@ -17,7 +17,9 @@ Tautulli > Settings > Notification Agents > Scripts > Gear icon: Tautulli Settings > Notification Agents > Scripts (Gear) > Script Timeout: 0 to disable or set to > 180 """ from __future__ import print_function +from __future__ import division +from past.utils import old_div import requests import sys import argparse @@ -67,7 +69,7 @@ def send_notification(subject_text, body_text): """Format notification text.""" try: subject = subject_text.format(p=p, total=cc_total) - body = body_text.format(p=p, total=cc_total, time=TIMEOUT / 60) + body = body_text.format(p=p, total=cc_total, time=old_div(TIMEOUT, 60)) except LookupError as e: sys.stderr.write("Unable to substitute '{0}' in the notification subject or body".format(e)) diff --git a/notify/notify_fav_tv_all_movie.py b/notify/notify_fav_tv_all_movie.py index 5c4a247..492d48a 100644 --- a/notify/notify_fav_tv_all_movie.py +++ b/notify/notify_fav_tv_all_movie.py @@ -19,6 +19,7 @@ Tautulli > Settings > Notification Agents > Scripts > Gear icon: """ from __future__ import print_function +from builtins import object import requests from email.mime.text import MIMEText import email.utils @@ -244,7 +245,7 @@ if __name__ == '__main__': if p.media_type == 'movie': email_subject = MOVIE_SUBJECT.format(p=p) - to = filter(None, [x['email'] for x in get_users() if x['user_id'] not in IGNORE_LST]) + to = [_f for _f in [x['email'] for x in get_users() if x['user_id'] not in IGNORE_LST] if _f] body_html = MOVIE_BODY.format(p=p) send_email(to, email_subject, body_html) diff --git a/notify/notify_newip.py b/notify/notify_newip.py index bea3121..7edba42 100644 --- a/notify/notify_newip.py +++ b/notify/notify_newip.py @@ -17,6 +17,7 @@ Arguments passed from Tautulli """ +from builtins import object import argparse import requests import sys diff --git a/notify/notify_user_favorites.py b/notify/notify_user_favorites.py index 543c0c4..98f82a4 100644 --- a/notify/notify_user_favorites.py +++ b/notify/notify_user_favorites.py @@ -18,6 +18,7 @@ Tautulli > Settings > Notification Agents > Scripts > Gear icon: """ from __future__ import print_function +from builtins import object import requests from email.mime.text import MIMEText import email.utils diff --git a/notify/notify_user_newip.py b/notify/notify_user_newip.py index 74586ff..939acfd 100644 --- a/notify/notify_user_newip.py +++ b/notify/notify_user_newip.py @@ -10,6 +10,7 @@ Restart Tautulli. Place in Playback Start """ from __future__ import print_function +from builtins import object import argparse import requests import sys diff --git a/reporting/added_to_plex.py b/reporting/added_to_plex.py index 3e7c7e3..699b061 100644 --- a/reporting/added_to_plex.py +++ b/reporting/added_to_plex.py @@ -9,6 +9,8 @@ Uncomment Exceptions if you run into problem and need to investigate. """ from __future__ import print_function +from builtins import str +from builtins import object import requests import sys import time diff --git a/reporting/check_play.py b/reporting/check_play.py index 459e7d7..b15550f 100644 --- a/reporting/check_play.py +++ b/reporting/check_play.py @@ -7,6 +7,7 @@ # {user} {title} # Add to Playback Resume +from builtins import object import requests import sys diff --git a/reporting/check_plex_log.py b/reporting/check_plex_log.py index 4c8eb3e..8cba31c 100644 --- a/reporting/check_plex_log.py +++ b/reporting/check_plex_log.py @@ -8,6 +8,7 @@ I corrupted a file to test. """ from __future__ import print_function +from builtins import object import requests import sys diff --git a/reporting/library_play_days.py b/reporting/library_play_days.py index 5b10bc0..54f4bc5 100644 --- a/reporting/library_play_days.py +++ b/reporting/library_play_days.py @@ -26,6 +26,7 @@ Usage: """ from __future__ import print_function +from builtins import str import requests import sys import argparse diff --git a/reporting/plex_netflix_check.py b/reporting/plex_netflix_check.py index 0c588ba..ccbd7ce 100644 --- a/reporting/plex_netflix_check.py +++ b/reporting/plex_netflix_check.py @@ -28,6 +28,7 @@ If title is matched in both, Amazon is first then Netflix. """ from __future__ import print_function +from builtins import str import requests import argparse from xmljson import badgerfish as bf diff --git a/reporting/userplays_weekly_reporting.py b/reporting/userplays_weekly_reporting.py index 9ae7ac0..08f7cdc 100644 --- a/reporting/userplays_weekly_reporting.py +++ b/reporting/userplays_weekly_reporting.py @@ -6,6 +6,7 @@ Use Tautulli to count how many plays per user occurred this week. Notify via Tautulli Notification """ +from builtins import object import requests import sys import time diff --git a/reporting/watched_percentages.py b/reporting/watched_percentages.py index 795d58d..392dcd7 100644 --- a/reporting/watched_percentages.py +++ b/reporting/watched_percentages.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import print_function +from builtins import object import time import argparse from plexapi.myplex import MyPlexAccount @@ -40,7 +41,7 @@ VERIFY_SSL = False timestr = time.strftime("%Y%m%d-%H%M%S") -class Connection: +class Connection(object): def __init__(self, url=None, apikey=None, verify_ssl=False): self.url = url self.apikey = apikey @@ -75,7 +76,7 @@ class Library(object): pass -class Tautulli: +class Tautulli(object): def __init__(self, connection): self.connection = connection @@ -128,7 +129,7 @@ class Tautulli: return self._call_api('get_libraries', payload) -class Plex: +class Plex(object): def __init__(self, token, url=None): if token and not url: self.account = MyPlexAccount(token) diff --git a/reporting/weekly_stats_reporting.py b/reporting/weekly_stats_reporting.py index 5ebd2b4..f56d6bc 100644 --- a/reporting/weekly_stats_reporting.py +++ b/reporting/weekly_stats_reporting.py @@ -12,6 +12,8 @@ Tautulli Settings > Extra Settings > Check - Calculate Total File Sizes [experi """ from __future__ import print_function +from builtins import range +from builtins import object from plexapi.server import CONFIG from datetime import datetime, timedelta, date from requests import Session @@ -220,7 +222,7 @@ def get_library_stats(libraries, tautulli, rich, notify=None): return sections_stats_lst -class Tautulli: +class Tautulli(object): def __init__(self, url, apikey, verify_ssl=False, debug=None): self.url = url self.apikey = apikey @@ -317,7 +319,7 @@ class Tautulli: return -class Notification: +class Notification(object): def __init__(self, notifier_id, subject, body, tautulli, stats=None): self.notifier_id = notifier_id self.subject = subject diff --git a/utility/delete_watched_TV.py b/utility/delete_watched_TV.py index 72deb03..47f717b 100644 --- a/utility/delete_watched_TV.py +++ b/utility/delete_watched_TV.py @@ -9,6 +9,7 @@ Add deletion via Plex. """ from __future__ import print_function +from builtins import object import requests import sys import os diff --git a/utility/find_unwatched.py b/utility/find_unwatched.py index 030ad05..210dace 100644 --- a/utility/find_unwatched.py +++ b/utility/find_unwatched.py @@ -6,6 +6,9 @@ Find what was added TFRAME ago and not watched using Tautulli. """ from __future__ import print_function +from builtins import input +from builtins import str +from builtins import object import requests import sys import time @@ -123,7 +126,7 @@ def get_libraries_table(): def delete_files(tmp_lst): - del_file = raw_input('Delete all unwatched files? (yes/no)').lower() + del_file = input('Delete all unwatched files? (yes/no)').lower() if del_file.startswith('y'): for x in tmp_lst: print("Removing {}".format(x)) diff --git a/utility/get_serial_transcoders.py b/utility/get_serial_transcoders.py index 81f7ec2..27444c5 100644 --- a/utility/get_serial_transcoders.py +++ b/utility/get_serial_transcoders.py @@ -7,6 +7,8 @@ Author: DirtyCajunRice Requires: requests, plexapi, python3.6+ """ from __future__ import print_function +from __future__ import division +from past.utils import old_div from requests import Session from plexapi.server import CONFIG from datetime import date, timedelta @@ -57,7 +59,7 @@ for play in HISTORY: PARAMS = {'cmd': 'get_user', 'user_id': 0} for user, counts in USERS.items(): TOTAL_PLAYS = counts['transcode'] + counts['direct play'] + counts['copy'] - TRANSCODE_PERCENT = round(counts['transcode'] * 100 / TOTAL_PLAYS, 2) + TRANSCODE_PERCENT = round(old_div(counts['transcode'] * 100, TOTAL_PLAYS), 2) if TRANSCODE_PERCENT >= THRESHOLD_PERCENT: PARAMS['user_id'] = user NAUGHTY = SESSION.get(FORMATTED_URL, params=PARAMS).json()['response']['data'] diff --git a/utility/grab_gdrive_media.py b/utility/grab_gdrive_media.py index 5cc663f..184a858 100644 --- a/utility/grab_gdrive_media.py +++ b/utility/grab_gdrive_media.py @@ -6,6 +6,7 @@ https://gist.github.com/blacktwin/f435aa0ccd498b0840d2407d599bf31d """ from __future__ import print_function +from builtins import input import os import httplib2 @@ -35,7 +36,7 @@ if credentials is None: flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI) authorize_url = flow.step1_get_authorize_url() print('Go to the following link in your browser: ' + authorize_url) - code = raw_input('Enter verification code: ').strip() + code = input('Enter verification code: ').strip() credentials = flow.step2_exchange(code) storage.put(credentials) diff --git a/utility/mark_multiepisode_watched.py b/utility/mark_multiepisode_watched.py index ea6c6c2..d2e1421 100644 --- a/utility/mark_multiepisode_watched.py +++ b/utility/mark_multiepisode_watched.py @@ -16,6 +16,7 @@ # --rating_key {rating_key} --filename {filename} from __future__ import print_function +from builtins import str import argparse import os from plexapi.server import PlexServer diff --git a/utility/media_manager.py b/utility/media_manager.py index 808f615..c6073f6 100644 --- a/utility/media_manager.py +++ b/utility/media_manager.py @@ -24,6 +24,7 @@ Enabling Scripts in Tautulli: """ from __future__ import print_function +from builtins import object import argparse import datetime import time @@ -71,7 +72,7 @@ OPTIMIZE_DEFAULT = {'targetTagID': 'Mobile', 'policyUnwatched': 0, 'videoQuality': None} -class Connection: +class Connection(object): def __init__(self, url=None, apikey=None, verify_ssl=False): self.url = url self.apikey = apikey @@ -160,7 +161,7 @@ class User(object): self.direct = {} -class Tautulli: +class Tautulli(object): def __init__(self, connection): self.connection = connection diff --git a/utility/off_deck.py b/utility/off_deck.py index 240c984..6652183 100644 --- a/utility/off_deck.py +++ b/utility/off_deck.py @@ -46,6 +46,7 @@ original. """ from __future__ import print_function +from builtins import range import requests import argparse import datetime diff --git a/utility/plex_api_poster_pull.py b/utility/plex_api_poster_pull.py index 47f3895..e766743 100644 --- a/utility/plex_api_poster_pull.py +++ b/utility/plex_api_poster_pull.py @@ -15,11 +15,13 @@ Requires: plexapi """ from __future__ import print_function +from future import standard_library +standard_library.install_aliases() from plexapi.server import PlexServer, CONFIG import requests import re import os -import urllib +import urllib.request, urllib.parse, urllib.error library_name = ['Movies', 'TV Shows'] # Your library names @@ -71,4 +73,4 @@ for library in library_name: print("ERROR, %s already exist" % image_path) else: # Save to directory - urllib.urlretrieve(thumb_url, image_path) + urllib.request.urlretrieve(thumb_url, image_path) diff --git a/utility/plex_imgur_dl.py b/utility/plex_imgur_dl.py index 6b59318..b76f4c2 100644 --- a/utility/plex_imgur_dl.py +++ b/utility/plex_imgur_dl.py @@ -10,8 +10,11 @@ Skips download if showname.jpg exists or if show does not exist. """ from __future__ import print_function +from future import standard_library +standard_library.install_aliases() +from builtins import object import requests -import urllib +import urllib.request, urllib.parse, urllib.error import os @@ -50,6 +53,6 @@ for x in get_imgur(): print("Poster for {} was already downloaded or filename already exists, skipping.".format(x.description)) else: print("Downloading poster for {}.".format(x.description)) - urllib.urlretrieve(x.link, '{}.jpg'.format((os.path.join(SHOW_PATH, x.description, x.description)))) + urllib.request.urlretrieve(x.link, '{}.jpg'.format((os.path.join(SHOW_PATH, x.description, x.description)))) else: print("{} - {} did not match your library.".format(x.description, x.link)) diff --git a/utility/plex_theme_songs.py b/utility/plex_theme_songs.py index 97f17ff..7aadbf6 100644 --- a/utility/plex_theme_songs.py +++ b/utility/plex_theme_songs.py @@ -9,11 +9,13 @@ Songs are saved in a 'Theme Songs' directory located in script's path. """ +from future import standard_library +standard_library.install_aliases() from plexapi.server import PlexServer, CONFIG # pip install plexapi import os import re -import urllib +import urllib.request, urllib.parse, urllib.error import requests # ## Edit ## @@ -56,4 +58,4 @@ for show in plex.library.section(TV_LIBRARY).all(): # Get tvdb_if from first episode, no need to go through all episodes tvdb_id = show.episodes()[0].guid.split('/')[2] # Download theme song to output path - urllib.urlretrieve(themes_url.format(tvdb_id), theme_path) + urllib.request.urlretrieve(themes_url.format(tvdb_id), theme_path) diff --git a/utility/remove_watched_movies.py b/utility/remove_watched_movies.py index 11e3f32..0c0d784 100644 --- a/utility/remove_watched_movies.py +++ b/utility/remove_watched_movies.py @@ -7,6 +7,8 @@ Deletion is prompted """ from __future__ import print_function +from builtins import input +from builtins import object import requests import sys import os @@ -76,7 +78,7 @@ def get_history(user, start, length): def delete_files(tmp_lst): - del_file = raw_input('Delete all watched files? (yes/no)').lower() + del_file = input('Delete all watched files? (yes/no)').lower() if del_file.startswith('y'): for x in tmp_lst: print("Removing {}".format(os.path.dirname(x))) diff --git a/utility/stream_limiter_ban_email.py b/utility/stream_limiter_ban_email.py index b3c36e5..b71964e 100644 --- a/utility/stream_limiter_ban_email.py +++ b/utility/stream_limiter_ban_email.py @@ -52,6 +52,8 @@ Concurrent stream count is the trigger. Trigger can be anything you want. from __future__ import print_function +from builtins import str +from builtins import object import requests import sys from xml.dom import minidom diff --git a/utility/sync_watch_status.py b/utility/sync_watch_status.py index 052a7e9..bbc502b 100644 --- a/utility/sync_watch_status.py +++ b/utility/sync_watch_status.py @@ -56,6 +56,7 @@ Taultulli > Settings > Notification Agents > New Script > Script Arguments: **Rating key must be a movie or episode. Shows and Seasons not support.... yet. """ from __future__ import print_function +from builtins import object import argparse from plexapi.myplex import MyPlexAccount from plexapi.server import PlexServer @@ -79,7 +80,7 @@ if not TAUTULLI_APIKEY: VERIFY_SSL = False -class Connection: +class Connection(object): def __init__(self, url=None, apikey=None, verify_ssl=False): self.url = url self.apikey = apikey @@ -133,7 +134,7 @@ class Metadata(object): pass -class Tautulli: +class Tautulli(object): def __init__(self, connection): self.connection = connection @@ -190,7 +191,7 @@ class Tautulli: return self._call_api('get_libraries', payload) -class Plex: +class Plex(object): def __init__(self, token, url=None): if token and not url: self.account = MyPlexAccount(token)