diff --git a/check.sh b/check.sh new file mode 100644 index 0000000..7895c55 --- /dev/null +++ b/check.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# 探测 m3u 里的 IPv6 直播源能不能真播。用法: ./check.sh +# 判定: 拿到 #EXTM3U -> 再用 ffprobe 看到视频流才算能播(302 后 403 的算失败) +set -uo pipefail +src="$1" +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT + +case "$src" in + http*) curl -sSL -m 40 -o "$tmp/in.m3u" "$src" ;; + *) cp "$src" "$tmp/in.m3u" ;; +esac +sed -i 's/\r$//' "$tmp/in.m3u" + +# nameurl,只留走 IPv6 的条目:要么是 IPv6 字面量 "://[",要么域名有 AAAA 记录 +awk '/^#EXTINF/{n=$0; sub(/.*,/,"",n); next} + /^http/ && !seen[$0]++ {print n"\t"$0}' "$tmp/in.m3u" > "$tmp/all.tsv" +: > "$tmp/pairs.tsv" +declare -A seen=() aaaa=() +while IFS=$'\t' read -r n u; do + if [[ "$u" == *"://["* ]]; then printf '%s\t%s\n' "$n" "$u" >> "$tmp/pairs.tsv"; continue; fi + h=${u#*://}; h=${h%%/*}; h=${h%%:*} + if [ -z "${seen[$h]:-}" ]; then + seen[$h]=1 + nslookup -type=AAAA "$h" 223.5.5.5 2>/dev/null | grep -q '^Addresses\?:.*:' && aaaa[$h]=1 || aaaa[$h]=0 + fi + [ "${aaaa[$h]}" = 1 ] && printf '%s\t%s\n' "$n" "$u" >> "$tmp/pairs.tsv" +done < "$tmp/all.tsv" + +total=$(wc -l < "$tmp/pairs.tsv") +[ "$total" -eq 0 ] && { echo "没有 IPv6 条目:$src"; exit 1; } + +probe() { + local n="$1" u="$2" body code + body=$(curl -g -sL -m 10 -A "okhttp/3.12.0" "$u" 2>/dev/null | head -c 400) + if ! grep -q '#EXTM3U' <<<"$body"; then echo -e "FAIL\tcurl\t$n\t$u"; return; fi + code=$(ffprobe -v error -rw_timeout 10000000 -select_streams v:0 \ + -show_entries stream=codec_name,width,height -of csv=p=0 "$u" 2>&1 "$tmp/res.tsv" + +echo "IPv6 条目 $total 条" +echo "能播 $(grep -c '^OK' "$tmp/res.tsv") 失败 $(grep -c '^FAIL' "$tmp/res.tsv")" +echo "--- 能播的 ---"; grep '^OK' "$tmp/res.tsv" | cut -f3,4 || echo "(无)" +echo "--- 失败原因 ---"; grep '^FAIL' "$tmp/res.tsv" | cut -f2 | sort | uniq -c