pqiv
pqiv copied to clipboard
Remote control via a socket instead of --actions-from-stdin?
I have a script that makes a string of possibly many image filenames (more than can fit on the command line). In mpv I can make a socket with --input-unix-socket and feed it filenames via stdin. However, it seems in pqiv, there's no way to feed an arbitrarily large number of filenames AND still control pqiv via a script, is there?
I want to be able to add still more images to the list after pqiv has been running for awhile, which --actions-for-stdin allows. This is fantastic! (pqiv is the only image viewer I've found with this capability.) But now I just wish it could be done via a socket instead of stdin. Is this possible? Or, alternately, is there a way to initially feed it with a long list of image filenames?
Why does stdin not work for you in this case? If you need to have the stream available as a named file, mkfifo ctrl && cat ctrl | pqiv --actions-from-stdin would be the easiest way to go. Unix sockets would work through socat.
(I'm trying to understand your use case. If you need a socket to live in pqiv itself / keep stdin for use with something else I can add support, shouldn't be much work.)
The use case is for when someone needs to pass image filenames via stdin too. I have a script that gathers images from all over using a bunch of find commands, randomly picks some, and sorts before piping to my image viewer. Then, later, I might like to add more without quitting first. I wanted this functionality so bad I've thought about using mpv to view images even though it's not as good in other ways as an image viewer. Was so happy to find pqiv!
Also, I think people might prefer a socket over stdin simply due to user-friendliness. The mkfifo and cat method is good, but takes some linux nuts 'n bolts knowledge. Seems like it doesn't always work and takes some fiddling sometimes too (See: https://serverfault.com/questions/188936/writing-to-stdin-of-background-process . I had to play around with the various answers and comments there before I could get --actions-from-stdin to work (namely, using tail -f didn't work for me, but also, the cat ones took a little fiddling), but in mpv I got --input-unix-socket working right away.)
I have experimented with the above mkfifo ctrl && cat ctrl | pqiv --actions-from-stdin, but it doesn't seem to work. I do echo "add_file(/path/to/file.jpg)" | socat - ctrl and pqiv never opens. But if I add some image files on the command line, pqiv opens, and then adding a file via ctrl will work, but note that it will only once unless, after the mkfifo you cat > ctrl &, then cat ctrl | pqiv ....
My version is pqiv 2.11-1-gbaa1697-dirty
A bit more on this. In a bash script, it doesn't work, but if I changed it to:
#!/bin/bash
mkfifo /tmp/ctrl
tail -f /tmp/ctrl | pqiv --actions-from-stdin /path/to/file.jpg &
Then it worked but only once. Further echo "add_file(somefile.jpg)" | socat - /tmp/ctrl didn't work.
I can see the same problem, it is like pqiv stops to read its stdin after the first command.
It works perfectly fine within a terminal, just like below:
pqiv --actions-from-stdin empty.jpg
and entering the actions in the terminal directly.
But could not make it works with a named pipe:
rm -f pqiv.fifo;mkfifo pqiv.fifo && cat pqiv.fifo|pqiv --actions-from-stdin empty.jpg
and entering the actions via multiple commands:
echo "output_file_list()" > pqiv.fifo echo "add_file(48566368131_9af4918954_b.jpg)" > pqiv.fifo
The second command for writing in the named pipe will be blocking because no reader anymore for the pipe (?)