История изменений
Исправление superuser, (текущая версия) :
мелкий баг поправил:
#!/bin/bash
MSG() { echo -e "\e[32m$@\e[0m"; }
ERR() { echo -e "\e[31mERROR: $@\e[0m" >&2; exit 1; }
usage(){
echo -e 'Use: coub [-h] [-l Num] source
Options:
-h - Help and exit;
-l - repeat audio Num times or inf for infinity;
source - url | id | file.mp4
Examples:
coub https://coub.com/view/38yafx
coub ~/COUB/Don_t_be_egoistic
coub -l inf 38yafx
'
}
makedesktop(){
ddf="${HOME}/.local/share/applications"
desctopfile="$ddf/coub.desktop"
[ -e "$desctopfile" ] || \
( mkdir -p "$ddf" && \
echo -e '[Desktop Entry]
Encoding=UTF-8
Type=Application
Exec=setsid coub %f
Name=COUB player
Icon=video
' > $desctopfile )
}
CHECKOPT() {
while getopts ":hl:" opt_name
do
case "$opt_name" in
"h") usage; exit 2 ;;
"l") loop=${OPTARG} ;;
":") usage; exit 3 ;;
"?") echo "Unknown option: '-$OPTARG'"; usage; exit 4 ;;
esac
done
}
play(){
[ -n "$loop" ] || loop=1
( mpv --volume=0 --loop=inf "$FV" && kill -9 -$$ ) & mpv --loop=$loop "$FA"; kill -9 -$$
}
playfile(){
#extension="${FV##*.}"
name="${FV%.*}"
FA=$name.mp3
[ -e "$FA" ] && play
ERR "Audio not found."
}
makedesktop
CHECKOPT "$@"
shift "$((OPTIND-1))"
[ -z "$1" ] && usage && exit 1
# FILE ?
FV=$(readlink -e "$1") && MSG "Play file..." && playfile
# ID or URL ?
ID="${1##*/}"
ID="${ID%\?*}"
MSG "ID=$ID"
DL="${HOME}/COUB" # storage for links
DD="$DL/DATA" # storage for media
[ -w "$DD" ] || mkdir -p "$DD" || ERR "Storage not writable."
FV="$DD/$ID.mp4"
FV=$(readlink -e "$FV") && MSG "Play from storage..." && playfile
# download
TS="${TMP:-/tmp/coub.$USER}"
[ -d "$TS" ] || mkdir "$TS" || exit 3
TS="$TS/$ID"
# echo "TS="$TS
[ -e "$TS" ] || wget -q -O "$TS" "https://coub.com/view/$ID" || ERR "download html"
# sed -ne '/^{.*abuses.*}$/p' "$TS" |\
sed -e "1,/<script id='coubPageCoubJson' type='text\/json'>/d" -e "/^<\/script>/,\$d" "$TS" |\
jq .file_versions.html5.video.higher.url,.file_versions.html5.audio.high.url,.title |\
tr -d '"' | (
read V; read A; read T;
[ -z "$V" -o -z "$A" -o -z "$T" ] && ERR "Bad coub"
VE="${V##*.}" # video extension
AE="${A##*.}" # audio extension
FV="$DD/$ID.$VE"
FA="$DD/$ID.$AE"
[ -f "$FV" ] || wget -q -Y off -c -O "$FV" "$V" || ERR "download video."
[ -f "$FA" ] || wget -q -Y off -c -O "$FA" "$A" || ERR "download audio."
T="`echo $T | tr -s '/&$#;* \"\`'\' _`"
ln -s $FV "$DL/$T"
MSG $(ls -l "$DL/$T")
play
)
Исходная версия superuser, :
баг нашол щас поправлю