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.
 
 
 

74 lignes
2.0 KiB

  1. #!/bin/bash
  2. # Read a list of URLs from stdin, replace suitable social media URLs with correctly capitalised version
  3. errorUrls=()
  4. while read -r url
  5. do
  6. if [[ "${url}" == '* '* ]]
  7. then
  8. prefix="${url::2}"
  9. url="${url:2}"
  10. else
  11. prefix=""
  12. fi
  13. if [[ "${url}" =~ ^https?://((www|m|[a-z][a-z]-[a-z][a-z]).)?facebook.com/([^/]+/?(\?|$)|pages/[^/]+/[0-9]+/?(\?|$)|profile\.php\?id=[0-9]+(&|$)) ]]
  14. then
  15. if [[ "${url}" == *profile.php* ]]
  16. then
  17. url="${url%%&*}"
  18. else
  19. url="${url%%\?*}"
  20. fi
  21. page="$(curl -sL -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept-Language: en-US,en;q=0.5' "https://www.facebook.com/${url#*facebook.com/}")"
  22. user="$(grep -Po '<div\s[^>]*(?<=\s)data-key\s*=\s*"tab_home".*?</div>' <<< "${page}" | grep -Po '<a\s[^>]*(?<=\s)href="/\K[^/]+')"
  23. if [[ "${user}" ]]
  24. then
  25. echo "${prefix}https://www.facebook.com/${user}/"
  26. continue
  27. else
  28. if grep -q 'id="pagelet_loggedout_sign_up"' <<< "${page}"
  29. then
  30. # Profile page which is only visible when logged in
  31. # Extract canonical URL
  32. user="$(grep -Po '<link rel="canonical" href="\K[^"]+' <<< "${page}")"
  33. if [[ "${user}" ]]
  34. then
  35. echo "${prefix}${user}"
  36. continue
  37. fi
  38. fi
  39. fi
  40. errorUrls+=("${url}")
  41. echo "${prefix}${url}"
  42. elif [[ "${url}" =~ ^https?://(www\.)?twitter\.com/[^/]+/?(\?.*)?$ ]]
  43. then
  44. url="${url%%\?*}"
  45. url="${url%/}"
  46. user="$(snscrape --max-results 1 twitter-user "${url##*/}" | grep -Po '^https?://twitter\.com/\K[^/]+')"
  47. if [[ "${user}" ]]
  48. then
  49. echo "${prefix}https://twitter.com/${user}"
  50. else
  51. errorUrls+=("${url}")
  52. echo "${prefix}${url}"
  53. fi
  54. elif [[ "${url}" =~ ^https?://(www\.)?instagram\.com/[^/]+/?$ ]]
  55. then
  56. user="${url%/}"
  57. user="${user##*/}"
  58. echo "${prefix}https://www.instagram.com/${user,,}/"
  59. else
  60. echo "${prefix}${url}"
  61. fi
  62. done
  63. if [[ ${#errorUrls[@]} -gt 0 ]]
  64. then
  65. echo "" >&2
  66. echo "Failed to process URLs:" >&2
  67. for errorUrl in "${errorUrls[@]}"
  68. do
  69. echo "${errorUrl}" >&2
  70. done
  71. fi