From 2cf2040b055cccc685d8071ed04dd75cc1392042 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Thu, 4 Jul 2024 18:14:33 +0800 Subject: make:epg command --- iptv.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/iptv.sh b/iptv.sh index da80728..e7a23c7 100755 --- a/iptv.sh +++ b/iptv.sh @@ -1,5 +1,67 @@ #!/usr/bin/env bash +make_epg () { + # Default variables + output_file="epg.xml" + endpoint="http://120.87.12.38:8083/epg/api/page/biz_59417088.json" + 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;; + *) echo "Unknown option: $1"; exit 1;; + esac + done + + echo "[-] Request channel index" + + response=$(curl --silent $curl_args "$endpoint") + + echo "[-] Create the EPG XML file" + + echo '' > $output_file + echo '' >> $output_file + echo "" >> $output_file + + while read -r item; do + item_title=$(echo "$item" | jq -r '.itemTitle') + item_type=$(echo "$item" | jq -r '.itemType') + data_link=$(echo "$item" | jq -r '.dataLink') + + if [[ "$item_type" == "channel" ]]; then + echo "[-] Process: $item_title" + + response=$(curl --silent --interface eth0 "$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') + + echo " " >> $output_file + echo " $channel_title" >> $output_file + echo " " >> $output_file + echo " " >> $output_file + + while read -r schedule; do + schedule_title=$(echo "$schedule" | jq -r '.title') + schedule_starttime=$(echo "$schedule" | jq -r '.starttime') + schedule_endtime=$(echo "$schedule" | jq -r '.endtime') + + echo " " >> $output_file + echo " $schedule_title" >> $output_file + echo " " >> $output_file + done < <(echo "$response" | jq -c '.schedules[]') + fi + done < <(echo "$response" | jq -c '.areaDatas[].items[]') + + echo '' >> $output_file + + echo "[-] EPG built sucessfully!" + + exit 0 +} + # Default values ip_address="127.0.0.1" udpxy_endpoint="http://127.0.0.1:4022" @@ -17,6 +79,7 @@ while [ $# -gt 0 ]; do --udpxy) udpxy_endpoint="$2"; shift 2;; -o | --output) output_file="$2"; shift 2;; --curl) curl_args="$2"; shift 2;; + make:epg) shift 1; make_epg "$@";; *) echo "Unknown option: $1"; exit 1;; esac done -- cgit v1.2.3