subserv: custom changes

This commit is contained in:
chayleaf 2023-04-19 01:58:58 +07:00
parent d8d9bab263
commit ea00c35f41
4 changed files with 86 additions and 10 deletions

View file

@ -2,5 +2,5 @@
, ... }:
{
subserv = callPackage ./subserv.nix { };
subserv = callPackage ./subserv { };
}

View file

@ -0,0 +1,22 @@
diff --git a/subserv.html b/subserv.html
index 1fcb5a8..d4b65f8 100644
--- a/subserv.html
+++ b/subserv.html
@@ -51,6 +51,7 @@ function updateText() {
return;
}
+ new_subs_elem.innerHTML = resp.subs[resp.subs.length-1];
if (new_subs_elem.innerHTML != "") {
old_subs_new_node = document.createElement("div");
old_subs_new_node.classList.add("old-sub-el");
@@ -63,8 +64,8 @@ function updateText() {
old_subs_new_node.innerHTML = new_subs_elem.innerHTML;
old_subs_elem.appendChild(old_subs_new_node);
old_subs_new_node.scrollIntoView();
+ new_subs_elem.innerHTML = "";
}
- new_subs_elem.innerHTML = resp.subs[resp.subs.length-1];
for (i = 0; i < resp.subs.length-1; i++) {
if (resp.subs[i] != "") {

View file

@ -1,7 +1,8 @@
{ stdenv
, substituteAll
, fetchFromGitHub
, mpv-unwrapped
, port ? 1337
, port ? 8080
, secondary ? false
, ... }:
@ -14,18 +15,21 @@ stdenv.mkDerivation {
rev = "08e312f02f3d3608d61944247d39148c34215f75";
sha256 = "sha256-CXyp+AAgyocAEbhuMMPVDlAiocozPe8tm/dIUofCRL8=";
};
patches = [
# patch for setting port and whether secondary subs should be shown
# (also removes verbose logs)
(substituteAll {
src = ./settings.patch;
inherit port;
sub_text = if secondary then "secondary-sub-text" else "sub-text";
})
# my custom changes
./custom.patch
];
buildInputs = [ mpv-unwrapped ];
installFlags = [ "SCRIPTS_DIR=$(out)/share/mpv/scripts" ];
stripDebugList = [ "share/mpv/scripts" ];
passthru.scriptName = "subserv.so";
patchPhase = ''
sed -i 's%<client.h>%<mpv/client.h>%' subserv.c
sed -i 's%printf("Hello%// printf("Hello%' subserv.c
sed -i 's%printf("Got event%// printf("Got event%' subserv.c
sed -i 's/PORT 8080/PORT ${builtins.toString port}/' subserv.c
'' + (if secondary then ''
sed -i 's/sub-text/secondary-sub-text/g' subserv.c
'' else "");
buildPhase = ''
gcc -o subserv.so subserv.c -shared -fPIC
'';

View file

@ -0,0 +1,50 @@
diff --git a/subserv.c b/subserv.c
index 82f76a4..bd74cef 100644
--- a/subserv.c
+++ b/subserv.c
@@ -16,10 +16,11 @@
#include <unistd.h>
#include <pthread.h>
-#include <client.h>
+#include <mpv/client.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
-#define PORT 8080
+#define PORT @port@
+#define SUB_TEXT "@sub_text@"
// modifies the buffer, so watch out
// return the number of words in the line and stores pointers to the individual words in word_pointers
@@ -206,7 +207,6 @@ void send_subs(int client_socket) {
if (reccnt == 0) {
return;
}
- printf("read_buf %s\n\n", read_buf);
char * words[3];
int num_words = split_line_into_words(read_buf, words, 3);
@@ -305,13 +305,10 @@ int mpv_open_cplugin(mpv_handle *handle) {
return 0;
}
- printf("Hello world from C plugin '%s'!\n", mpv_client_name(handle));
-
- int obs_ret = mpv_observe_property(handle, 0, "sub-text", MPV_FORMAT_STRING);
+ int obs_ret = mpv_observe_property(handle, 0, SUB_TEXT, MPV_FORMAT_STRING);
while (1) {
mpv_event *event = mpv_wait_event(handle, -1);
- printf("Got event: %d\n", event->event_id);
if (event->event_id == MPV_EVENT_SHUTDOWN)
break;
@@ -319,7 +316,7 @@ int mpv_open_cplugin(mpv_handle *handle) {
if (event->event_id == MPV_EVENT_PROPERTY_CHANGE) {
mpv_event_property* event_prop = (mpv_event_property*)event->data;
- if (strcmp(event_prop->name, "sub-text") == 0) {
+ if (strcmp(event_prop->name, SUB_TEXT) == 0) {
if (event_prop->data == NULL)
continue;