Advertisement
UmbertoKing

IPTV_CheckM3U

Oct 14th, 2017
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #sudo apt install -y git ffmpeg fdk-aac-dev rtmpdump vlc mpv youtube-dl aria2
  4.  
  5. #+==========================================================+#
  6. # m3u8-link-checker check m3u8 - m3u files for working links #
  7. #+==========================================================+#
  8.  
  9. # exit status and error codes
  10. SUCCESS=0      # success exit code
  11. E_WRONGARGS=65 # wrong number of arguments passed to script
  12. E_WRONGFILE=66 # wrong file passed to script
  13.  
  14. # script usage
  15. script_usage="Usage: $(basename "$0") [m3u8 or m3u file]"
  16.  
  17. #+========================================================+#
  18. # check arguments passed to scripts                        #
  19. #+========================================================+#
  20.  
  21. # check number of arguments passed to script and exit if not correct
  22. [[ $# -eq 1 ]] || { printf "%s\n" "$script_usage"; exit "$E_WRONGARGS"; }
  23.  
  24. if [[ "$1" =~ \.m3u8?$ ]]; then        # + m3u8 file passed as first argument to script
  25.     file="$1"                          # - filename is first argument passed to script
  26.     outfile="${file%%.*}-checked.${file##*.}" # - get filename and extension
  27. else
  28.    printf "%s\n%s\n" "'$1' invalid input" "$script_usage" # + no arguments are passed to the script
  29.    exit "$E_WRONGFILE"                 # - exit with E_WRONGFILE error code
  30. fi
  31.  
  32. #+========================================================+#
  33. # while read file check links with ffprobe                +#
  34. #+========================================================+#
  35.  
  36. printf "%s\n" "Checking $file for working links"
  37.  
  38. while IFS= read -r line               # while read m3u8 or m3u file check links with ffprobe
  39. do
  40.   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)]$')
  41.   [[ $? -eq 0 ]] && ffprobe -hide_banner "$link"
  42.   [[ $? -eq 0 ]] && grep -B 1 "$link" "$file" 2>/dev/null | sed -e '/--/d' >> "$outfile"
  43. done <"$file"
  44.  
  45. # check if any working links are found
  46. [[ -f "$outfile" ]] && sed -i '1i #EXTM3U' "$outfile" || printf "%s\n" "No working links found"
  47.  
  48. exit "$SUCCESS" # exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement