From fa1fe75f772f1bb105e281a9986087642df3460a Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Sat, 24 Jan 2026 13:39:29 +0800 Subject: extract `retrieve_access_token` function --- iptv.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/iptv.sh b/iptv.sh index aa9fd55..b06cdc4 100755 --- a/iptv.sh +++ b/iptv.sh @@ -134,6 +134,19 @@ encrypt_authinfo () { printf '%s\n' "$res" } +retrieve_access_token () { + local endpoint="$1" + local user_id="$2" + local authinfo="$3" + local url="http://$endpoint/EPG/oauth/v2/token?grant_type=EncryToken&client_id=jiulian&UserID=$user_id&DeviceType=UNT400G&DeviceVersion=5.5.021&authinfo=$authinfo&issmarthomestb=1&tvdesktopid=" + local response + local token + response=$(curl "${CURL_ARGS[@]}" "$url") || return 1 + token=$(printf '%s' "$response" | jq -r '.access_token') || return 1 + [[ -n "$token" && "$token" != "null" ]] || return 1 + printf '%s\n' "$token" +} + make_epg () { # Check dependencies ensure_curl_is_installed @@ -262,10 +275,8 @@ make_playlist () { authinfo=$(build_authinfo "$encry_token" "$user_id" "$device_id" "$ip_address" "$mac_address") || fatal 'Failed to build authinfo' authinfo=$(encrypt_authinfo "$authinfo" "$key") || fatal 'Failed to encrypt authinfo' - response=$(curl "${CURL_ARGS[@]}" \ - "http://$host/EPG/oauth/v2/token?grant_type=EncryToken&client_id=jiulian&UserID=$user_id&DeviceType=UNT400G&DeviceVersion=5.5.021&authinfo=$authinfo&issmarthomestb=1&tvdesktopid=") - - access_token=$(echo "$response" | jq -r '.access_token') + local access_token + access_token=$(retrieve_access_token "$host" "$user_id" "$authinfo") || fatal 'Failed to retrieve access token' step "Request channel metas" declare -A logos -- cgit v1.2.3