summaryrefslogtreecommitdiff
path: root/iptv.sh
diff options
context:
space:
mode:
authorZhineng Li <[email protected]>2026-01-24 13:29:59 +0800
committerZhineng Li <[email protected]>2026-01-24 13:29:59 +0800
commitddab55b91d9af60011ceddca3cc589f4027caf01 (patch)
tree104824af4d31f3f729167154a344e892f611fe7e /iptv.sh
parente4108b605da47804d9b44d6c729046051165bb67 (diff)
downloadchina-unicom-iptv-gd-ddab55b91d9af60011ceddca3cc589f4027caf01.tar.gz
china-unicom-iptv-gd-ddab55b91d9af60011ceddca3cc589f4027caf01.zip
extract `retrieve_encry_token` function
Diffstat (limited to 'iptv.sh')
-rwxr-xr-xiptv.sh19
1 files changed, 14 insertions, 5 deletions
diff --git a/iptv.sh b/iptv.sh
index ad2dd04..aa9fd55 100755
--- a/iptv.sh
+++ b/iptv.sh
@@ -98,6 +98,18 @@ extract_hostname () {
printf '%s\n' "$res"
}
+retrieve_encry_token () {
+ local endpoint="$1"
+ local user_id="$2"
+ local url="http://$endpoint/EPG/oauth/v2/authorize?response_type=EncryToken&client_id=jiulian&userid=$user_id"
+ local response
+ local token
+ response=$(curl "${CURL_ARGS[@]}" "$url") || return 1
+ token=$(printf '%s' "$response" | jq -r '.EncryToken') || return 1
+ [[ -n "$token" && "$token" != "null" ]] || return 1
+ printf '%s\n' "$token"
+}
+
build_authinfo () {
local encry_token="$1"
local user_id="$2"
@@ -239,11 +251,8 @@ make_playlist () {
local host
host=$(retrieve_endpoint "$user_id") || fatal 'Failed to retrieve endpoint'
- # Retreive challenge token
- response=$(curl "${CURL_ARGS[@]}" \
- "http://$host/EPG/oauth/v2/authorize?response_type=EncryToken&client_id=jiulian&userid=$user_id")
-
- encry_token=$(echo "$response" | jq -r '.EncryToken')
+ local encry_token
+ encry_token=$(retrieve_encry_token "$host" "$user_id") || fatal 'Failed to retrieve encry token'
# Authenticate
local key