Last active
March 27, 2025 14:08
-
-
Save bjesus/beb8f9d9542841f568492707bdec4783 to your computer and use it in GitHub Desktop.
Catt (chromecast) indicator for Waybar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"custom/cast": { | |
"format": "{icon} {}", | |
"tooltip": true, | |
"interval": 3, | |
"return-type": "json", | |
"format-icons": { | |
"default": "๐" | |
}, | |
"exec": "/PATH/TO/waybar-catt.py", | |
"exec-if": "nmcli -t | grep -q NAME_OF_YOUR_HOME_WIFI", | |
"on-click": "catt play_toggle && rm /tmp/cattstatus" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import datetime | |
import json | |
from html import escape | |
import re | |
import os | |
import time | |
data = {} | |
path = "/tmp/cattstatus" | |
now = time.time() | |
should_check_again = False | |
if os.path.exists(path): | |
with open(path, "r") as f: | |
try: | |
output = json.loads(f.read()) | |
except: | |
should_check_again = True | |
output = False | |
if output: | |
if 'duration' in output: | |
try: | |
if now > output['duration']-output['current_time']+output['time_now']: | |
should_check_again = True | |
except: | |
should_check_again = True | |
else: | |
should_check_again = True | |
else: | |
should_check_again = True | |
if should_check_again: | |
output = subprocess.check_output("catt info -j", shell=True) | |
output = json.loads(output.decode("utf-8")) | |
now = time.time() | |
with open(path, "w") as f: | |
output['time_now'] = now | |
f.write(json.dumps(output)) | |
def formatTime(seconds): | |
seconds = int(seconds) | |
g = time.gmtime(seconds) | |
return str(g.tm_min)+":"+str(g.tm_sec).zfill(2) | |
if 'duration' in output: | |
total_length = formatTime(output['duration']) | |
current_time = formatTime(output['current_time']+(now-output['time_now'])) | |
title = escape(output['media_metadata']['title']) | |
album = escape(output['media_metadata']['albumName']) | |
artist = escape(output['media_metadata']['artist']) | |
data['text'] = re.sub("[\(\[].*?[\)\]]", "", title).strip() | |
data['tooltip'] = f"๐ <b>{title}</b> ({current_time}/{total_length})\n๏ {album}\n๏ {artist}" | |
print(json.dumps(data)) |
Author
bjesus
commented
Sep 13, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment