Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions ipregion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ declare -A CUSTOM_SERVICES=(
[JETBRAINS]="JetBrains"
[PLAYSTATION]="PlayStation"
[MICROSOFT]="Microsoft"
[FUBO_TV]="FuboTV"
)

CUSTOM_SERVICES_ORDER=(
Expand All @@ -161,6 +162,7 @@ CUSTOM_SERVICES_ORDER=(
"JETBRAINS"
"PLAYSTATION"
"MICROSOFT"
"FUBO_TV"
)

declare -A CUSTOM_SERVICES_HANDLERS=(
Expand All @@ -187,6 +189,7 @@ declare -A CUSTOM_SERVICES_HANDLERS=(
[JETBRAINS]="lookup_jetbrains"
[PLAYSTATION]="lookup_playstation"
[MICROSOFT]="lookup_microsoft"
[FUBO_TV]="lookup_fubo_tv"
)

declare -A CDN_SERVICES=(
Expand Down Expand Up @@ -1508,6 +1511,14 @@ add_result() {
ipv6=${ipv6//$'\n'/}
ipv6=${ipv6//$'\t'/ }

# For FuboTV, we only store the status (Yes/No/N/A) in the JSON output, ignoring country_code and postal
if [[ "$service" == "FuboTV" && "$ipv4" =~ ^(.*)\|(.*)\|(.*)$ ]]; then
ipv4="${BASH_REMATCH[1]}"
fi
if [[ "$service" == "FuboTV" && "$ipv6" =~ ^(.*)\|(.*)\|(.*)$ ]]; then
ipv6="${BASH_REMATCH[1]}"
fi

case "$group" in
primary) ARR_PRIMARY+=("$service|||$ipv4|||$ipv6") ;;
custom) ARR_CUSTOM+=("$service|||$ipv4|||$ipv6") ;;
Expand Down Expand Up @@ -1560,13 +1571,33 @@ print_table_group() {
if [[ "$v4" == "null" || -z "$v4" ]]; then
v4="$na"
fi
if [[ "$s" == "FuboTV" && "$v4" =~ ^(.*)\|(.*)\|(.*)$ ]]; then
local status="${BASH_REMATCH[1]}"
local country_code="${BASH_REMATCH[2]}"
local postal="${BASH_REMATCH[3]}"
if [[ "$country_code" == "US" && "$postal" != "N/A" ]]; then
v4="$status ($country_code, $postal)"
else
v4="$status ($country_code)"
fi
fi
printf "%s%s" "$separator" "$(format_value "$v4")"
fi

if [[ $show_ipv6 -eq 1 ]]; then
if [[ "$v6" == "null" || -z "$v6" ]]; then
v6="$na"
fi
if [[ "$s" == "FuboTV" && "$v6" =~ ^(.*)\|(.*)\|(.*)$ ]]; then
local status="${BASH_REMATCH[1]}"
local country_code="${BASH_REMATCH[2]}"
local postal="${BASH_REMATCH[3]}"
if [[ "$country_code" == "US" && "$postal" != "N/A" ]]; then
v6="$status ($country_code, $postal)"
else
v6="$status ($country_code)"
fi
fi
printf "%s%s" "$separator" "$(format_value "$v6")"
fi

Expand Down Expand Up @@ -1974,6 +2005,52 @@ lookup_microsoft() {
grep_wrapper --perl '"sRequestCountry":"\K[^"]*' <<<"$response"
}

lookup_fubo_tv() {
local ip_version="$1"
local response is_available color_name country_code postal

response=$(curl_wrapper GET "https://api.fubo.tv/v3/location" \
--ip-version "$ip_version" \
--user-agent "$USER_AGENT")

if [[ "$response" == "$STATUS_DENIED" || "$response" == "$STATUS_SERVER_ERROR" || "$response" == "$STATUS_RATE_LIMIT" ]]; then
is_available="No"
color_name="HEART"
country_code="N/A"
postal="N/A"
elif ! is_valid_json "$response"; then
is_available="N/A"
color_name="NULL"
country_code="N/A"
postal="N/A"
else
is_allowed=$(process_json "$response" ".network_allowed")
country_code=$(process_json "$response" ".country_code2 // \"N/A\"")
if [[ "$is_allowed" == "true" ]]; then
is_available="Yes"
color_name="SERVICE"
else
is_available="No"
color_name="HEART"
fi
if [[ "$country_code" == "US" ]]; then
postal=$(process_json "$response" ".postal // \"N/A\"")
else
postal="N/A"
fi
fi

if [[ "$JSON_OUTPUT" == true ]]; then
echo "$is_available|$country_code|$postal"
else
if [[ "$country_code" == "US" && "$postal" != "N/A" ]]; then
print_value_or_colored "$is_available ($country_code, $postal)" "$color_name"
else
print_value_or_colored "$is_available ($country_code)" "$color_name"
fi
fi
}

main() {
parse_arguments "$@"

Expand Down