Skip to content

Commit

Permalink
Merge branch 'ultrabug:master' into add-mpris-trackno
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmiont authored Jan 21, 2025
2 parents e5f2ebb + c2d623a commit c139394
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 112 deletions.
35 changes: 21 additions & 14 deletions py3status/modules/cmus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*(default '[\?if=is_started [\?if=is_playing > ][\?if=is_paused \|\| ]'
'[\?if=is_stopped .. ][[{artist}][\?soft - ][{title}]'
'|\?show cmus: waiting for user input]]')*
replacements: specify a list/dict of string placeholders to modify (default None)
sleep_timeout: sleep interval for this module. when cmus is not running,
this interval will be used. this allows some flexible timing where one
might want to refresh constantly with some placeholders... or to refresh
Expand Down Expand Up @@ -100,6 +101,7 @@ class Py3status:
r"[\?if=is_stopped .. ][[{artist}][\?soft - ][{title}]"
r"|\?show cmus: waiting for user input]]"
)
replacements = None
sleep_timeout = 20

def post_config_hook(self):
Expand All @@ -109,6 +111,7 @@ def post_config_hook(self):
self.color_stopped = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD
self.color_paused = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED
self.color_playing = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD
self.replacements_init = self.py3.get_replacements_list(self.format)

def _seconds_to_time(self, value):
m, s = divmod(int(value), 60)
Expand Down Expand Up @@ -165,14 +168,14 @@ def cmus(self):
cached_until = self.sleep_timeout
color = self.py3.COLOR_BAD

is_started, data = self._get_cmus_data()
is_started, cmus_data = self._get_cmus_data()

if is_started:
cached_until = self.cache_timeout
data = self._organize_data(data)
data = self._manipulate_data(data)
cmus_data = self._organize_data(cmus_data)
cmus_data = self._manipulate_data(cmus_data)

status = data.get("status")
status = cmus_data.get("status")
if status == "playing":
is_playing = True
color = self.color_playing
Expand All @@ -183,19 +186,23 @@ def cmus(self):
is_stopped = True
color = self.color_stopped

for x in self.replacements_init:
if x in cmus_data:
cmus_data[x] = self.py3.replace(cmus_data[x], x)

cmus_data.update(
{
"is_paused": is_paused,
"is_playing": is_playing,
"is_started": is_started,
"is_stopped": is_stopped,
}
)

return {
"cached_until": self.py3.time_in(cached_until),
"color": color,
"full_text": self.py3.safe_format(
self.format,
dict(
is_paused=is_paused,
is_playing=is_playing,
is_started=is_started,
is_stopped=is_stopped,
**data,
),
),
"full_text": self.py3.safe_format(self.format, cmus_data),
}

def on_click(self, event):
Expand Down
12 changes: 9 additions & 3 deletions py3status/modules/conky.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,15 @@ def post_config_hook(self):
tmp = f"conky.config = {config}\nconky.text = [[{text}]]"

# write tmp output to '/tmp/py3status-conky_*', make a command
self.tmpfile = NamedTemporaryFile(
prefix="py3status_conky-", suffix=".conf", delete_on_close=False
)
try:
# python 3.12+
self.tmpfile = NamedTemporaryFile(
prefix="py3status_conky-", suffix=".conf", delete_on_close=False
)
except TypeError:
self.tmpfile = NamedTemporaryFile(
prefix="py3status_conky-", suffix=".conf", delete=False
)
self.tmpfile.write(str.encode(tmp))
self.tmpfile.close()
self.conky_command = f"conky -c {self.tmpfile.name}".split()
Expand Down
7 changes: 7 additions & 0 deletions py3status/modules/deadbeef.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Configuration parameters:
cache_timeout: refresh interval for this module (default 5)
format: display format for this module (default '[{artist} - ][{title}]')
replacements: specify a list/dict of string placeholders to modify (default None)
sleep_timeout: when deadbeef is not running, this interval will be used
to allow faster refreshes with time-related placeholders and/or
to refresh few times per minute rather than every few seconds
Expand Down Expand Up @@ -58,6 +59,7 @@ class Py3status:
# available configuration parameters
cache_timeout = 5
format = "[{artist} - ][{title}]"
replacements = None
sleep_timeout = 20

class Meta:
Expand Down Expand Up @@ -89,6 +91,7 @@ def post_config_hook(self):
self.color_paused = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED
self.color_playing = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD
self.color_stopped = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD
self.replacements_init = self.py3.get_replacements_list(self.format)

def _is_running(self):
try:
Expand Down Expand Up @@ -124,6 +127,10 @@ def deadbeef(self):
else:
color = self.color_paused

for x in self.replacements_init:
if x in beef_data:
beef_data[x] = self.py3.replace(beef_data[x], x)

