:spark: song_detail automatically switches to latest
Browse files at this commit8ffed3a16463e023f07864f5c3518ab7a17416ddParent: 58c6a6f- feat
- :spark: song_detail automatically switches to latest
4 changed files +64 -13
- .config/hypr/hyprland.conf +1 -1
- .config/mimeapps.list +4 -4
- .config/qt6ct/qt6ct.conf +1 -1
- .config/scripts/shared/song_detail.sh +58 -7
.config/hypr/hyprland.confmodified+1 -1
| @@ -47,7 +47,7 @@ $power_menu = bash ~/.config/scripts/system/power_menu.sh | |||
| 47 | $browser = flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll | 47 | $browser = flatpak run io.github.ungoogled_software.ungoogled_chromium --enable-features=MiddleClickAutoscroll |
| 48 | $browser_unsafe = mullvad-exclude flatpak run com.brave.Browser --incognito --enable-features=MiddleClickAutoscroll | 48 | $browser_unsafe = mullvad-exclude flatpak run com.brave.Browser --incognito --enable-features=MiddleClickAutoscroll |
| 49 | $signal = flatpak run org.signal.Signal | 49 | $signal = flatpak run org.signal.Signal |
| 50 | -$deezer = flatpak run app.zen_browser.zen | 50 | +$deezer = mullvad-exclude flatpak run app.zen_browser.zen |
| 51 | $mainMod = SUPER | 51 | $mainMod = SUPER |
| 52 | $my_trigger = Alt | 52 | $my_trigger = Alt |
| 53 | 53 | ||
.config/mimeapps.listmodified+4 -4
| @@ -1,5 +1,5 @@ | |||
| 1 | - | ||
| 2 | [Default Applications] | 1 | [Default Applications] |
| 3 | -image=org.gnome.Loupe.desktop | 2 | +video/mp4=org.gnome.Showtime.desktop |
| 4 | -image/jpeg=org.gnome.Loupe.desktop | 3 | + |
| 5 | -image/png=org.gnome.Loupe.desktop | 4 | +[Added Associations] |
| 5 | +video/mp4=org.gnome.Showtime.desktop; | ||
.config/qt6ct/qt6ct.confmodified+1 -1
| @@ -24,7 +24,7 @@ underline_shortcut=1 | |||
| 24 | wheel_scroll_lines=3 | 24 | wheel_scroll_lines=3 |
| 25 | 25 | ||
| 26 | [SettingsWindow] | 26 | [SettingsWindow] |
| 27 | -geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x3\0\0\0\0\0\0\0\0\0\0\0\0\x3\xae\0\0\x3\xfd\0\0\0\0\0\0\0\0\0\0\x3\xae\0\0\x3\xfd\0\0\0\0\x2\0\0\0\a\x80\0\0\0\0\0\0\0\0\0\0\x3\xae\0\0\x3\xfd) | 27 | +geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x3\0\0\0\0\0\0\0\0\0\0\0\0\ag\0\0\x3\xfd\0\0\0\0\0\0\0\0\0\0\ag\0\0\x3\xfd\0\0\0\0\x2\0\0\0\a\x80\0\0\0\0\0\0\0\0\0\0\ag\0\0\x3\xfd) |
| 28 | 28 | ||
| 29 | [Troubleshooting] | 29 | [Troubleshooting] |
| 30 | force_raster_widgets=1 | 30 | force_raster_widgets=1 |
.config/scripts/shared/song_detail.shmodified+58 -7
| @@ -1,15 +1,66 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | -# Get current playing song from playerctl | 2 | +# Get current playing song from playerctl, prioritizing the most recently active player |
| 3 | + | ||
| 3 | if command -v playerctl &> /dev/null; then | 4 | if command -v playerctl &> /dev/null; then |
| 4 | # Check if any player is running | 5 | # Check if any player is running |
| 5 | if playerctl status &> /dev/null; then | 6 | if playerctl status &> /dev/null; then |
| 6 | - status=$(playerctl status 2>/dev/null) | 7 | + # Get list of all players and find the one with most recent activity |
| 7 | - artist=$(playerctl metadata artist 2>/dev/null) | 8 | + player_list=$(playerctl -l 2>/dev/null) |
| 8 | - title=$(playerctl metadata title 2>/dev/null) | 9 | + |
| 9 | - duration_us=$(playerctl metadata mpris:length 2>/dev/null) | 10 | + if [[ -z "$player_list" ]]; then |
| 11 | + echo "" | ||
| 12 | + exit 0 | ||
| 13 | + fi | ||
| 14 | + | ||
| 15 | + # Track which player has the most recent activity | ||
| 16 | + most_recent_player="" | ||
| 17 | + most_recent_time=0 | ||
| 18 | + | ||
| 19 | + while IFS= read -r player; do | ||
| 20 | + player_status=$(playerctl -p "$player" status 2>/dev/null) | ||
| 21 | + | ||
| 22 | + # Only consider players that are Playing or Paused | ||
| 23 | + if [[ "$player_status" == "Playing" ]] || [[ "$player_status" == "Paused" ]]; then | ||
| 24 | + # Get the last activity time for this player | ||
| 25 | + activity_cache="/tmp/playerctl_activity_${player}" | ||
| 26 | + | ||
| 27 | + if [[ "$player_status" == "Playing" ]]; then | ||
| 28 | + # Update timestamp for playing player | ||
| 29 | + current_time=$(date +%s) | ||
| 30 | + echo "$current_time" > "$activity_cache" | ||
| 31 | + most_recent_time=$current_time | ||
| 32 | + most_recent_player="$player" | ||
| 33 | + elif [[ -f "$activity_cache" ]]; then | ||
| 34 | + # Check if paused player has a recent activity timestamp | ||
| 35 | + activity_time=$(cat "$activity_cache") | ||
| 36 | + if [[ $activity_time -gt $most_recent_time ]]; then | ||
| 37 | + most_recent_time=$activity_time | ||
| 38 | + most_recent_player="$player" | ||
| 39 | + fi | ||
| 40 | + fi | ||
| 41 | + fi | ||
| 42 | + done <<< "$player_list" | ||
| 43 | + | ||
| 44 | + # If no active player found, exit | ||
| 45 | + if [[ -z "$most_recent_player" ]]; then | ||
| 46 | + echo "" | ||
| 47 | + exit 0 | ||
| 48 | + fi | ||
| 49 | + | ||
| 50 | + status=$(playerctl -p "$most_recent_player" status 2>/dev/null) | ||
| 51 | + | ||
| 52 | + # Exit if media is stopped | ||
| 53 | + if [[ "$status" == "Stopped" ]]; then | ||
| 54 | + echo "" | ||
| 55 | + exit 0 | ||
| 56 | + fi | ||
| 57 | + | ||
| 58 | + artist=$(playerctl -p "$most_recent_player" metadata artist 2>/dev/null) | ||
| 59 | + title=$(playerctl -p "$most_recent_player" metadata title 2>/dev/null) | ||
| 60 | + duration_us=$(playerctl -p "$most_recent_player" metadata mpris:length 2>/dev/null) | ||
| 10 | 61 | ||
| 11 | # Define cache file for paused position | 62 | # Define cache file for paused position |
| 12 | - POSITION_CACHE="/tmp/playerctl_position_cache" | 63 | + POSITION_CACHE="/tmp/playerctl_position_cache_${most_recent_player}" |
| 13 | 64 | ||
| 14 | # Set icon based on playback status | 65 | # Set icon based on playback status |
| 15 | if [[ "$status" == "Playing" ]]; then | 66 | if [[ "$status" == "Playing" ]]; then |
| @@ -30,7 +81,7 @@ if command -v playerctl &> /dev/null; then | |||
| 30 | 81 | ||
| 31 | # Get current position with caching logic | 82 | # Get current position with caching logic |
| 32 | position="" | 83 | position="" |
| 33 | - position_us=$(playerctl position 2>/dev/null) | 84 | + position_us=$(playerctl -p "$most_recent_player" position 2>/dev/null) |
| 34 | 85 | ||
| 35 | if [[ "$status" == "Playing" ]]; then | 86 | if [[ "$status" == "Playing" ]]; then |
| 36 | # When playing, get live position and cache it | 87 | # When playing, get live position and cache it |