Browse Source

Merge branch 'mplayer_alt' of maxime-alves/shcheck into master

Yann Weber 5 years ago
parent
commit
31aa726422
1 changed files with 61 additions and 38 deletions
  1. 61
    38
      check.sh

+ 61
- 38
check.sh View File

@@ -120,7 +120,7 @@ TC_INIT() {
120 120
 }
121 121
 
122 122
 TC_END() {
123
-	
123
+
124 124
 	if [ "$tc_fail" -gt 0 ]
125 125
 	then
126 126
 		if [ "$verbose" -gt 1 ]
@@ -269,10 +269,10 @@ check_html_title() {
269 269
 	echo '<?xml version="1.0"?>
270 270
 <xsl:stylesheet version="1.0"
271 271
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
272
-        <xsl:output method = "text"/>
273
-        <xsl:template match="/">
274
-                <xsl:value-of select="/html/head/title"/>
275
-        </xsl:template>
272
+		<xsl:output method = "text"/>
273
+		<xsl:template match="/">
274
+				<xsl:value-of select="/html/head/title"/>
275
+		</xsl:template>
276 276
 </xsl:stylesheet>' > $tmpxsl
277 277
 
278 278
 	tmphtml=$(mktemp -t html.XXXXXXXXX)
@@ -298,33 +298,56 @@ check_audiostream() {
298 298
 	# Uses mplayer to fetch 128Kb of stream
299 299
 	# $1 Stream URL
300 300
 	# $2 size
301
-	tmpfile=$(mktemp -t check_audiostream.XXXXXXXXX)
302
-	
303
-	sz="$2"
304
-	if [ -z "$sz" ]
305
-	then
306
-		sz="128kb"
307
-	fi
308
-	if [ "$verbose" -gt 1 ]
309
-	then
310
-		logdate INFO "$tc_name: Running mplayer on '$1' for $sz" 3
311
-	fi
301
+	MPLAYER=$(whereis mplayer|cut -d' ' -f2)
302
+	MPV=$(whereis mpv|cut -d' ' -f2)
303
+	if [ -x $MPLAYER ]
304
+	then
305
+		tmpfile=$(mktemp -t check_audiostream.XXXXXXXXX)
306
+		
307
+		sz="$2"
308
+		if [ -z "$sz" ]
309
+		then
310
+			sz="128kb"
311
+		fi
312
+		if [ "$verbose" -gt 1 ]
313
+		then
314
+			logdate INFO "$tc_name: Running mplayer on '$1' for $sz" 3
315
+		fi
312 316
 
313
-	mplayer -endpos $sz -ao pcm:file=$tmpfile "$1" 1>/dev/null 2>/dev/null
314
-	res=$?
315
-	bytes=$(du $tmpfile | cut -f1)
316
-	rm $tmpfile 2>/dev/null
317
+		$MPLAYER -endpos $sz -ao pcm:file=$tmpfile "$1" 1>/dev/null 2>/dev/null
318
+		res=$?
319
+		bytes=$(du $tmpfile | cut -f1)
320
+		rm $tmpfile 2>/dev/null
317 321
 
318
-	if [ "$bytes" -lt 1024 ]
319
-	then
320
-		fail "mplayer retrieved ${bytes}B of stream instead of expected $sz"
321
-		return
322
-	fi
323
-	if [ "$res" -eq 0 ]
322
+		if [ "$bytes" -lt 1024 ]
323
+		then
324
+			fail "mplayer retrieved ${bytes}B of stream instead of expected $sz"
325
+			return
326
+		fi
327
+		if [ "$res" -eq 0 ]
328
+		then
329
+			success "mplayer retrieved $sz of stream on $1"
330
+		else
331
+			fail "mplayer failed to retrieve stream on $1"
332
+		fi
333
+	elif [ -x $MPV ]
324 334
 	then
325
-		success "mplayer retrieved $sz of stream on $1"
326
-	else
327
-		fail "mplayer failed to retrieve stream on $1"
335
+		if [ "$verbose" -gt 1 ]
336
+		then
337
+			logdate INFO "$tc_name: Running mpv on '$1' for $sz" 3
338
+		fi
339
+		tmpfile=$(mktemp -t check_audiostream.XXXXXXXXX)
340
+		$MPV --vo=null --ao=null --o=$tmpfile --of=wav --length 1 "$1" &> /dev/null
341
+		bytes=$(du $tmpfile | cut -f1)
342
+		rm $tmpfile 2>/dev/null
343
+
344
+		if [ "$bytes" -ge 1 ]
345
+		then
346
+			success "mpv read successfully $1"
347
+		else
348
+			fail "mpv could not read $1"
349
+		fi
350
+
328 351
 	fi
329 352
 }
330 353
 
@@ -557,9 +580,9 @@ check_ssh_key() {
557 580
 }
558 581
 
559 582
 check_mpc() {
560
-    # check_mpc [$host [$port] ]
561
-    # tests if you can contact an MPD server in a client way
562
-    # returns the current state of the server
583
+	# check_mpc [$host [$port] ]
584
+	# tests if you can contact an MPD server in a client way
585
+	# returns the current state of the server
563 586
 
564 587
 	host=$1
565 588
 	port=$2
@@ -574,10 +597,10 @@ check_mpc() {
574 597
 		port=6600
575 598
 	fi
576 599
 
577
-    if echo "status" | nc -w 1 "$host" "$port" | head -1 | grep "^OK MPD"
578
-    then
579
-        success "MPD server can be contacted on $host:$port"
580
-        status=$(echo "status" | nc -w 1 "$host" "$port" | grep "^state:"|cut -d: -f2)
581
-        success "It's state is : $status"
582
-    fi
600
+	if echo "status" | nc -w 1 "$host" "$port" | head -1 | grep "^OK MPD"
601
+	then
602
+		success "MPD server can be contacted on $host:$port"
603
+		status=$(echo "status" | nc -w 1 "$host" "$port" | grep "^state:"|cut -d: -f2)
604
+		success "It's state is : $status"
605
+	fi
583 606
 }

Loading…
Cancel
Save