The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

93 lignes
2.2 KiB

  1. #!/bin/bash
  2. function fetch_n_extract {
  3. local url="$1"
  4. {
  5. curl -sSL -A 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' "${url}" | \
  6. grep -Fi -e 'facebook' -e 'flickr' -e 'instagram' -e 'twitter' -e 't.me' -e 'youtube' -e 'youtu.be' -e 'vk.com' | \
  7. tee \
  8. >(
  9. # Facebook
  10. grep -Poi 'facebook\.com/(pages/[^/ <"'"'"']+/|groups/)?[^/ <"'"'"']+' | \
  11. sed 's,^,https://www.,' | \
  12. grep -vi -e '^https://www\.facebook\.com/2008$' -e '^https://www\.facebook\.com/tr\?' -e '^https://www\.facebook\.com/plugins$' | \
  13. grep -Pvi '^https://www\.facebook\.com/sharer(\.php\?|\?|$)'
  14. ) \
  15. >(
  16. # Flickr
  17. grep -Poi 'flickr\.com/photos/[^/ <"'"'"']+' | \
  18. sed 's,^,https://www.,'
  19. ) \
  20. >(
  21. # Instagram
  22. grep -Poi 'instagram\.com/[^/ <"'"'"']+' | \
  23. sed 's,^,https://www.,'
  24. ) \
  25. >(
  26. # Telegram
  27. grep -Poi '//(www\.)?t\.me/[^/ <"'"'"']+' | \
  28. sed 's,^//,,; s,^www\.,,; s,^,https://,'
  29. ) \
  30. >(
  31. # Twitter
  32. grep -Poi 'twitter\.com/(hashtag/)?[^/ <"'"'"']+' | \
  33. sed 's,^,https://,' | \
  34. grep -vi -e '^https://twitter\.com/home\?' -e '^https://twitter\.com/widgets\.js$' -e '^https://twitter\.com/share\?' | \
  35. sed 's,\([?&]\)ref_src=[^&]\+&\?,\1,; s,?$,,'
  36. ) \
  37. >(
  38. # VKontakte
  39. grep -Poi 'vk\.com/[^/ <"'"'"']+' | \
  40. sed 's,^,https://,'
  41. ) \
  42. >(
  43. # YouTube
  44. grep -Poi '(youtube\.com/((user|channel|embed)/)?[^/ <"'"'"']+|youtu\.be/[^/ <"'"'"']+)' | \
  45. awk '/^youtube/ { print "https://www." $0 } /^youtu\.be/ { print "https://" $0 }' | \
  46. grep -vi -e '^https://www\.youtube\.com/vi$'
  47. ) \
  48. >/dev/null
  49. } | awk '!seen[$0]++'
  50. }
  51. # Parse options
  52. printInputUrl=
  53. while [[ $# -gt 0 ]]
  54. do
  55. if [[ "$1" == '--print-input-urls' || "$1" == '--print-input-url' ]]
  56. then
  57. printInputUrl=true
  58. shift
  59. elif [[ "$1" == '--' ]]
  60. then
  61. # End of options
  62. shift
  63. break
  64. elif [[ "$1" == '--'* ]]
  65. then
  66. echo "Unknown option: $1" >&2
  67. exit 1
  68. else
  69. # Assume end of options
  70. break
  71. fi
  72. done
  73. {
  74. for arg in "$@"
  75. do
  76. echo "${arg}"
  77. done
  78. if [ ! -t 0 ]
  79. then
  80. cat
  81. fi
  82. } | while read -r url
  83. do
  84. if [[ "${printInputUrl}" ]]
  85. then
  86. echo "${url}"
  87. fi
  88. fetch_n_extract "${url}"
  89. done