#!/bin/bash # Given social media links on stdin or as args, this extracts the link in the profile description, if any. function verbose_echo { if [[ "${verbose}" ]] then echo "$@" fi } function fetch { verbose_echo "Fetching $1" >&2 curl -sL -A 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0' "$1" } function fetch_n_extract { url="$1" if [[ "${url}" == *'facebook.com/'* ]] then page="$(fetch "${url}")" if grep -qF '"tab_home"' <<<"${page}" then # Publicly accessible profile grep -Po '"website_url":"\K[^"]+' <<<"${page}" | sed 's,\\/,/,g' | awk '!seen[$0]++' elif grep -qF 'id="pagelet_loggedout_sign_up"' <<< "${page}" then # Profile overview only grep -Po 'href="https://l\.facebook\.com/l\.php\?u=\K[^&]+' <<<"${page}" | sed 's,%3A,:,g; s,%2F,/,g' fi elif [[ "${url}" == *'instagram.com/'* ]] then fetch "${url}" | grep -Po '"external_url":"\K[^"]+' sleep 3 # To avoid getting banned elif [[ "${url}" == *'twitter.com/'* ]] then fetch "${url}" | tr -d '\n' | grep -Po '