summaryrefslogtreecommitdiff
path: root/iptv.sh
diff options
context:
space:
mode:
Diffstat (limited to 'iptv.sh')
-rwxr-xr-xiptv.sh63
1 files changed, 63 insertions, 0 deletions
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 '<?xml version="1.0" encoding="UTF-8"?>' > $output_file
+ echo '<!DOCTYPE tv SYSTEM "xmltv.dtd">' >> $output_file
+ echo "<tv date=\"$(date +"%Y%m%d%H%M%S %z")\">" >> $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 " <channel id=\"$hwcode\">" >> $output_file
+ echo " <display-name lang=\"zh\">$channel_title</display-name>" >> $output_file
+ echo " <icon src=\"$channel_icon\"/>" >> $output_file
+ echo " </channel>" >> $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 " <programme start=\"$schedule_starttime +0800\" stop=\"$schedule_endtime +0800\" channel=\"$hwcode\">" >> $output_file
+ echo " <title lang=\"zh\">$schedule_title</title>" >> $output_file
+ echo " </programme>" >> $output_file
+ done < <(echo "$response" | jq -c '.schedules[]')
+ fi
+ done < <(echo "$response" | jq -c '.areaDatas[].items[]')
+
+ echo '</tv>' >> $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