Hi Rodrigo,
Just for fun, here is a version which uses curl instead of wget. This has the advantage that curl can output the Content-Type from the server, and we can use this to perform actions instead of relying on the file extension. Another advantage is that curl can tell us the output filename, so we don't have to mess around to get that anymore.
These examples are very useful to test the ideas of rules and actions. Here is how I could imagine it being written:
action youtube label "Open YouTube in MPV" shell "mpv $url" action audio label "Open audio in MPV" shell "mpv $url" action video label "Open video in MPV" shell "mpv $url" action image label "Open image in NSXIV" download shell "nsxiv $out" action mupdf label "Open PDF in MuPDF" download shell "mupdf $out" action default open-new-tab "$url"
match url "outu" action youtube match url "\.(mp3|ogg)$" action audio match url "\.(mkv|mp4|webm)$" action video # From here on Dillo needs to fetch the headers match mime-type "image" action image match mime-type "pdf" action mupdf # Catchall for non-matched urls match any action default
This looks pretty reasonable. I guess the trick is to not make things too complicated, and yet still make it flexible enough.
Although, we may use Dillo to download the content on the fly, like this:
action image label "Open image in NSXIV" pipe "nsxiv -" action mupdf label "Open PDF in MuPDF" pipe "mupdf -"
So there is no need to download the file completely before it is piped to the tools.
I don't think mupdf will open a file piped from stdin. Neither does nsxiv. Maybe I'm missing something. It is possible to determine the Content-Type without downloading the file with something like: curl -XHEAD -s -w '%{content_type}' $url Also, it may be desirable to restrict the download filesize to a reasonable limit, which can also be determined with a similar method.
Anyway, I need to think more about it. I also need to consider how this could be moved out of Dillo, so we don't bring more complexity to it.
Executing a user script is fine, but I also want to be able to rewrite the page and bring it back to Dillo for display, which requires more cooperation.
I'm curious what the use-case for this is. Sounds interesting.
Just a small comment, you can use `exec` to avoid nesting the ifs as it won't return:
if echo $1 | grep outu; then exec $youtube "$1" fi
Or exit:
if echo $1 | grep outu; then $youtube "$1" exit $? fi
Oops! I should know better than that, but there is is.. Thanks for pointing it out. Regards, Alex