summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhineng Li <[email protected]>2026-01-24 11:12:40 +0800
committerZhineng Li <[email protected]>2026-01-24 11:12:40 +0800
commitcaea928cfd4a6eaf28edebc25ec93a533908851f (patch)
tree3e1325f232f344fc531ff7e56f59418523555621
parentffe171f1e53f3b86a673a20d8326d2d204b028eb (diff)
downloadchina-unicom-iptv-gd-caea928cfd4a6eaf28edebc25ec93a533908851f.tar.gz
china-unicom-iptv-gd-caea928cfd4a6eaf28edebc25ec93a533908851f.zip
customize network interface with `-I` or `--interface`
-rwxr-xr-xiptv.sh45
1 files changed, 23 insertions, 22 deletions
diff --git a/iptv.sh b/iptv.sh
index cae7a02..6325d10 100755
--- a/iptv.sh
+++ b/iptv.sh
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
+# cURL configurations applied to all requests
+CURL_ARGS=(--silent --max-time 6)
+
show_usage () {
echo "Usage: $0 [COMMAND] [OPTIONS]"
echo ""
@@ -16,23 +19,23 @@ show_make_playlist_usage () {
echo "Usage: $0 make:playlist -u <user-id> -p <password> -d <device-id> --mac <mac-address>"
echo ""
echo "Options:"
- echo " -u | --user User ID"
- echo " -p | --password Password"
- echo " -d | --device Device ID"
- echo " --ip Device IP address (default: 127.0.0.1)"
- echo " --mac Device MAC address"
- echo " --udpxy Udpxy endpoint (default: http://127.0.0.1:4022)"
- echo " -o | --output Playlist file name (default: playlist.M3U8)"
- echo " --curl Specify the additional cURL arguments"
+ echo " -u | --user User ID"
+ echo " -p | --password Password"
+ echo " -d | --device Device ID"
+ echo " --ip Device IP address (default: 127.0.0.1)"
+ echo " --mac Device MAC address"
+ echo " --udpxy Udpxy endpoint (default: http://127.0.0.1:4022)"
+ echo " -o | --output Playlist file name (default: playlist.M3U8)"
+ echo " -I | --interface Network interface for cURL requests (optional)"
}
show_make_epg_usage () {
echo "Usage: $0 make:epg"
echo ""
echo "Options:"
- echo " --endpoint EPG index endpoint (default: http://120.87.12.38:8083/epg/api/page/biz_59417088.json)"
- echo " -o | --output EPG file name (default: epg.xml)"
- echo " --curl Specify the additional cURL arguments"
+ echo " --endpoint EPG index endpoint (default: http://120.87.12.38:8083/epg/api/page/biz_59417088.json)"
+ echo " -o | --output EPG file name (default: epg.xml)"
+ echo " -I | --interface Network interface for cURL requests (optional)"
}
show_decrypt_authinfo_usage () {
@@ -104,20 +107,19 @@ make_epg () {
# Default variables
local output_file='epg.xml'
local endpoint='http://120.87.12.38:8083/epg/api/page/biz_59417088.json'
- local curl_args=''
while [ $# -gt 0 ]; do
case "$1" in
-o | --output ) output_file="$2"; shift 2;;
--endpoint ) endpoint="$2"; shift 2;;
- --curl ) curl_args="$2"; shift 2;;
+ -I | --interface ) CURL_ARGS+=(--interface "$2"); shift 2;;
-h | --help ) show_make_epg_usage; exit 0;;
*) echo "Unknown option: $1"; exit 1;;
esac
done
step "Request channel index"
- response=$(curl --silent $curl_args "$endpoint")
+ response=$(curl "${CURL_ARGS[@]}" "$endpoint")
step "Create the EPG XML file"
echo '<?xml version="1.0" encoding="UTF-8"?>' > "$output_file"
@@ -132,7 +134,7 @@ make_epg () {
if [[ "$item_type" == "channel" ]]; then
step "Process: $item_title"
- response=$(curl --silent --interface eth0 "$data_link")
+ response=$(curl "${CURL_ARGS[@]}" "$data_link")
channel_icon=$(echo "$response" | jq -r '.channel.icon')
channel_title=$(echo "$response" | jq -r '.channel.title')
hwcode=$(echo "$response" | jq -r '.channel.params.hwcode')
@@ -175,7 +177,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 curl_args=''
local endpoint='http://eds1.unicomgd.com:8082'
while [ $# -gt 0 ]; do
@@ -187,7 +188,7 @@ make_playlist () {
--mac) mac_address="$2"; shift 2;;
--udpxy) udpxy_endpoint="$2"; shift 2;;
-o | --output) output_file="$2"; shift 2;;
- --curl) curl_args="$2"; shift 2;;
+ -I | --interface) CURL_ARGS+=(--interface "$2"); shift 2;;
-h | --help ) show_make_playlist_usage; exit 0;;
*) echo "Unknown option: $1"; exit 1;;
esac
@@ -213,7 +214,7 @@ make_playlist () {
# Retreive Authentication URL
step "Authenticate"
- response=$(curl --silent $curl_args \
+ response=$(curl "${CURL_ARGS[@]}" \
"$endpoint/EDS/jsp/AuthenticationURL?Action=Login&UserID=$user_id&return_type=1")
epgurl=$(echo "$response" | jq -r '.epgurl')
@@ -221,7 +222,7 @@ make_playlist () {
host="${host%%/*}"
# Retreive challenge token
- response=$(curl --silent $curl_args \
+ 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')
@@ -234,7 +235,7 @@ 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 --silent $curl_args \
+ 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')
@@ -242,7 +243,7 @@ make_playlist () {
step "Request channel metas"
declare -A logos
- response=$(curl --silent $curl_args \
+ response=$(curl "${CURL_ARGS[@]}" \
http://120.87.12.38:8083/epg/api/custom/getAllChannel.json)
while read -r channel; do
@@ -253,7 +254,7 @@ make_playlist () {
done < <(echo "$response" | jq -c '.channels[]')
step "Request channels from the batch API"
- response=$(curl --silent $curl_args \
+ response=$(curl "${CURL_ARGS[@]}" \
--data '{"channelcodes":""}' \
--header 'Content-Type: application/json;charset=utf-8' \
--header "Authorization: $access_token" \