On Sat, 15 Jun 2024 22:16:12 +0200 Rodrigo Arias <rodarima@gmail.com> wrote:
Thanks! I'm interested in how you are using a script to match several URLs and do some actions automatically, not sure if you would be interesting in sharing it (or some parts).
Sure, here is a very basic example which mainly just goes by the extension in the URL to handle some common filetypes. I suppose that for more complex links in which the filetype can't be parsed like this, you could curl the link into the 'file' command to determine the type: curl -s "https://example.com/filename" | file - But that's overkill for my needs. There are many ways to improve on this, but hopefully it at least illustrates the concept. --------------------------------------------------------------------- #!/bin/sh # Example Dillo URL action handler script # handlers youtube="mpv" audio="mpv" video="mpv" image="nsxiv" pdf="mupdf" # temporary file location tmp_dir="/tmp/dillo" # routine to download link and define $file dl() { if [ ! -d $tmp_dir ] ; then mkdir $tmp_dir ; fi wget "$1" --no-use-server-timestamps -P $tmp_dir file="$tmp_dir/$(ls -tp $tmp_dir | grep -v /$ | head -1)" } # youtube if echo $1 | grep outu then $youtube "$1" else # audio if echo $1 | tail -c -5 | grep -e mp3 -e ogg then $audio "$1" else # video if echo $1 | tail -c -5 | grep -e mkv -e mp4 -e webm then $video "$1" else # images if echo $1 | tail -c -5 | grep -e jpg -e jpeg -e png -e gif -e tif then dl "$1" $image "$file" else # pdf if echo $1 | tail -c -5 | grep pdf then dl "$1" $pdf "$file" fi ; fi ; fi ; fi ; fi ----------------------------------------------------------------------- Regards, Alex