Reformat code.

This commit is contained in:
Ian Walton 2023-02-14 21:33:58 -05:00
parent d03edf81f4
commit e541dcea2f
12 changed files with 69 additions and 47 deletions

View File

@ -8,7 +8,7 @@ lib_root = os.path.join(os.path.dirname(webview.__file__), "lib")
files_to_copy = [
"WebBrowserInterop.x86.dll",
"WebBrowserInterop.x64.dll",
"Microsoft.Toolkit.Forms.UI.Controls.WebView.dll"
"Microsoft.Toolkit.Forms.UI.Controls.WebView.dll",
]
for f in files_to_copy:

View File

@ -50,6 +50,7 @@ class PeriodicHealthCheck(threading.Thread):
if not self.trigger.wait(settings.health_check_interval):
self.callback()
class ClientManager(object):
def __init__(self):
self.callback = lambda client, event_name, data: None
@ -141,7 +142,7 @@ class ClientManager(object):
):
if server.endswith("/"):
server = server[:-1]
protocol, host, port, path = path_regex.match(server).groups()
if not protocol:
@ -177,11 +178,15 @@ class ClientManager(object):
return False
def validate_client(self, client: "JellyfinClient"):
for f_client in client.jellyfin.sessions(params={ "ControllableByUserId": "{UserId}" }):
if f_client.get('DeviceId') == settings.client_uuid:
for f_client in client.jellyfin.sessions(
params={"ControllableByUserId": "{UserId}"}
):
if f_client.get("DeviceId") == settings.client_uuid:
break
else:
log.warning("Client is not actually connected. (It does not show in the client list.)")
log.warning(
"Client is not actually connected. (It does not show in the client list.)"
)
# WebSocketDisconnect doesn't always happen here.
client.callback = lambda *_: None
client.callback_ws = lambda *_: None
@ -243,11 +248,13 @@ class ClientManager(object):
# Retry three times to reduce odds of this happening.
partial_reconnect_attempts = 3
for i in range(partial_reconnect_attempts):
log.warning(f"Partially connected. Retrying {i+1}/{partial_reconnect_attempts}.")
log.warning(
f"Partially connected. Retrying {i+1}/{partial_reconnect_attempts}."
)
self._disconnect_client(server=server)
time.sleep(1)
if self.connect_client(server, False):
is_logged_in=True
is_logged_in = True
break
return is_logged_in

View File

