diff options
author | neodarz <neodarz@neodarz.net> | 2020-10-06 21:43:04 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2020-10-06 21:43:04 +0200 |
commit | a9933887eca7a6885f6f738845f846a5f8f5a114 (patch) | |
tree | 7b8862233827c448e5bf91221c96524592f9b016 | |
parent | 52060dfbdfac04938393b4fdc441415fa08abe6e (diff) | |
download | dotfiles_dotdrop-a9933887eca7a6885f6f738845f846a5f8f5a114.tar.xz dotfiles_dotdrop-a9933887eca7a6885f6f738845f846a5f8f5a114.zip |
Add ability to launch a video via a mpv from firefox
It just send the url to an mpv instance, for example launched via
mpv --idle
-rw-r--r-- | config.yaml | 6 | ||||
-rwxr-xr-x | dotfiles/scripts/ff2mpv.py | 49 | ||||
-rw-r--r-- | dotfiles/waterfox/native-messaging-hosts/ff2mpv.json | 7 | ||||
-rwxr-xr-x | install.sh | 15 |
4 files changed, 76 insertions, 1 deletions
diff --git a/config.yaml b/config.yaml index 88d213a..338851b 100644 --- a/config.yaml +++ b/config.yaml @@ -94,6 +94,9 @@ dotfiles: d_zathura: src: config/zathura dst: ~/.config/zathura + d_waterfox: + src: waterfox + dst: ~/.waterfox profiles: unicorn: dotfiles: @@ -127,6 +130,7 @@ profiles: - d_picom - d_kitty - d_zathura + - d_waterfox pegasus: dotfiles: - d_i3pystatus @@ -156,6 +160,7 @@ profiles: - d_zsh - d_terminator - d_cava + - d_waterfox fenec: dotfiles: - d_i3pystatus @@ -187,3 +192,4 @@ profiles: - f_zshrc - d_zsh - d_zathura + - d_waterfox diff --git a/dotfiles/scripts/ff2mpv.py b/dotfiles/scripts/ff2mpv.py new file mode 100755 index 0000000..acc5d4a --- /dev/null +++ b/dotfiles/scripts/ff2mpv.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import sys +import struct +import json +from subprocess import Popen, DEVNULL + + +def main(): + message = get_message() + url = message.get("url") + + # Need to install playerctl [1] and mpv-mpris [2] + # [1] https://github.com/altdesktop/playerctl + # [2] https://github.com/hoyon/mpv-mpris + # To use with https://addons.mozilla.org/fr/firefox/addon/ff2mpv/ + # Tips: to have mpv in "deamon mode" use mpv --idle + + args = ["playerctl", "--player=mpv", "open", url] + Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) + + args = ["playerctl", "--player=mpv", "play"] + Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) + + # Need to respond something to avoid "Error: An unexpected error occurred" + # in Browser Console. + send_message("ok") + + +# https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging#App_side +def get_message(): + raw_length = sys.stdin.buffer.read(4) + if not raw_length: + return {} + length = struct.unpack("@I", raw_length)[0] + message = sys.stdin.buffer.read(length).decode("utf-8") + return json.loads(message) + + +def send_message(message): + content = json.dumps(message).encode("utf-8") + length = struct.pack("@I", len(content)) + sys.stdout.buffer.write(length) + sys.stdout.buffer.write(content) + sys.stdout.buffer.flush() + + +if __name__ == "__main__": + main() diff --git a/dotfiles/waterfox/native-messaging-hosts/ff2mpv.json b/dotfiles/waterfox/native-messaging-hosts/ff2mpv.json new file mode 100644 index 0000000..78a1186 --- /dev/null +++ b/dotfiles/waterfox/native-messaging-hosts/ff2mpv.json @@ -0,0 +1,7 @@ +{ + "name": "ff2mpv", + "description": "ff2mpv's external manifest", + "path": "/home/neodarz/.scripts/ff2mpv.py", + "type": "stdio", + "allowed_extensions": ["ff2mpv@yossarian.net"] +} @@ -76,7 +76,6 @@ echo "Install pikaur..." echo "[AUR] Install some common app..." -#pikaur -S --noconfirm --needed waterfox-bin #pikaur -S --noconfirm --needed grv #pikaur -S --noconfirm --needed friendly-find @@ -153,6 +152,10 @@ echo "Install i3pystatus..." # needed for update count on i3pystatus #pikaur -S --noconfirm --needed yay +echo "Install waterfox..." + +#pikaur -S --noconfirm --needed waterfox-bin + ## scripts echo "Install packages need by scripts..." @@ -173,6 +176,9 @@ echo "Install packages need by scripts..." #sudo pacman -S --noconfirm --needed tmuxp #sudo pacman -S --noconfirm --needed task +#pikaur -S --noconfirm --needed mpv-mpris +#sudo pacman -S --noconfirm --needed playerctl + ## khal echo "Install khal...." @@ -293,6 +299,13 @@ echo "Configure zathura..." #sudo curl https://raw.githubusercontent.com/pwmt/zathura/develop/data/org.pwmt.zathura.desktop.in -o /usr/share/applications/zathura.desktop #xdg-mime default zathura.desktop application/pdf +echo "Configure waterfox..." + +#Extension need to be installed manually sorry :/ +#https://addons.mozilla.org/fr/firefox/addon/ff2mpv/ +#https://addons.mozilla.org/fr/firefox/addon/ublock-origin/ +#https://addons.mozilla.org/fr/firefox/addon/sponsorblock/ + echo "Hey install is done!" echo "Check arch wiki for driver installation." echo "=> https://wiki.archlinux.org/index.php/Xorg#Driver_installation" |