123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #copyright (c) 2016,2023 weber yann
- #
- #this program is free software; you can redistribute it and/or modify
- #it under the terms of the gnu general public license as published by
- #the free software foundation; either version 3 of the license, or
- #any later version.
- #
- #this program is distributed in the hope that it will be useful,
- #but without any warranty; without even the implied warranty of
- #merchantability or fitness for a particular purpose. see the
- #gnu general public license for more details.
- #
- #you should have received a copy of the gnu general public license
- #along with this program. if not, see <http://www.gnu.org/licenses/>.
-
- check_audiostream() {
- # Uses one of mplayer or mpv to retrieve a small amount of stream
- # and attempt to decode it.
- # $1 Stream URL
-
- MPLAYER="$(which mplayer)"
- MPV="$(which mpv)"
- if [ -x "$MPLAYER" ]
- then
- check_audiostream_mplayer "$1"
- elif [ -x "$MPV" ]
- then
- check_audiostream_mpv "$1"
- else
- fail "Unable to find mplayer nor mpv"
- fi
- }
-
- check_audiostream_mplayer() {
- # Uses mplayer to fetch 128Kb (by default) of stream
- # $1 Stream URL
- # $2 size in kb without the kb suffix
- # $3 mplayer path
-
- tmpfile=$(mktemp -t check_audiostream.XXXXXXXXX)
- sz="$2"
- if [ -z "$sz" ]
- then
- sz="128"
- fi
- MPLAYER="$3"
- if [ -z "$MPLAYER" ]
- then
- MPLAYER="$(which mplayer)"
- fi
-
- sz_kb="${sz}kb"
- expt_sz="$(( sz * 8 ))"
-
- if [ "$verbose" -gt 1 ]
- then
- logdate INFO "$tc_name: Running mplayer on '$1' for $sz_kb" 3
- fi
-
- $MPLAYER -endpos "$sz_kb" -ao "pcm:file=$tmpfile" "$1" 1>/dev/null 2>/dev/null
- res="$?"
- bytes=$(du -b "$tmpfile" | cut -f1)
- rm "$tmpfile" 2>/dev/null
-
- if [ "$bytes" -lt $expt_sz ]
- then
- fail "mplayer retrieved ${bytes}B of stream instead of expected $sz_kb"
- return
- fi
- if [ "$res" -eq 0 ]
- then
- success "mplayer retrieved $sz of stream on $1"
- else
- fail "mplayer failed to retrieve stream on $1"
- fi
- }
-
- check_audiostream_mpv() {
- # Uses mpv to fetch 4s of audio stream
- # $1 Stream URL
- # $2 time of stream to fetch
- # $3 mpv path
-
- time="$2"
- if [ -z "$time" ]
- then
- time="4"
- fi
- MPV="$3"
- if [ -z "$MPV" ]
- then
- MPV="$(which mpv)"
- fi
-
-
- if [ "$verbose" -gt 1 ]
- then
- logdate INFO "$tc_name: Running mpv on '$1' for ${time}s" 3
- fi
- start_time=$(date "+%s")
- $MPV --vo=null --ao=null --o=/dev/null --of=wav --length $time "$1" 1> /dev/null 2>/dev/null
- res=$?
- stop_time=$(date "+%s")
- run_time=$(( stop_time - start_time))
-
- if [ "$run_time" -lt "$time" ]
- then
- fail "mpv stopped running ${run_time} after launch but ${time}s should be received"
- return
- fi
-
- if [ "$res" -eq 0 ]
- then
- success "mpv retrieved ${time}s of stream on $1"
- else
- fail "mpv failed to retrieve ${time}s of stream on $1"
- fi
- }
|