about summary refs log tree commit diff
path: root/pkgs/aszlig/firefox/ff2mpv.py
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2022-10-27 01:37:51 +0200
committeraszlig <aszlig@nix.build>2022-10-27 01:44:28 +0200
commit133af4ac95c3e061f819ce78c6154d2aad8b7154 (patch)
treee6ab74a7ddb92531cb3ee5cbdad9917b6cd364ce /pkgs/aszlig/firefox/ff2mpv.py
parent48c935c59198d831a3ab6a70d75a59f2aa345fff (diff)
workstation: Switch to Nix-managed Firefox
I had this laying around locally for a year now and I'm still not really
happy with some things, for example not having yet full source builds of
the extensions and a few config options not yet managed by Nix (eg.
search engines).

However, since Firefox takes a while to build it's a bit tedious to
always do it directly (and locally) after I update my machines. Having
this part of my workstation profile should make sure that my version of
Firefox is available at all times.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/aszlig/firefox/ff2mpv.py')
-rw-r--r--pkgs/aszlig/firefox/ff2mpv.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/pkgs/aszlig/firefox/ff2mpv.py b/pkgs/aszlig/firefox/ff2mpv.py
new file mode 100644
index 00000000..a983c982
--- /dev/null
+++ b/pkgs/aszlig/firefox/ff2mpv.py
@@ -0,0 +1,38 @@
+import sys
+import struct
+import json
+from subprocess import Popen, DEVNULL
+
+
+def main():
+    message = get_message()
+    url = message.get("url")
+
+    mpv_args = ["--no-terminal", "--pause", "--force-window=immediate"]
+
+    args = ["mpv", *mpv_args, "--", url]
+    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")
+
+
+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()