ph1080.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. LC_CTYPE=C
  3. master_m3u="$1"
  4. v_name="$2"
  5. __usage() {
  6. echo "usage: ph1080 <master_m3u_URL>"
  7. exit 1
  8. }
  9. m3u_base_url=$(echo "$master_m3u" | rev | cut -d '/' -f2-10 | rev)
  10. m3u_init_index=$(wget -U mozilla --no-cookie "$master_m3u" -qO- /dev/null \
  11. | grep -E "index-f1")
  12. R_N=$(tr -dc '0-9' < /dev/urandom | head -c 9)
  13. ts_segment_list="${m3u_base_url}/${m3u_init_index}"
  14. main()
  15. {
  16. #
  17. # input_check
  18. #
  19. [ -z "$(echo "$master_m3u" | grep 'master.m3u')" ] && __usage || :
  20. #
  21. # Create random directory for video
  22. #
  23. mkdir -p ./"$R_N"
  24. #
  25. # Generate the list of .ts file segments
  26. #
  27. wget -U -mozilla "$ts_segment_list" -qO- /dev/null | grep seg \
  28. | sed "s|^|${m3u_base_url}/|g" \
  29. > ./"$R_N"/"$R_N".m3u8
  30. #
  31. # Download the .ts files with aria
  32. #
  33. aria2c -x16 -k1M -i ./"$R_N"/"$R_N".m3u8 -d ./"$R_N"
  34. #
  35. # Join the .ts files
  36. #
  37. cat ./"$R_N"/*.ts > ./"$R_N"/out.ts
  38. #
  39. # Join the .ts files into .mp4 video
  40. #
  41. [ -z "$v_name" ] && ffmpeg -i ./"$R_N"/out.ts -codec copy ./"$R_N".mp4 \
  42. || ffmpeg -i ./"$R_N"/out.ts -codec copy ./"$v_name".mp4
  43. #
  44. # Remove the temporary directory
  45. #
  46. rm -rf ./"$R_N"
  47. }
  48. #
  49. # Main function
  50. #
  51. main