Skip to content

Commit

Permalink
fix: ignore same tab and empty tab on update (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucabral committed May 13, 2023
1 parent 817c1c3 commit 3c2a81b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@

__all__ = ["App", "Logger"]
__title__ = "Youtube Music RPC"
__version__ = "0.4"
__version__ = "0.4.2"
__author__ = "Manuel Cabral"
__license__ = "MIT"
11 changes: 9 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .tab import Tab
from .utils import remote_debugging, run_browser, get_default_browser, get_browser_tabs

DISCORD_STATUS_LIMIT = 15


class App:
"""Core class of the application."""
Expand All @@ -26,7 +28,7 @@ def __init__(
):
os.system("title " + title + " v" + version)
Logger.write(message=f"{title} v{version}", level="INFO", origin=self)
Logger.write(message="initialized.", origin=self)
Logger.write(message="initialized, to stop, press CTRL+C.", origin=self)
self.__presence = Presence(client_id=client_id)
self.version = version
self.title = title
Expand Down Expand Up @@ -90,15 +92,20 @@ def run(self) -> None:
)
Logger.write(message="Starting browser remote debugging..", origin=self)
run_browser(self.__browser)
Logger.write(message="Starting presence loop..", origin=self)
time.sleep(5)
while self.connected:
tabs = self.update_tabs()
tab = [tab for tab in tabs if tab.playing] or [
tab for tab in tabs if tab.pause
]
if not tab:
Logger.write(message="No tab found.", origin=self)
time.sleep(DISCORD_STATUS_LIMIT)
continue
tab = tab[0]
if self.last_tab == tab:
time.sleep(DISCORD_STATUS_LIMIT)
continue
self.last_tab = tab
state = self.last_tab.artist if self.last_tab.artist else "Unknown"
Expand All @@ -123,7 +130,7 @@ def run(self) -> None:
],
start=time.time(),
)
time.sleep(15)
time.sleep(DISCORD_STATUS_LIMIT)
except Exception as exc:
self.__handle_exception(exc)
if exc.__class__.__name__ == "URLError":
Expand Down
4 changes: 3 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def get_browser_tabs(filter_url: str = "") -> list:


def run_browser(browser: dict) -> None:
sp.Popen([browser["path"], "--remote-debugging-port=9222", "--remote-allow-origins=*"])
sp.Popen(
[browser["path"], "--remote-debugging-port=9222", "--remote-allow-origins=*"]
)


def current_playing_tab(tabs: Tab) -> dict:
Expand Down

0 comments on commit 3c2a81b

Please sign in to comment.