@ -240,12 +240,17 @@ class Video(object):
# provided by plugin
try:
skip_intro_data = self.client.jellyfin._get(f"Episode/{media_source_id}/IntroTimestamps")
skip_intro_data = self.client.jellyfin._get(
f"Episode/{media_source_id}/IntroTimestamps"
)
if skip_intro_data is not None and skip_intro_data["Valid"]:
self.intro_start = skip_intro_data["IntroStart"]
self.intro_end = skip_intro_data["IntroEnd"]
except:
log.warning("Fetching intro data failed. Do you have the plugin installed?", exc_info=1)
log.warning(
"Fetching intro data failed. Do you have the plugin installed?",
exc_info=1,
)
def get_playback_url(
self,
@ -402,7 +407,7 @@ class Media(object):
def replace_queue(self, sp_items, seq):
"""Update queue for SyncPlay.
Returns None if the video is the same or a new Media if not."""
Returns None if the video is the same or a new Media if not."""
if self.queue[self.seq]["Id"] == sp_items[seq]["Id"]:
self.queue, self.seq = sp_items, seq
return None

View File

@ -502,9 +502,7 @@ class OSDMenu(object):
),
self.subtitle_color_menu,
),
self.get_settings_toggle(
_("Transcode Hi10p to 8bit"), "transcode_hi10p"
),
self.get_settings_toggle(_("Transcode Hi10p to 8bit"), "transcode_hi10p"),
self.get_settings_toggle(_("Transcode HDR"), "transcode_hdr"),
self.get_settings_toggle(_("Direct Paths"), "direct_paths"),
self.get_settings_toggle(_("Disable Direct Play"), "always_transcode"),
@ -520,10 +518,7 @@ class OSDMenu(object):
),
)
self.put_menu(
_("Video Preferences"),
options
)
self.put_menu(_("Video Preferences"), options)
def shader_pack_subtype_menu(self):
self.put_menu(

View File

@ -390,10 +390,10 @@ class PlayerManager(object):
# Python-MPV 1.0 uses a class/struct combination now
if hasattr(event, "as_dict"):
event = event.as_dict()
if 'event' in event:
event['event'] = event['event'].decode('utf-8')
if 'args' in event:
event['args'] = [d.decode('utf-8') for d in event['args']]
if "event" in event:
event["event"] = event["event"].decode("utf-8")
if "args" in event:
event["args"] = [d.decode("utf-8") for d in event["args"]]
if "event_id" in event:
args = event["event"]["args"]
@ -432,12 +432,15 @@ class PlayerManager(object):
@synchronous("_lock")
def update(self):
if ((settings.skip_intro_always or settings.skip_intro_prompt)
if (
(settings.skip_intro_always or settings.skip_intro_prompt)
and not self.syncplay.is_enabled()
and self._video is not None and self._video.intro_start is not None
and self._video is not None
and self._video.intro_start is not None
and self._player.playback_time is not None
and self._player.playback_time > self._video.intro_start
and self._player.playback_time < self._video.intro_end):
and self._player.playback_time < self._video.intro_end
):
if not self.is_in_intro:
if settings.skip_intro_always and not self.intro_has_triggered:
@ -458,7 +461,11 @@ class PlayerManager(object):
self.last_update.restart()
def play(
self, video: "Video_type", offset: int = 0, no_initial_timeline: bool = False, is_initial_play: bool = False
self,
video: "Video_type",
offset: int = 0,
no_initial_timeline: bool = False,
is_initial_play: bool = False,
):
self.should_send_timeline = False
self.start_time = time.time()
@ -476,7 +483,7 @@ class PlayerManager(object):
url: str,
offset: int = 0,
no_initial_timeline: bool = False,
is_initial_play: bool = False
is_initial_play: bool = False,
):
self.pause_ignore = True
self.do_not_handle_pause = True
@ -633,7 +640,11 @@ class PlayerManager(object):
else:
if self.syncplay.is_enabled():
self.last_seek = self._player.playback_time + offset
if self.is_in_intro and self._player.playback_time + offset > self._player.playback_time:
if (
self.is_in_intro
and self._player.playback_time + offset
> self._player.playback_time
):
self.skip_intro()
if exact:
self._player.command("seek", offset, "exact")

View File

@ -7,7 +7,7 @@ RPC.start()
def register_join_event(syncplay_join_group: callable):
RPC.register_event('activity_join', syncplay_join_group)
RPC.register_event("activity_join", syncplay_join_group)
def send_presence(

View File

@ -1,24 +1,30 @@
from __future__ import annotations
from typing import Optional
import logging
log = logging.getLogger("settings_base")
# This is NOT a full pydantic replacement!!!
# Compatible with PEP 563
# Tries to also deal with common errors in the config
def allow_none(constructor):
def wrapper(input):
if input is None or input == "null":
return None
return constructor(input)
return wrapper
yes_set = {1, "yes", "Yes", "True", "true", "1", True}
def adv_bool(value):
return value in yes_set
object_types = {
"float": float,
"int": int,
@ -38,6 +44,7 @@ object_types = {
Optional[bool]: allow_none(adv_bool),
}
class SettingsBase:
def __init__(self):
self.__fields_set__ = set()
@ -48,7 +55,7 @@ class SettingsBase:
self.__fields__.append(attr)
setattr(self, attr, getattr(self.__class__, attr))
def dict(self):
result = {}
for attr in self.__fields__:
@ -66,5 +73,8 @@ class SettingsBase:
setattr(new_obj, attr, parse(object[attr]))
new_obj.__fields_set__.add(attr)
except:
log.error("Setting {0} had invalid value {1}.".format(attr, object[attr]), exc_info=True)
log.error(
"Setting {0} had invalid value {1}.".format(attr, object[attr]),
exc_info=True,
)
return new_obj

View File

@ -425,7 +425,9 @@ class SyncPlayManager:
if video:
if settings.pre_media_cmd:
os.system(settings.pre_media_cmd)
self.playerManager.play(video, offset, no_initial_timeline=True, is_initial_play=True)
self.playerManager.play(
video, offset, no_initial_timeline=True, is_initial_play=True
)
self.playerManager.send_timeline()
# Really not sure why I have to call this.
self.join_group(group_id)

View File

@ -15,9 +15,7 @@ if TYPE_CHECKING:
log = logging.getLogger("update_check")
release_url = "https://github.com/jellyfin/jellyfin-mpv-shim/releases/"
release_urls = [
release_url
]
release_urls = [release_url]
one_day = 86400

View File

@ -189,8 +189,10 @@ class VideoProfileManager:
selected = 0
profile_option_list = [(_("None (Disabled)"), self.menu_handle, None)]
for i, (profile_name, profile) in enumerate(self.profiles.items()):
if (profile.get("subtype", None) is not None and
not settings.shader_pack_subtype in profile["subtype"]):
if (
profile.get("subtype", None) is not None
and not settings.shader_pack_subtype in profile["subtype"]
):
continue
name = profile["displayname"]

View File

@ -4,10 +4,7 @@ APP = ["/usr/local/bin/jellyfin-mpv-shim"]
OPTIONS = {
"argv_emulation": True,
"iconfile": "jellyfin.icns",
"resources": [
"/usr/local/bin/mpv",
"/usr/local/bin/jellyfin-mpv-shim"
],
"resources": ["/usr/local/bin/mpv", "/usr/local/bin/jellyfin-mpv-shim"],
"packages": ["pkg_resources"],
}

View File

@ -13,18 +13,13 @@ setup(
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/jellyfin/jellyfin-mpv-shim",
packages=[
"jellyfin_mpv_shim",
"jellyfin_mpv_shim.display_mirror"
],
packages=["jellyfin_mpv_shim", "jellyfin_mpv_shim.display_mirror"],
package_data={
"jellyfin_mpv_shim.display_mirror": ["*.css", "*.html"],
"jellyfin_mpv_shim": ["systray.png"],
},
entry_points={
"console_scripts": [
"jellyfin-mpv-shim=jellyfin_mpv_shim.mpv_shim:main"
]
"console_scripts": ["jellyfin-mpv-shim=jellyfin_mpv_shim.mpv_shim:main"]
},
classifiers=[
"Programming Language :: Python :: 3",