-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle-url.sh
executable file
·66 lines (50 loc) · 1.43 KB
/
handle-url.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
# Version: 2023-06-03
# Since: 2023-02-20
# About: Downloads or opens resource in web-browser depending on filename extension (if present)
#
if [ $# -eq 0 ]
then
>&2 echo "Usage: $0 <URL>"
exit 1
fi
# Settings:
URL=$1
APPNAME=QuiteRSS-handle-url
XDG_DOWNLOAD_DIR=$( xdg-user-dir DOWNLOAD ); # or source "${HOME}/.config/user-dirs.dirs"
TODAY=$(date '+%Y%m%d')
ERRLOGPATH="/tmp/${APPNAME}.error.$TODAY.log"
FILENAME="${URL##*/}" # "file.mp3?param=val"
FILENAME="${FILENAME%%\?*}" # "file.mp3"
FILEEXT="${FILENAME##*.}" # "mp3"
FILENAME=$( echo "${FILENAME}" | tr '[:upper:]' '[:lower:]' )
FILEEXT=$( echo "${FILEEXT}" | tr '[:upper:]' '[:lower:]' )
case "${FILEEXT}" in
mp4)
DLDIR="${XDG_DOWNLOAD_DIR}"
;&
mp3|ogg)
DLDIR="${XDG_DOWNLOAD_DIR}/mp3"
# Public service radio broadcaster in own folder:
if [[ "${FILENAME}" =~ (drk|dlf|wdr|swr|deutschlandfunk|dertag|derTag) ]]
then
DLDIR="${XDG_DOWNLOAD_DIR}/mp3/oer"
fi
;&
*)
if [ -z ${DLDIR} ]
then
chromium -- "${URL}"
else
notify-send --app-name=${APPNAME} --expire-time=5000 "Downloading" "${FILENAME}"
mkdir -pf "${DLDIR}"
if ! wget -q -O "${DLDIR}/${FILENAME}" -- "${URL}"
then
echo "${URL}" >> "${ERRLOGPATH}"
notify-send --app-name=${APPNAME} --urgency=critical "Error Downloading" "${FILENAME}"
# Remove incomplete file:
rm "${DLDIR}/${FILENAME}"
fi
fi
;;
esac