From bf513dee433d0c66be5c32f9aa41e950f38d7a98 Mon Sep 17 00:00:00 2001 From: mcarlton00 Date: Wed, 11 Jan 2023 19:51:26 -0500 Subject: [PATCH] Fix flake8 linting complaints --- resources/lib/functions.py | 1 - resources/lib/item_functions.py | 6 +----- resources/lib/jellyfin.py | 4 ++-- resources/lib/menu_functions.py | 12 ------------ resources/lib/play_utils.py | 12 ++++-------- resources/lib/server_detect.py | 4 +--- resources/lib/utils.py | 16 +++++++--------- resources/lib/widgets.py | 2 +- 8 files changed, 16 insertions(+), 41 deletions(-) diff --git a/resources/lib/functions.py b/resources/lib/functions.py index 3210183..1baef0a 100644 --- a/resources/lib/functions.py +++ b/resources/lib/functions.py @@ -364,7 +364,6 @@ def show_menu(params): li.setProperty('menu_id', 'instant_mix') action_items.append(li) - if result["Type"] in ["Episode", "Movie", "Video", "TvChannel", "Program", "MusicVideo"]: li = xbmcgui.ListItem(translate_string(30275), offscreen=True) li.setProperty('menu_id', 'transcode') diff --git a/resources/lib/item_functions.py b/resources/lib/item_functions.py index 0ea3198..4588e5f 100644 --- a/resources/lib/item_functions.py +++ b/resources/lib/item_functions.py @@ -3,7 +3,6 @@ from __future__ import division, absolute_import, print_function, unicode_litera import sys from six.moves.urllib.parse import quote -from datetime import datetime from dateutil import tz import xbmcgui @@ -211,7 +210,7 @@ def extract_item_info(item, gui_options): try: aspect_width, aspect_height = aspect_ratio.split(':') media_info["apect_ratio"] = float(aspect_width) / float(aspect_height) - except: + except: # noqa media_info["apect_ratio"] = 1.85 else: media_info["apect_ratio"] = 1.85 @@ -360,9 +359,6 @@ def add_gui_item(url, item_details, display_options, folder=True, default_sort=F else: u = sys.argv[0] + "?item_id=" + url + "&mode=PLAY" - # Create the ListItem that will be displayed - thumb_path = item_details.art["thumb"] - list_item_name = item_details.name item_type = item_details.item_type.lower() is_video = item_type not in ['musicalbum', 'audio', 'music'] diff --git a/resources/lib/jellyfin.py b/resources/lib/jellyfin.py index ee07f2a..fbc5a35 100644 --- a/resources/lib/jellyfin.py +++ b/resources/lib/jellyfin.py @@ -49,7 +49,7 @@ class API: response_data = json.loads(r.text) except ValueError: response_data = r.json() - except: + except: # noqa response_data = {} return response_data @@ -66,7 +66,7 @@ class API: response_data = json.loads(r.text) except ValueError: response_data = r.json() - except: + except: # noqa response_data = {} return response_data diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index 92651c2..8c8c180 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -412,7 +412,6 @@ def show_tvshow_alpha_list(menu_params): return parent_id = menu_params.get("parent_id") - user_id = get_current_user_id() prefixes = '#' + string.ascii_uppercase @@ -606,8 +605,6 @@ def display_menu(params): def show_global_types(params): handle = int(sys.argv[1]) - user_id = get_current_user_id() - continue_watching_url_params = { "Fields": get_default_filters(), "ImageTypeLimit": 1, @@ -631,7 +628,6 @@ def display_homevideos_type(menu_params, view): view_name = view.get("Name") item_limit = settings.getSetting("show_x_filtered_items") hide_watched = settings.getSetting("hide_watched") == "true" - user_id = get_current_user_id() # All Home Movies base_params = { @@ -696,7 +692,6 @@ def display_tvshow_type(menu_params, view): view_name = view.get("Name") item_limit = settings.getSetting("show_x_filtered_items") - user_id = get_current_user_id() # All TV Shows base_params = { @@ -799,7 +794,6 @@ def display_music_type(menu_params, view): view_name = view.get("Name") item_limit = settings.getSetting("show_x_filtered_items") - user_id = get_current_user_id() # all albums params = { @@ -891,7 +885,6 @@ def display_musicvideos_type(params, view): xbmcplugin.setContent(handle, 'files') view_name = view.get("Name") - user_id = get_current_user_id() # artists params = { @@ -913,7 +906,6 @@ def display_livetv_type(menu_params, view): xbmcplugin.setContent(handle, 'files') view_name = view.get("Name") - user_id = get_current_user_id() # channels params = { @@ -964,7 +956,6 @@ def display_movies_type(menu_params, view): item_limit = settings.getSetting("show_x_filtered_items") group_movies = settings.getSetting('group_movies') == "true" hide_watched = settings.getSetting("hide_watched") == "true" - user_id = get_current_user_id() base_params = { "IncludeItemTypes": "Movie", @@ -1247,7 +1238,6 @@ def get_playlist_path(view_info): "Fields": get_default_filters(), "ImageTypeLimit": 1 } - user_id = get_current_user_id() path = get_jellyfin_url("/Users/{userid}/Items", params) url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=playlists" @@ -1265,7 +1255,6 @@ def get_collection_path(view_info): "Recursive": True, "IsMissing": False } - user_id = get_current_user_id() path = get_jellyfin_url("/Users/{userid}/Items", params) url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=boxsets" @@ -1279,7 +1268,6 @@ def get_channel_path(view): "ImageTypeLimit": 1, "Fields": get_default_filters() } - user_id = get_current_user_id() path = get_jellyfin_url("/Users/{userid}/Items", params) url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=files" diff --git a/resources/lib/play_utils.py b/resources/lib/play_utils.py index d5c9154..32eb81f 100644 --- a/resources/lib/play_utils.py +++ b/resources/lib/play_utils.py @@ -781,7 +781,7 @@ def audio_subs_pref(url, list_item, media_source, item_id, audio_stream_index, s try: # Track includes language track = "%s - %s - %s %s" % (index, stream['Language'], codec, channel_layout) - except: + except KeyError: # Track doesn't include language track = "%s - %s %s" % (index, codec, channel_layout) @@ -790,8 +790,10 @@ def audio_subs_pref(url, list_item, media_source, item_id, audio_stream_index, s elif 'Subtitle' in stream['Type']: try: + # Track includes language track = "%s - %s" % (index, stream['Language']) - except: + except KeyError: + # Track doesn't include language track = "%s - %s" % (index, stream['Codec']) default = stream['IsDefault'] @@ -873,8 +875,6 @@ def external_subs(media_source, list_item, item_id): sub_names = [] server = settings.getSetting('server_address') - user_details = load_user_details() - token = user_details.get('token') for stream in media_streams: @@ -883,9 +883,6 @@ def external_subs(media_source, list_item, item_id): and stream['IsTextSubtitleStream'] and stream['SupportsExternalStream']): - index = stream['Index'] - source_id = media_source['Id'] - language = stream.get('Language', '') if language and stream['IsDefault']: language = '{}.default'.format(language) @@ -1172,7 +1169,6 @@ def get_play_url(media_source, play_session_id, channel_id=None): # get all the options server = settings.getSetting('server_address') - use_https = settings.getSetting('protocol') == "1" allow_direct_file_play = settings.getSetting('allow_direct_file_play') == 'true' can_direct_play = media_source["SupportsDirectPlay"] diff --git a/resources/lib/server_detect.py b/resources/lib/server_detect.py index 375d0da..35bc08e 100644 --- a/resources/lib/server_detect.py +++ b/resources/lib/server_detect.py @@ -4,7 +4,6 @@ from __future__ import division, absolute_import, print_function, unicode_litera import socket import json import time -from datetime import datetime import xbmcaddon import xbmcgui @@ -107,7 +106,7 @@ def get_server_details(): xbmc.sleep(1000) data, addr = sock.recvfrom(1024) servers.append(json.loads(data)) - except: + except: # noqa break except Exception as e: log.error("UPD Discovery Error: {0}".format(e)) @@ -288,7 +287,6 @@ def check_server(force=False, change_user=False, notify=False): log.info('There was an error logging in with user {}'.format(selected_user_name)) xbmcgui.Dialog().ok(__addon_name__, translate_string(30446)) - if something_changed: home_window = HomeWindow() home_window.clear_property("jellycon_widget_reload") diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 0de8e28..c1c01cf 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -97,7 +97,7 @@ def datetime_from_string(time_string): if time_string[-1:] == "Z": time_string = re.sub("[0-9]{1}Z", " UTC", time_string) elif time_string[-6:] == "+00:00": - time_string = re.sub("[0-9]{1}\+00:00", " UTC", time_string) + time_string = re.sub("[0-9]{1}\+00:00", " UTC", time_string) # noqa: W605 try: dt = datetime.strptime(time_string, "%Y-%m-%dT%H:%M:%S.%f %Z") @@ -190,7 +190,7 @@ def save_user_details(user_name, user_id, token): try: with open(os.path.join(addon_data, 'auth.json'), 'rb') as infile: auth_data = json.load(infile) - except: + except: # noqa # File doesn't exist or is empty auth_data = {} @@ -225,7 +225,7 @@ def load_user_details(): try: with open(os.path.join(addon_data, 'auth.json'), 'rb') as infile: auth_data = json.load(infile) - except: + except: # noqa # File doesn't exist yet return {} @@ -258,12 +258,12 @@ def get_saved_users(): try: with open(os.path.join(addon_data, 'auth.json'), 'rb') as infile: auth_data = json.load(infile) - except: + except: # noqa # File doesn't exist yet return [] users = [] - for user,values in auth_data.items(): + for user, values in auth_data.items(): users.append( { 'Name': user, @@ -276,8 +276,6 @@ def get_saved_users(): return users - - def get_current_user_id(): user_details = load_user_details() user_id = user_details.get('user_id') @@ -426,6 +424,6 @@ def get_bitrate(enum_value): Max bit rate supported by server: 2147483 (max signed 32bit integer) ''' bitrate = [500, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6000, - 7000, 8000, 9000, 10000, 12000, 14000, 16000, 18000, - 20000, 25000, 30000, 35000, 40000, 100000, 1000000, 2147483] + 7000, 8000, 9000, 10000, 12000, 14000, 16000, 18000, + 20000, 25000, 30000, 35000, 40000, 100000, 1000000, 2147483] return bitrate[int(enum_value) if enum_value else 24] * 1000 diff --git a/resources/lib/widgets.py b/resources/lib/widgets.py index bb71f2c..8ce82f1 100644 --- a/resources/lib/widgets.py +++ b/resources/lib/widgets.py @@ -8,7 +8,7 @@ import random import time from .jellyfin import api -from .utils import get_jellyfin_url, image_url, get_current_user_id, get_art_url, get_default_filters, kodi_version +from .utils import get_jellyfin_url, image_url, get_current_user_id, get_art_url, get_default_filters from .lazylogger import LazyLogger from .kodi_utils import HomeWindow from .dir_functions import process_directory