Skip to content

Commit 3c2a81b

Browse files
committed
fix: ignore same tab and empty tab on update (#6)
1 parent 817c1c3 commit 3c2a81b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929

3030
__all__ = ["App", "Logger"]
3131
__title__ = "Youtube Music RPC"
32-
__version__ = "0.4"
32+
__version__ = "0.4.2"
3333
__author__ = "Manuel Cabral"
3434
__license__ = "MIT"

src/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from .tab import Tab
66
from .utils import remote_debugging, run_browser, get_default_browser, get_browser_tabs
77

8+
DISCORD_STATUS_LIMIT = 15
9+
810

911
class App:
1012
"""Core class of the application."""
@@ -26,7 +28,7 @@ def __init__(
2628
):
2729
os.system("title " + title + " v" + version)
2830
Logger.write(message=f"{title} v{version}", level="INFO", origin=self)
29-
Logger.write(message="initialized.", origin=self)
31+
Logger.write(message="initialized, to stop, press CTRL+C.", origin=self)
3032
self.__presence = Presence(client_id=client_id)
3133
self.version = version
3234
self.title = title
@@ -90,15 +92,20 @@ def run(self) -> None:
9092
)
9193
Logger.write(message="Starting browser remote debugging..", origin=self)
9294
run_browser(self.__browser)
95+
Logger.write(message="Starting presence loop..", origin=self)
96+
time.sleep(5)
9397
while self.connected:
9498
tabs = self.update_tabs()
9599
tab = [tab for tab in tabs if tab.playing] or [
96100
tab for tab in tabs if tab.pause
97101
]
98102
if not tab:
103+
Logger.write(message="No tab found.", origin=self)
104+
time.sleep(DISCORD_STATUS_LIMIT)
99105
continue
100106
tab = tab[0]
101107
if self.last_tab == tab:
108+
time.sleep(DISCORD_STATUS_LIMIT)
102109
continue
103110
self.last_tab = tab
104111
state = self.last_tab.artist if self.last_tab.artist else "Unknown"
@@ -123,7 +130,7 @@ def run(self) -> None:
123130
],
124131
start=time.time(),
125132
)
126-
time.sleep(15)
133+
time.sleep(DISCORD_STATUS_LIMIT)
127134
except Exception as exc:
128135
self.__handle_exception(exc)
129136
if exc.__class__.__name__ == "URLError":

src/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def get_browser_tabs(filter_url: str = "") -> list:
5858

5959

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

6365

6466
def current_playing_tab(tabs: Tab) -> dict:

0 commit comments

Comments
 (0)