Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #sudo apt install -y git ffmpeg fdk-aac-dev rtmpdump vlc mpv youtube-dl aria2
- #+==========================================================+#
- # m3u8-link-checker check m3u8 - m3u files for working links #
- #+==========================================================+#
- # exit status and error codes
- SUCCESS=0 # success exit code
- E_WRONGARGS=65 # wrong number of arguments passed to script
- E_WRONGFILE=66 # wrong file passed to script
- # script usage
- script_usage="Usage: $(basename "$0") [m3u8 or m3u file]"
- #+========================================================+#
- # check arguments passed to scripts #
- #+========================================================+#
- # check number of arguments passed to script and exit if not correct
- [[ $# -eq 1 ]] || { printf "%s\n" "$script_usage"; exit "$E_WRONGARGS"; }
- if [[ "$1" =~ \.m3u8?$ ]]; then # + m3u8 file passed as first argument to script
- file="$1" # - filename is first argument passed to script
- outfile="${file%%.*}-checked.${file##*.}" # - get filename and extension
- else
- printf "%s\n%s\n" "'$1' invalid input" "$script_usage" # + no arguments are passed to the script
- exit "$E_WRONGFILE" # - exit with E_WRONGFILE error code
- fi
- #+========================================================+#
- # while read file check links with ffprobe +#
- #+========================================================+#
- printf "%s\n" "Checking $file for working links"
- while IFS= read -r line # while read m3u8 or m3u file check links with ffprobe
- do
- link=$(printf "%s\n" "$line" | grep -Eo '(http|https)://[a-zA-Z0-9:0-9./?=_@&%|()[:blank:],;-]*' | grep -vP '(http|https|rtmp)://[a-zA-Z0-9:0-9./?=_@&%|()[:blank:],;-]*\.[(jpg|png|gif|svg)]$')
- [[ $? -eq 0 ]] && ffprobe -hide_banner "$link"
- [[ $? -eq 0 ]] && grep -B 1 "$link" "$file" 2>/dev/null | sed -e '/--/d' >> "$outfile"
- done <"$file"
- # check if any working links are found
- [[ -f "$outfile" ]] && sed -i '1i #EXTM3U' "$outfile" || printf "%s\n" "No working links found"
- exit "$SUCCESS" # exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement