diff --git a/.scripts/fetch-weather.sh b/.scripts/fetch-weather.sh index f13a91b..3c653f8 100755 --- a/.scripts/fetch-weather.sh +++ b/.scripts/fetch-weather.sh @@ -1,3 +1,157 @@ -#!/bin/sh +#!/bin/bash -$HOME/.config/eww/Main/scripts/weather --getdata +## Collect data +cache_dir="$HOME/.cache/eww/weather" +cache_weather_stat=${cache_dir}/weather-stat +cache_weather_degree=${cache_dir}/weather-degree +cache_weather_hex=${cache_dir}/weather-hex +cache_weather_icon=${cache_dir}/weather-icon +cache_weather_updatetime=${cache_dir}/weather-updatetime + +if [[ -z "$OPENWEATHER_API_KEY" ]]; then + echo "Please set the OPENWEATHER_API_KEY environment variable." + exit 1 +fi +if [[ -z "$OPENWEATHER_LAT" ]]; then + echo "Please set the OPENWEATHER_LAT environment variable." + exit 1 +fi +if [[ -z "$OPENWEATHER_LON" ]]; then + echo "Please set the OPENWEATHER_LON environment variable." + exit 1 +fi + +## Weather data +KEY=$OPENWEATHER_API_KEY +LAT=$OPENWEATHER_LAT +LON=$OPENWEATHER_LON +UNITS=metric + +## Make cache dir +if [[ ! -d "$cache_dir" ]]; then + mkdir -p ${cache_dir} +fi + +## Get data +get_weather_data() { + weather=`curl -sf "http://api.openweathermap.org/data/3.0/onecall?lat=${LAT}&lon=${LON}&exclude=minutely,hourly,daily&appid=${KEY}&units=${UNITS}"` + echo ${weather} >&2 + weather=$(echo "$weather" | jq -r ".current") + + if [ ! -z "$weather" ]; then + weather_temp=`echo "$weather" | jq ".temp" | cut -d "." -f 1` + weather_icon_code=`echo "$weather" | jq -r ".weather[].icon" | head -1` + weather_description=`echo "$weather" | jq -r ".weather[].description" | head -1 | sed -e "s/\b\(.\)/\u\1/g"` + + #Big long if statement of doom + if [ "$weather_icon_code" == "50d" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "50n" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "01d" ]; then + weather_icon=" " + weather_hex="#e0af68" + elif [ "$weather_icon_code" == "01n" ]; then + weather_icon=" " + weather_hex="#c0caf5" + elif [ "$weather_icon_code" == "02d" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "02n" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "03d" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "03n" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "04d" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "04n" ]; then + weather_icon=" " + weather_hex="#7aa2f7" + elif [ "$weather_icon_code" == "09d" ]; then + weather_icon="" + weather_hex="#7dcfff" + elif [ "$weather_icon_code" == "09n" ]; then + weather_icon="" + weather_hex="#7dcfff" + elif [ "$weather_icon_code" == "10d" ]; then + weather_icon="" + weather_hex="#7dcfff" + elif [ "$weather_icon_code" == "10n" ]; then + weather_icon="" + weather_hex="#7dcfff" + elif [ "$weather_icon_code" == "11d" ]; then + weather_icon="" + weather_hex="#ff9e64" + elif [ "$weather_icon_code" == "11n" ]; then + weather_icon="" + weather_hex="#ff9e64" + elif [ "$weather_icon_code" == "13d" ]; then + weather_icon=" " + weather_hex="#c0caf5" + elif [ "$weather_icon_code" == "13n" ]; then + weather_icon=" " + weather_hex="#c0caf5" + elif [ "$weather_icon_code" == "40d" ]; then + weather_icon=" " + weather_hex="#7dcfff" + elif [ "$weather_icon_code" == "40n" ]; then + weather_icon=" " + weather_hex="#7dcfff" + else + weather_icon=" " + weather_hex="#c0caf5" + fi + echo "$weather_icon" > ${cache_weather_icon} + echo "$weather_description" > ${cache_weather_stat} + echo "$weather_temp""°C" > ${cache_weather_degree} + echo "$weather_hex" > ${cache_weather_hex} + date "+%Y-%m-%d %H:%M:%S" | tee ${cache_weather_updatetime} >/dev/null + else + echo "Weather Unavailable" > ${cache_weather_stat} + echo " " > ${cache_weather_icon} + echo "-" > ${cache_weather_degree} + echo "#adadff" > ${cache_weather_hex} + date "+%Y-%m-%d %H:%M:%S" | tee ${cache_weather_updatetime} >/dev/null + fi +} + +check_network() { + local max=12 + local cnt=0 + + while [ $cnt -lt $max ]; do + if ping -c1 8.8.8.8 &>/dev/null || ping -c1 1.1.1.1 &>/dev/null; then + return 0 + fi + echo "Waiting for network connection... (attempt: $((cnt + 1))/$max)" >&2 + sleep 5 + ((cnt++)) + done + + echo "Network connection failed after $max attempts." >&2 + return 1 +} + +## Execute +if [[ -z "$1" ]]; then + if check_network; then + get_weather_data + fi +elif [[ "$1" == "--icon" ]]; then + cat ${cache_weather_icon} +elif [[ "$1" == "--temp" ]]; then + cat ${cache_weather_degree} +elif [[ "$1" == "--hex" ]]; then + tail -F ${cache_weather_hex} +elif [[ "$1" == "--stat" ]]; then + cat ${cache_weather_stat} +elif [[ "$1" == "--updatetime" ]]; then + cat ${cache_weather_updatetime} +fi \ No newline at end of file diff --git a/eww/Lyrics/eww.yuck b/eww/Lyrics/eww.yuck index a4a9dc0..45e2bd1 100644 --- a/eww/Lyrics/eww.yuck +++ b/eww/Lyrics/eww.yuck @@ -42,10 +42,10 @@ ) (box :class "player-controls-box" :vexpand "false" :hexpand "false" :valign "center" :space-evenly "false" :orientation "h" - (button :class "player-prev" :onclick "playerctl prev --player=spotify" "󰒮") + (button :class "player-prev" :onclick "playerctl previous --player=spotify" "󰒮") (button :class "player-pp" :onclick "playerctl play-pause --player=spotify" "${play-button}") (button :class "player-next" :onclick "playerctl next --player=spotify" "󰒭") - (button :class "lyrics-info" :onclick "ghostty -e '\"$HOME/.local/bin/spotify-lyrics\" fetch -p | less' &" "") + (button :class "lyrics-info" :onclick "ghostty -e '\"$HOME/.local/bin/spotify-lyrics\" fetch | less' &" "") ) (box :class "offset-box" :vexpand "false" :hexpand "true" :valign "center" :halign "center" :space-evenly "false" :orientation "h" @@ -69,7 +69,7 @@ ) (box :class "control-box-single" :vexpand "false" :hexpand "false" :space-evenly "true" :orientation "v" (box :class "control-row-1-single" :space-evenly "false" :orientation "h" - (button :class "info-single" :onclick "ghostty -e '\"$HOME/.local/bin/spotify-lyrics\" fetch -p | less' &" "") + (button :class "info-single" :onclick "ghostty -e '\"$HOME/.local/bin/spotify-lyrics\" fetch | less' &" "") (button :class "offset-plus-single" :onclick "Lyrics/scripts/lyric-offset.py +500" "󰾆") (button :class "offset-reset-single" :onclick "Lyrics/scripts/lyric-offset.py" "󰾅") (button :class "offset-minus-single" :onclick "Lyrics/scripts/lyric-offset.py -500" "󰓅") diff --git a/fastfetch/brief.jsonc b/fastfetch/brief.jsonc index daa4c37..503db8f 100644 --- a/fastfetch/brief.jsonc +++ b/fastfetch/brief.jsonc @@ -1,24 +1,24 @@ { - "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", - "display": { - "key": { - // "width": 14 - } - }, - "modules": [ - { "type": "title" }, - { "type": "separator" }, - { "key": " os", "type": "os" }, - { "key": "┠ host", "type": "host" }, - { "key": "┠ cpu", "type": "cpu" }, - { "key": "┠ gpu", "type": "gpu" }, - { "key": "┖ uptime", "type": "uptime" }, - { "type": "break" }, - { "key": " display", "type": "display" }, - { "key": "┠ wm", "type": "wm" }, - { "key": "┠ de", "type": "de" }, - { "key": "┠ shell", "type": "shell" }, - { "key": "┖ terminal", "type": "terminal" }, - { "type": "break" } - ] + "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", + "display": { + "key": { + // "width": 14 + } + }, + "modules": [ + { "type": "title" }, + { "type": "separator" }, + { "key": " os", "type": "os" }, + { "key": "┠ kernel", "type": "kernel" }, + { "key": "┠ cpu", "type": "cpu" }, + { "key": "┠ gpu", "type": "gpu" }, + { "key": "┖ host", "type": "host" }, + { "type": "break" }, + { "key": " wm", "type": "wm" }, + { "key": "┠ de", "type": "de" }, + { "key": "┠ shell", "type": "shell" }, + { "key": "┠ terminal", "type": "terminal" }, + { "key": "┖ uptime", "type": "uptime" }, + { "type": "break" } + ] } diff --git a/hypr/hyprland/keybinds.conf b/hypr/hyprland/keybinds.conf index 8933480..0daa9d0 100755 --- a/hypr/hyprland/keybinds.conf +++ b/hypr/hyprland/keybinds.conf @@ -22,6 +22,7 @@ bind = Super+Shift, Return, exec, ghostty # [hidden] bind = Alt, Space, exec, pkill rofi || rofi -show drun # [hidden] Launch app launcher bind = Super, Super_L, exec, pkill rofi || rofi -show drun # [hidden] Launch app launcher bind = Super, R, exec, pkill rofi || rofi -show run # Launch command launcher +bind = , mouse:277, exec, killall rofi || rofi -show drun ##! Actions # Screenshot, Record, OCR, Color picker, Clipboard history diff --git a/waybar/mediaplayer.py b/waybar/mediaplayer.py deleted file mode 100755 index 7404f48..0000000 --- a/waybar/mediaplayer.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import logging -import sys -import signal -import gi -import json -gi.require_version('Playerctl', '2.0') -from gi.repository import Playerctl, GLib - -logger = logging.getLogger(__name__) - - -def write_output(text, player): - logger.info('Writing output') - - output = {'text': text, - 'class': 'custom-' + player.props.player_name, - 'alt': player.props.player_name} - - sys.stdout.write(json.dumps(output) + '\n') - sys.stdout.flush() - - -def on_play(player, status, manager): - logger.info('Received new playback status') - on_metadata(player, player.props.metadata, manager) - - -def on_metadata(player, metadata, manager): - logger.info('Received new metadata') - track_info = '' - - if player.props.player_name == 'spotify' and \ - 'mpris:trackid' in metadata.keys() and \ - ':ad:' in player.props.metadata['mpris:trackid']: - track_info = 'AD PLAYING' - elif player.get_artist() != '' and player.get_title() != '': - track_info = '{artist} - {title}'.format(artist=player.get_artist(), - title=player.get_title()) - else: - track_info = player.get_title() - - if player.props.status != 'Playing' and track_info: - track_info = ' ' + track_info - write_output(track_info, player) - - -def on_player_appeared(manager, player, selected_player=None): - if player is not None and (selected_player is None or player.name == selected_player): - init_player(manager, player) - else: - logger.debug("New player appeared, but it's not the selected player, skipping") - - -def on_player_vanished(manager, player): - logger.info('Player has vanished') - sys.stdout.write('\n') - sys.stdout.flush() - - -def init_player(manager, name): - logger.debug('Initialize player: {player}'.format(player=name.name)) - player = Playerctl.Player.new_from_name(name) - player.connect('playback-status', on_play, manager) - player.connect('metadata', on_metadata, manager) - manager.manage_player(player) - on_metadata(player, player.props.metadata, manager) - - -def signal_handler(sig, frame): - logger.debug('Received signal to stop, exiting') - sys.stdout.write('\n') - sys.stdout.flush() - # loop.quit() - sys.exit(0) - - -def parse_arguments(): - parser = argparse.ArgumentParser() - - # Increase verbosity with every occurance of -v - parser.add_argument('-v', '--verbose', action='count', default=0) - - # Define for which player we're listening - parser.add_argument('--player') - - return parser.parse_args() - - -def main(): - arguments = parse_arguments() - - # Initialize logging - logging.basicConfig(stream=sys.stderr, level=logging.DEBUG, - format='%(name)s %(levelname)s %(message)s') - - # Logging is set by default to WARN and higher. - # With every occurrence of -v it's lowered by one - logger.setLevel(max((3 - arguments.verbose) * 10, 0)) - - # Log the sent command line arguments - logger.debug('Arguments received {}'.format(vars(arguments))) - - manager = Playerctl.PlayerManager() - loop = GLib.MainLoop() - - manager.connect('name-appeared', lambda *args: on_player_appeared(*args, arguments.player)) - manager.connect('player-vanished', on_player_vanished) - - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) - - for player in manager.props.player_names: - if arguments.player is not None and arguments.player != player.name: - logger.debug('{player} is not the filtered player, skipping it' - .format(player=player.name) - ) - continue - - init_player(manager, player) - - loop.run() - - -if __name__ == '__main__': - main() diff --git a/waybar/modules/mediaplayer.py b/waybar/modules/mediaplayer.py index b9842bc..a5b9dfe 100755 --- a/waybar/modules/mediaplayer.py +++ b/waybar/modules/mediaplayer.py @@ -6,10 +6,13 @@ import signal import sys import logging import argparse -from gi.repository.Playerctl import Player -from gi.repository import Playerctl, GLib + import gi + gi.require_version("Playerctl", "2.0") +from gi.repository import Playerctl, GLib +from gi.repository.Playerctl import Player + logger = logging.getLogger(__name__) @@ -27,15 +30,17 @@ class PlayerManager: self.manager = Playerctl.PlayerManager() self.loop = GLib.MainLoop() self.manager.connect( - "name-appeared", lambda *args: self.on_player_appeared(*args)) + "name-appeared", lambda *args: self.on_player_appeared(*args) + ) self.manager.connect( - "player-vanished", lambda *args: self.on_player_vanished(*args)) + "player-vanished", lambda *args: self.on_player_vanished(*args) + ) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGPIPE, signal.SIG_DFL) self.selected_player = selected_player - self.excluded_player = excluded_player.split(',') if excluded_player else [] + self.excluded_player = excluded_player.split(",") if excluded_player else [] self.init_players() @@ -55,8 +60,7 @@ class PlayerManager: def init_player(self, player): logger.info(f"Initialize new player: {player.name}") player = Playerctl.Player.new_from_name(player) - player.connect("playback-status", - self.on_playback_status_changed, None) + player.connect("playback-status", self.on_playback_status_changed, None) player.connect("metadata", self.on_metadata_changed, None) self.manager.manage_player(player) self.on_metadata_changed(player, player.props.metadata) @@ -67,9 +71,11 @@ class PlayerManager: def write_output(self, text, player): logger.debug(f"Writing output: {text}") - output = {"text": text, - "class": "custom-" + player.props.player_name, - "alt": player.props.player_name} + output = { + "text": text, + "class": "custom-" + player.props.player_name, + "alt": player.props.player_name, + } sys.stdout.write(json.dumps(output) + "\n") sys.stdout.flush() @@ -79,7 +85,9 @@ class PlayerManager: sys.stdout.flush() def on_playback_status_changed(self, player, status, _=None): - logger.debug(f"Playback status changed for player {player.props.player_name}: {status}") + logger.debug( + f"Playback status changed for player {player.props.player_name}: {status}" + ) self.on_metadata_changed(player, player.props.metadata) def get_first_playing_player(self): @@ -116,7 +124,11 @@ class PlayerManager: title = title.replace("&", "&") track_info = "" - if player_name == "spotify" and "mpris:trackid" in metadata.keys() and ":ad:" in player.props.metadata["mpris:trackid"]: + if ( + player_name == "spotify" + and "mpris:trackid" in metadata.keys() + and ":ad:" in player.props.metadata["mpris:trackid"] + ): track_info = "Advertisement" elif artist is not None and title is not None: track_info = f"{artist} - {title}" @@ -130,22 +142,31 @@ class PlayerManager: track_info = " " + track_info # only print output if no other player is playing current_playing = self.get_first_playing_player() - if current_playing is None or current_playing.props.player_name == player.props.player_name: + if ( + current_playing is None + or current_playing.props.player_name == player.props.player_name + ): self.write_output(track_info, player) else: - logger.debug(f"Other player {current_playing.props.player_name} is playing, skipping") + logger.debug( + f"Other player {current_playing.props.player_name} is playing, skipping" + ) def on_player_appeared(self, _, player): logger.info(f"Player has appeared: {player.name}") if player.name in self.excluded_player: logger.debug( - "New player appeared, but it's in exclude player list, skipping") + "New player appeared, but it's in exclude player list, skipping" + ) return - if player is not None and (self.selected_player is None or player.name == self.selected_player): + if player is not None and ( + self.selected_player is None or player.name == self.selected_player + ): self.init_player(player) else: logger.debug( - "New player appeared, but it's not the selected player, skipping") + "New player appeared, but it's not the selected player, skipping" + ) def on_player_vanished(self, _, player): logger.info(f"Player {player.props.player_name} has vanished") @@ -173,10 +194,14 @@ def main(): # Initialize logging if arguments.enable_logging: - logfile = os.path.join(os.path.dirname( - os.path.realpath(__file__)), "media-player.log") - logging.basicConfig(filename=logfile, level=logging.DEBUG, - format="%(asctime)s %(name)s %(levelname)s:%(lineno)d %(message)s") + logfile = os.path.join( + os.path.dirname(os.path.realpath(__file__)), "media-player.log" + ) + logging.basicConfig( + filename=logfile, + level=logging.DEBUG, + format="%(asctime)s %(name)s %(levelname)s:%(lineno)d %(message)s", + ) # Logging is set by default to WARN and higher. # With every occurrence of -v it's lowered by one