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.
 
 
 

66 lignes
1.9 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}" =~ ^https?://((www|m|[a-z][a-z]-[a-z][a-z]).)?facebook.com/([^/]+/?(\?|$)|pages/[^/]+/[0-9]+/?(\?|$)|profile\.php\?id=[0-9]+(&|$)) ]]
  7. then
  8. if [[ "${url}" == *profile.php* ]]
  9. then
  10. url="${url%%&*}"
  11. else
  12. url="${url%%\?*}"
  13. fi
  14. 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/}")"
  15. user="$(grep -Po '<div\s[^>]*(?<=\s)data-key\s*=\s*"tab_home".*?</div>' <<< "${page}" | grep -Po '<a\s[^>]*(?<=\s)href="/\K[^/]+')"
  16. if [[ "${user}" ]]
  17. then
  18. echo "https://www.facebook.com/${user}/"
  19. continue
  20. else
  21. if grep -q 'id="pagelet_loggedout_sign_up"' <<< "${page}"
  22. then
  23. # Profile page which is only visible when logged in
  24. # Extract canonical URL
  25. user="$(grep -Po '<link rel="canonical" href="\K[^"]+' <<< "${page}")"
  26. if [[ "${user}" ]]
  27. then
  28. echo "${user}"
  29. continue
  30. fi
  31. fi
  32. fi
  33. errorUrls+=("${url}")
  34. echo "${url}"
  35. elif [[ "${url}" =~ ^https?://(www\.)?twitter\.com/[^/]+/?(\?.*)?$ ]]
  36. then
  37. url="${url%%\?*}"
  38. url="${url%/}"
  39. user="$(snscrape --max-results 1 twitter-user "${url##*/}" | grep -Po '^https?://twitter\.com/\K[^/]+')"
  40. if [[ "${user}" ]]
  41. then
  42. echo "https://twitter.com/${user}"
  43. else
  44. errorUrls+=("${url}")
  45. echo "${url}"
  46. fi
  47. elif [[ "${url}" =~ ^https?://(www\.)?instagram\.com/[^/]+/?$ ]]
  48. then
  49. user="${url%/}"
  50. user="${user##*/}"
  51. echo "https://www.instagram.com/${user,,}/"
  52. else
  53. echo "${url}"
  54. fi
  55. done
  56. if [[ ${#errorUrls[@]} -gt 0 ]]
  57. then
  58. echo "" >&2
  59. echo "Failed to process URLs:" >&2
  60. for errorUrl in "${errorUrls[@]}"
  61. do
  62. echo "${errorUrl}" >&2
  63. done
  64. fi