Skip to content

Instantly share code, notes, and snippets.

@jfcarr
Created July 27, 2023 01:21
Show Gist options
  • Save jfcarr/89c0a62b6c06f83663e1b8299d5946d3 to your computer and use it in GitHub Desktop.
Save jfcarr/89c0a62b6c06f83663e1b8299d5946d3 to your computer and use it in GitHub Desktop.
Displays a single line of text describing what's currently playing in Rhythmbox
#!/usr/bin/python3
# Example output:
# [ Baba O'Riley | The Who | 1970 (0:05:09)]
import datetime
import subprocess
def get_value(full_array, position):
return full_array[position].rstrip('\n').strip()
def get_time_left(elapsed, duration):
elapsed_array = elapsed.split(':')
elapsed_seconds = (int(elapsed_array[0]) * 60) + int(elapsed_array[1])
duration_array = duration.split(':')
duration_seconds = (int(duration_array[0]) * 60) + int(duration_array[1])
return datetime.timedelta(seconds=(duration_seconds - elapsed_seconds))
result = subprocess.check_output(
"rhythmbox-client --no-start --print-playing-format '%tt ~ %aa ~ %te ~ %td ~ %ay'", shell=True).decode("utf-8").strip()
if result == '':
print("[ Nothing playing ]")
else:
result_items = result.split('~')
title = get_value(result_items, 0)
artist = get_value(result_items, 1)
elapsed = get_value(result_items, 2)
duration = get_value(result_items, 3)
year = get_value(result_items, 4)
if title == '':
print("[ Nothing playing ]")
else:
display_value = f"{title}"
if artist != '':
display_value = f"{display_value} | {artist}"
if year != '':
display_value = f"{display_value} | {year}"
if duration != 'Unknown' and duration != '':
# display_value = f"{display_value} ({elapsed} of {duration})"
display_value = f"{display_value} ({get_time_left(elapsed, duration)})"
display_value = f"[ {display_value} ]"
print(display_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment