From e4108b605da47804d9b44d6c729046051165bb67 Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Sat, 24 Jan 2026 13:18:57 +0800 Subject: extract `extract_endpoint` function --- iptv.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'iptv.sh') diff --git a/iptv.sh b/iptv.sh index 832f1fb..ad2dd04 100755 --- a/iptv.sh +++ b/iptv.sh @@ -80,6 +80,24 @@ categorize_by_channel_name () { echo "$result" } +retrieve_endpoint () { + local user_id="$1" + local url="http://eds1.unicomgd.com:8082/EDS/jsp/AuthenticationURL?Action=Login&UserID=$user_id&return_type=1" + local response + local epgurl + response=$(curl "${CURL_ARGS[@]}" "$url") || return 1 + epgurl=$(printf '%s' "$response" | jq -r '.epgurl') + printf '%s\n' "$(extract_hostname "$epgurl")" +} + +extract_hostname () { + local url="$1" + local res + res="${url#*//}" + res="${res%%/*}" + printf '%s\n' "$res" +} + build_authinfo () { local encry_token="$1" local user_id="$2" @@ -182,7 +200,6 @@ make_playlist () { local ip_address='127.0.0.1' local udpxy_endpoint='http://127.0.0.1:4022' local output_file='playlist.M3U8' - local endpoint='http://eds1.unicomgd.com:8082' while [ $# -gt 0 ]; do case "$1" in @@ -219,12 +236,8 @@ make_playlist () { # Retreive Authentication URL step "Authenticate" - response=$(curl "${CURL_ARGS[@]}" \ - "$endpoint/EDS/jsp/AuthenticationURL?Action=Login&UserID=$user_id&return_type=1") - - epgurl=$(echo "$response" | jq -r '.epgurl') - host="${epgurl#*//}" - host="${host%%/*}" + local host + host=$(retrieve_endpoint "$user_id") || fatal 'Failed to retrieve endpoint' # Retreive challenge token response=$(curl "${CURL_ARGS[@]}" \ -- cgit v1.2.3