The plumber is basically this program that can handle a lot of different filetypes, it knows some
rules about these files and from that it knows what to with whatever it is given, or if it has no logic
it is basically a noop, perhaps an expensive noop.
The plumber technically handles text input, and if it is a file it figures out how to handle that, I am however only interested in the file opening aspect, it is sort of like xdg on linux, which I can't make do the right thing, so I decided I would just write my own.
1.1 Design
My idea is basically 3 parts
1.1.1 Finding all relevant files
I want to find all the relevant files across my whole computer, which can be done by invoking a somewhat complex find command, so I do not need to write this part.
1.1.2 Displaying the files for selection
This has been solved very well several times, I kind of like fzf, another option is dmenu. I prefer fzf since it has the ability to let me bind keys to do dynamic things very easily.
1.1.3 Displaying the selected file.
This program should be able to take any sort of file and do something sensible, if I give it an mp3 file it should start the music player. If I give it a mkv file it should start a video player, and so on.
1.2 Code
I am not exactly sure what language I want to program this in, but at the first pass I think bash shell would be as good as anything else.
file="$1" case $file in *.mp3) mocp -a $file ;; *.ogg) mocp -a $file ;; *.opus) mocp -a $file ;; *.mp4) vlc --playlist-enqueue $file ;; *.mkv) vlc --playlist-enqueue $file ;; *.wmv) vlc --playlist-enqueue $file ;; *.avi) vlc --playlist-enqueue $file ;; *.rm) vlc --playlist-enqueue $file ;; *.mov) vlc --playlist-enqueue $file ;; *.webm) vlc --playlist-enqueue $file ;; *.pdf) mupdf $file ;; *.dvi) mupdf $file ;; esac
Amazing how difficult it can be to dig into the man page of the big programs, vlc is really big, and I could not find anything that did the thing I wanted to have done.
Luckily I found the information online, seems I just missed it.
So I found the option I wanted for vlc, –playlist-enqueue is exactly what I want, if you want you can also do it by configuring vlc to only one instance and any new file is enqueued to the playlist.
However I am sure you can see how this program is coming together, any file I select will go through this 'filter' and be sent to the right program, anything that is not defined yet will probably throw an error, might be I should add a catch all clause at the end.
Now we have to only do a little bit of shell magic to put the pieces together in such a fashion that the pieces actually works together.
But first let me just show the pieces of this thing.
cd ; find ~ /mnt/media -type f \( -name *.mp3 -o -name *.mp4 -o -name *.pdf -o -name *.mkv -o -name *.dvi -o -name *.avi \) 2> /dev/null
This is the invocation of find that does the heavy lifting, do be aware that the 2> /dev/null only is there to make potential errors go away
the invocation I use for fzf is not as complicated but it has a small trick up its sleeve.
fzf --bind "Ctrl-a:execute(mocp -a {})"
plain fzf, only added a singular binding to fzf, this allows me to add several pieces of music to the playlist without closing fzf.
But having these pieces are all good, but the magic is really what happens when the pieces are put together.
search.sh | fzf.sh | xargs sh ~/.local/bin/select.sh $1
This is the system I have created for dealing with my medias, it is very likely that I will do some things with this I will for one probably want to make it better, one in support for more filetypes, and two make it do a better job of figuring out the different filetypes on its own.
Another thing that might eventually happen is making this program in a more serious language. No I will not write it to support another OS.
At least this illustrates the idea I had, right now I am happy with this implementation, technically there is no config file, but editing select.sh kind of allows configuration, unless you want some other config.
2 Final Notes
Now the complex invocation of find is custom to my computer, you would want to at least change the paths that is /mnt/media and ~ to something suitable to you. Also you might want to completely change all the programs mocp is a music player (music on console program), you can change that to your preferred music player, this can be whatever. Vlc is the video player due to the fact that it 1) supports adding to the playlist 2) pretty standard on linux.
If you found any use in this post I would appreciate an upvote. Thanks for reading.