return {
"cached_until": self.py3.time_in(cached_until),
"full_text": self.py3.safe_format(self.format, beef_data),
Expand Down
15 changes: 10 additions & 5 deletions py3status/modules/external_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
Display output of any executable script set by `script_path`. Only the first
two lines of output will be used. The first line is used as the displayed
text. If the output has two or more lines, the second line is set as the text
color (and should hence be a valid hex color code such as #FF0000 for red).
text. If the output has two or more lines, the second line contains additional
information as whitespace separated tokens. Valid tokens are:
`#rrggbb`: the text color as a hex color code (eg. `#FF0000` for red)
`urgent`: the word `urgent` to set the urgent flag
The script should not have any parameters, but it could work.
Configuration parameters:
Expand Down Expand Up @@ -75,9 +77,12 @@ def external_script(self):
)
output_lines = self.output.splitlines()
if len(output_lines) > 1:
output_color = output_lines[1]
if re.search(r"^#[0-9a-fA-F]{6}$", output_color):
response["color"] = output_color
words = output_lines[1].split()
for word in words:
if re.search(r"^#[0-9a-fA-F]{6}$", word):
response["color"] = word
elif word == "urgent":
response["urgent"] = True
except self.py3.CommandError as e:
# something went wrong show error to user
output = e.output or e.error
Expand Down
24 changes: 16 additions & 8 deletions py3status/modules/getjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@
Examples:
```
# straightforward key replacement
url = 'http://ip-api.com/json'
format = '{lat}, {lon}'
getjson {
url = "https://ifconfig.co/json"
format = "{latitude}, {longitude}"
}
# access child objects
url = 'https://api.icndb.com/jokes/random'
format = '{value-joke}'
getjson {
url = 'https://api.icndb.com/jokes/random'
format = '{value-joke}'
}
# access title from 0th element of articles list
url = 'https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey={KEY}'
format = '{articles-0-title}'
getjson {
url = 'https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey={KEY}'
format = '{articles-0-title}'
}
# access if top-level object is a list
url = 'https://jsonplaceholder.typicode.com/posts/1/comments'
format = '{0-name}'
getjson {
url = 'https://jsonplaceholder.typicode.com/posts/1/comments'
format = '{0-name}'
}
```
@author vicyap
Expand Down
27 changes: 17 additions & 10 deletions py3status/modules/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
format: display format for this module
*(default '\?if=is_started [\?if=is_stopped \[\] moc|'
'[\?if=is_paused \|\|][\?if=is_playing >] {title}]')*
replacements: specify a list/dict of string placeholders to modify (default None)
sleep_timeout: when moc is not running, this interval will be used to
allow one to refresh constantly with time placeholders and/or
to refresh once every minute rather than every few seconds
Expand Down Expand Up @@ -88,6 +89,7 @@ class Py3status:
r"\?if=is_started [\?if=is_stopped \[\] moc|"
r"[\?if=is_paused \|\|][\?if=is_playing >] {title}]"
)
replacements = None
sleep_timeout = 20

def post_config_hook(self):
Expand All @@ -97,6 +99,7 @@ def post_config_hook(self):
self.color_stopped = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD
self.color_paused = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED
self.color_playing = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD
self.replacements_init = self.py3.get_replacements_list(self.format)

def _get_moc_data(self):
try:
Expand Down Expand Up @@ -133,19 +136,23 @@ def moc(self):
is_stopped = True
color = self.color_stopped

for x in self.replacements_init:
if x in moc_data:
moc_data[x] = self.py3.replace(moc_data[x], x)

moc_data.update(
{
"is_paused": is_paused,
"is_playing": is_playing,
"is_started": is_started,
"is_stopped": is_stopped,
}
)

return {
"cached_until": self.py3.time_in(cached_until),
"color": color,
"full_text": self.py3.safe_format(
self.format,
dict(
is_paused=is_paused,
is_playing=is_playing,
is_started=is_started,
is_stopped=is_stopped,
**data,
),
),
"full_text": self.py3.safe_format(self.format, moc_data),
}

def on_click(self, event):
Expand Down
10 changes: 9 additions & 1 deletion py3status/modules/playerctl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r"""
Display song/video and control players supported by playerctl
Playerctl is a command-line utility for controlling media players
Playerctl is a command-line utility for controlling media players
that implement the MPRIS D-Bus Interface Specification. With Playerctl
you can bind player actions to keys and get metadata about the currently
playing song or video.
Expand All @@ -25,6 +25,7 @@
'[\?if=status=Stopped .. ][[{artist}][\?soft - ][{title}|{player}]]]')*
format_player_separator: show separator if more than one player (default ' ')
players: list of players to track. An empty list tracks all players (default [])
replacements: specify a list/dict of string placeholders to modify (default None)
seek_delta: time (in seconds) to change the playback's position by (default 5)
thresholds: specify color thresholds to use for different placeholders
(default {"status": [("Playing", "good"), ("Paused", "degraded"), ("Stopped", "bad")]})
Expand Down Expand Up @@ -100,6 +101,7 @@ class Py3status:
)
format_player_separator = " "
players = []
replacements = None
seek_delta = 5
thresholds = {"status": [("Playing", "good"), ("Paused", "degraded"), ("Stopped", "bad")]}
volume_delta = 10
Expand All @@ -117,6 +119,7 @@ class Meta:

def post_config_hook(self):
self.thresholds_init = self.py3.get_color_names_list(self.format_player)
self.replacements_init = self.py3.get_replacements_list(self.format_player)
self.position = self.py3.format_contains(self.format_player, "position")
self.cache_timeout = getattr(self, "cache_timeout", 1)

Expand Down Expand Up @@ -283,6 +286,11 @@ def playerctl(self):
if self.position and player_data["status"] == "Playing" and player_data["position"]:
cached_until = self.cache_timeout

# Replace the values
for x in self.replacements_init:
if x in player_data:
player_data[x] = self.py3.replace(player_data[x], x)

# Set the color of a player
for key in self.thresholds_init:
if key in player_data:
Expand Down
Loading

0 comments on commit c139394

Please sign in to comment.