diff --git a/files/.config/i3/config b/files/.config/i3/config index c793251..cc8a377 100644 --- a/files/.config/i3/config +++ b/files/.config/i3/config @@ -105,6 +105,8 @@ bindsym $mod+Shift+q kill bindsym $mod+Control+Return exec /bin/bash ~/.config/i3/rofi.bash # start rofi-pass for password autotype bindsym $mod+Shift+Return exec rofi-pass +# start rofi-radio +bindsym $mod+p exec ~/.config/i3/rofi-radio.py # change focus bindsym $mod+h focus left @@ -255,7 +257,7 @@ exec --no-startup-id /bin/dex -a exec --no-startup-id /bin/bash ~/.config/i3/startup.bash bar { - status_command i3status --config ~/.config/i3/i3status.conf + status_command i3status --config ~/.config/i3/i3status.conf | ~/.config/i3/wrapper.py output primary font pango:$font 10 diff --git a/files/.config/i3/i3status.conf b/files/.config/i3/i3status.conf index 9e26dff..234d5a1 100644 --- a/files/.config/i3/i3status.conf +++ b/files/.config/i3/i3status.conf @@ -12,6 +12,7 @@ general { color_degraded = "#E2995C" color_bad = "#B04C50" + output_format = "i3bar" interval = 5 } diff --git a/files/.config/i3/rofi-radio.py b/files/.config/i3/rofi-radio.py new file mode 100755 index 0000000..378b1a8 --- /dev/null +++ b/files/.config/i3/rofi-radio.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +import json +import yaml +import os +import sys + +from subprocess import Popen, PIPE, check_output, check_call + +def mpv_ipc(*args): + try: + j = json.loads(check_output(['mpv-ipc'] + list(args))) + if j: + return j['data'] + except: + pass + return '' + +with open(os.path.expanduser("~/.local/share/playlists.yaml")) as y: + stations = yaml.load(y) + +rofi_command = ['rofi', '-i', '-selected-row', '0', '-dmenu', '-p', 'mpv'] + +current_song = mpv_ipc('get_property_string', 'media-title') +if current_song: + rofi_command += ['-mesg', current_song] + commands = b"Play/Pause\nStop\nNext\nPrevious" +else: + commands = bytes('\n'.join([s["name"] for s in stations]), 'utf8') + +rofi = Popen(rofi_command, stdout=PIPE, stdin=PIPE) +choice = rofi.communicate(input=commands)[0].decode('utf8').rstrip() + +if current_song: + if choice == "Play/Pause": + mpv_ipc('cycle', 'pause') + elif choice == "Stop": + mpv_ipc('stop') +else: + s = [s for s in stations if s["name"] == choice] + if s: + mpv_ipc('loadfile', s[0]["loc"]) + mpv_ipc('set_property_string', 'pause', 'no') + +# force update of i3status +check_call('killall', '-USR1', 'i3status') + diff --git a/files/.config/i3/wrapper.py b/files/.config/i3/wrapper.py new file mode 100755 index 0000000..0f1cce9 --- /dev/null +++ b/files/.config/i3/wrapper.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# This script is a simple wrapper which prefixes each i3status line with custom +# information. It is a python reimplementation of: +# http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.pl +# +# To use it, ensure your ~/.i3status.conf contains this line: +# output_format = "i3bar" +# in the 'general' section. +# Then, in your ~/.i3/config, use: +# status_command i3status | ~/i3status/contrib/wrapper.py +# In the 'bar' section. +# +# In its current version it will display the cpu frequency governor, but you +# are free to change it to display whatever you like, see the comment in the +# source code below. +# +# © 2012 Valentin Haenel +# +# This program is free software. It comes without any warranty, to the extent +# permitted by applicable law. You can redistribute it and/or modify it under +# the terms of the Do What The Fuck You Want To Public License (WTFPL), Version +# 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more +# details. + +import subprocess +import sys +import json + +def get_song_name(): + """ Get the name of the currently playing song """ + try: + j = json.loads(subprocess.check_output(['mpv-ipc', 'get_property_string', 'media-title'])) + if j['data']: + return ' ' + j['data'] + except: + pass + return '' + +def print_line(message): + """ Non-buffered printing to stdout. """ + sys.stdout.write(message + '\n') + sys.stdout.flush() + +def read_line(): + """ Interrupted respecting reader for stdin. """ + # try reading a line, removing any extra whitespace + try: + line = sys.stdin.readline().strip() + # i3status sends EOF, or an empty line + if not line: + sys.exit(3) + return line + # exit on ctrl-c + except KeyboardInterrupt: + sys.exit() + +if __name__ == '__main__': + # Skip the first line which contains the version header. + print_line(read_line()) + + # The second line contains the start of the infinite array. + print_line(read_line()) + + while True: + line, prefix = read_line(), '' + # ignore comma at start of lines + if line.startswith(','): + line, prefix = line[1:], ',' + + j = json.loads(line) + # insert information into the start of the json, but could be anywhere + song_name = get_song_name() + if song_name: + j.insert(0, {'full_text' : '%s' % song_name, 'name' : 'music'}) + # and echo back new encoded json + print_line(prefix+json.dumps(j)) diff --git a/files/.config/mpv/mpv.conf b/files/.config/mpv/mpv.conf index e882bac..530cd31 100644 --- a/files/.config/mpv/mpv.conf +++ b/files/.config/mpv/mpv.conf @@ -1,10 +1,19 @@ -profile=opengl-hq +# video +profile=gpu-hq video-sync=display-resample +x11-bypass-compositor=yes display-fps=60 +interpolation +# audio +af=acompressor + +# filter scale=ewa_lanczossharp cscale=ewa_lanczossharp tscale=oversample +# extra +save-position-on-quit no-sub -interpolation + diff --git a/files/.config/systemd/user/mpv.service b/files/.config/systemd/user/mpv.service new file mode 100644 index 0000000..d065211 --- /dev/null +++ b/files/.config/systemd/user/mpv.service @@ -0,0 +1,8 @@ +[Unit] +Description=mpv - a media player + +[Service] +ExecStart=/usr/bin/mpv --idle --input-ipc-server /tmp/mpv.sock + +[Install] +WantedBy=default.target diff --git a/files/.local/bin/__on-gamemode b/files/.local/bin/__on-gamemode index 47c974e..cfb0f87 100755 --- a/files/.local/bin/__on-gamemode +++ b/files/.local/bin/__on-gamemode @@ -2,7 +2,7 @@ exec 1<&- system_services="cronie" -user_services="compton redshift" +user_services="compton redshift mpv" if [[ "$1" == "start" ]]; then for service in $system_services; do diff --git a/files/.local/bin/mpv-ipc b/files/.local/bin/mpv-ipc new file mode 100755 index 0000000..10dd452 --- /dev/null +++ b/files/.local/bin/mpv-ipc @@ -0,0 +1,4 @@ +#!/bin/bash + +jq -nc --arg argv "$(echo "$@" | tr ' ' '\n')" '{ command: $argv | split("\n") }' | socat - /tmp/mpv.sock 2>/dev/null + diff --git a/files/.local/share/playlists.yaml b/files/.local/share/playlists.yaml new file mode 100644 index 0000000..1cdf884 --- /dev/null +++ b/files/.local/share/playlists.yaml @@ -0,0 +1,4 @@ +- name: Nectarine + loc: http://nectarine.ers35.net:8000/necta192.mp3 +- name: TheBase + loc: http://radio.thebase.sc:8000/stream diff --git a/scripts/post-install.sh b/scripts/post-install.sh index c525b97..addcfcd 100644 --- a/scripts/post-install.sh +++ b/scripts/post-install.sh @@ -3,3 +3,5 @@ # install vim plugins vim -E +"call dein#update()" +"qall!" /dev/null &>/dev/null +systemctl --user enable mpv.service +