Files
misc/ff_brotab.py

32 lines
912 B
Python

"""Radio Info (FF Tab Info Grabber)"""
import subprocess
import sys
import logging
import os
logging.getLogger().setLevel(logging.DEBUG)
bin_path = os.path.join(os.path.expanduser("~"), ".local", "bin", "bt")
def query_ff() -> tuple[str, str] | None:
res: str | None = subprocess.check_output(
f"{bin_path} query -title 'CODEY STUFF*'", shell=True
).decode() # Utilize brotab to get open tab info
if not res:
logging.debug("brotab: No matching (radio) tab found")
return None
tab_name = res.split("\t", maxsplit=1)[
1
] # Discard brotab output before first \t (tab character)
station = tab_name.split("[")[-1].split("]", maxsplit=1)[
0
] # Extract station from page title
track = tab_name.split(" - Radio - ")[1].split(f"[{station}]")[
0
] # Extract track from page title
return (station, track)
print(query_ff())