From b6bc2e11cff538d091ec9d5d00e556451f9d92d0 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Tue, 13 Dec 2022 22:40:30 +0100 Subject: [PATCH] Add an additional CALL logging level --- main.py | 5 ++-- manual.txt | 2 +- twitch.py | 68 +++++++++++++++++++++++++++++------------------------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/main.py b/main.py index 55c289b..e5686db 100644 --- a/main.py +++ b/main.py @@ -29,7 +29,7 @@ if __name__ == "__main__": from utils import resource_path from version import __version__ from exceptions import CaptchaRequired - from constants import SELF_PATH, FILE_FORMATTER, LOG_PATH, WINDOW_TITLE + from constants import CALL, SELF_PATH, FILE_FORMATTER, LOG_PATH, WINDOW_TITLE class Parser(argparse.ArgumentParser): def __init__(self, *args, **kwargs) -> None: @@ -61,7 +61,8 @@ if __name__ == "__main__": 0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, - 3: logging.DEBUG, + 3: CALL, + 4: logging.DEBUG, }[min(self._verbose, 3)] @property diff --git a/manual.txt b/manual.txt index 7ba8b1c..7fefdbf 100644 --- a/manual.txt +++ b/manual.txt @@ -7,7 +7,7 @@ Available command line arguments: • --tray Start application as minimised into tray. • -v - Increase verbosity level. Can be stacked up to 3 times (-vv and -vvv) to show + Increase verbosity level. Can be stacked up several times (-vv, -vvv, etc.) to show increasingly more information during application runtime. • --log Enables logging of runtime information into a 'log.txt' file. Verbosity level of this logging diff --git a/twitch.py b/twitch.py index c939bd3..82d6e63 100644 --- a/twitch.py +++ b/twitch.py @@ -1157,39 +1157,45 @@ class Twitch: NOTE: 'stream_before' gets dealocated once this function finishes. """ - if stream_before is None and stream_after is not None: - # Channel going ONLINE - logger.info(f"{channel.name} goes ONLINE") - # continue to below - elif stream_before is not None and stream_after is None: - # Channel going OFFLINE - # Change the channel if we're currently watching it - watching_channel = self.watching_channel.get_with_default(None) - if watching_channel is not None and watching_channel == channel: - self.print(_("status", "goes_offline").format(channel=channel.name)) - self.change_state(State.CHANNEL_SWITCH) + if stream_before is None: + if stream_after is not None: + # Channel going ONLINE + if ( + self.can_watch(channel) # we can watch the channel + and self.should_switch(channel) # and we should! + ): + self.watch(channel) + self.print(_("status", "goes_online").format(channel=channel.name)) + self.gui.status.update( + _("gui", "status", "watching").format(channel=channel.name) + ) + else: + logger.info(f"{channel.name} goes ONLINE") else: - logger.info(f"{channel.name} goes OFFLINE") - channel.display() - return - elif stream_after is not None and stream_after is not None: - # Channel is and stays ONLINE, but has been updated - logger.info(f"{channel.name} status has been updated") - # continue to below + # Channel was OFFLINE and stays that way + # Nothing to do here for now + return else: - # Channel was OFFLINE and stays that way - # Nothing to do here for now - return - - if ( - self.can_watch(channel) # we can watch the channel - and self.should_switch(channel) # and we should! - ): - self.watch(channel) - self.print(_("status", "goes_online").format(channel=channel.name)) - self.gui.status.update( - _("gui", "status", "watching").format(channel=channel.name) - ) + watching_channel = self.watching_channel.get_with_default(None) + if ( + watching_channel is not None + and watching_channel == channel + and not self.can_watch(channel) + ): + if stream_after is None: + # Channel going OFFLINE + self.print(_("status", "goes_offline").format(channel=channel.name)) + # if the channel stays online, we silently trigger a switch + self.change_state(State.CHANNEL_SWITCH) + elif stream_after is None: + logger.info(f"{channel.name} goes OFFLINE") + else: + # Channel is and stays ONLINE, but has been updated + logger.info( + f"{channel.name} status has been updated " + f"(🎁: {stream_before.drops_enabled and '✔' or '❌'} -> " + f"{stream_after.drops_enabled and '✔' or '❌'})" + ) channel.display() @task_wrapper