From 7ca49f3768b1cb34d8616b6363d652352b423761 Mon Sep 17 00:00:00 2001 From: woniuzfb <47843848+woniuzfb@users.noreply.github.com> Date: Sun, 5 Dec 2021 11:04:25 +0800 Subject: [PATCH] feat: nbcsn,beinsports,supersport,btsport,premiersports,sky tv schedules --- docs/iptv.sh | 648 ++++++++++++++++++++++++++++++++++++++++-- i18n/iptv.sh.pot | 390 ++++++++++++------------- i18n/po/iptv.sh-en.mo | Bin 27383 -> 27383 bytes iptv.sh | 648 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 1447 insertions(+), 239 deletions(-) diff --git a/docs/iptv.sh b/docs/iptv.sh index dd69201..2584a56 100755 --- a/docs/iptv.sh +++ b/docs/iptv.sh @@ -5,7 +5,7 @@ set -euo pipefail -sh_ver="1.87.1" +sh_ver="1.87.2" sh_debug=0 export LANGUAGE= export LC_ALL= @@ -68,7 +68,7 @@ IBM_CONFIG="$HOME/ibm.json" DEFAULT_DEMOS="default.json" DEFAULT_CHANNELS="channels.json" XTREAM_CODES_CHANNELS="xtream_codes" -USER_AGENT_BROWSER="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36" +USER_AGENT_BROWSER="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36" USER_AGENT_TV="Mozilla/5.0 (QtEmbedded; U; Linux; C)" monitor=false red='\033[31m' @@ -4081,7 +4081,8 @@ RandSegDirName() } # printf %s "$1" | jq -s -R -r @uri -Urlencode() { +Urlencode() +{ local LC_ALL='' LANG=C i c e='' for ((i=0;i<${#1};i++)) do @@ -4092,7 +4093,8 @@ Urlencode() { echo "$e" } -UrlencodeUpper() { +UrlencodeUpper() +{ local LC_ALL='' LANG=C i c e='' for ((i=0;i<${#1};i++)) do @@ -4103,6 +4105,12 @@ UrlencodeUpper() { echo "$e" } +Urldecode() +{ + local i="${*//+/ }" + echo -e "${i//%/\\x}" +} + GetServerIp() { ip=$(dig +short myip.opendns.com @resolver1.opendns.com) || true @@ -9432,7 +9440,7 @@ SetStreamLink() for((try_i=0;try_i<10;try_i++)); do - stream_link_data=$(curl -s -Lm 10 -X POST \ + stream_link_data=$(curl -s -Lm 10 \ -H "User-Agent: $user_agent" \ -H "${headers:0:-4}" \ --data "value=$value" \ @@ -12499,7 +12507,7 @@ StartChannel() for((try_i=0;try_i<10;try_i++)); do - stream_link_data=$(curl -s -Lm 10 -X POST \ + stream_link_data=$(curl -s -Lm 10 \ ${_4gtv_proxy_command[@]+"${_4gtv_proxy_command[@]}"} \ -H "User-Agent: $chnl_user_agent" \ -H "${chnl_headers:0:-4}" \ @@ -13969,6 +13977,16 @@ ListChannelsSchedule() AddChannelsSchedule() { + echo + add_options=( '手动添加' '选择足球比赛' ) + inquirer list_input_index "选择操作" add_options add_options_index + + if [ "$add_options_index" -eq 1 ] + then + + return 0 + fi + ListChannels InputChannelsIndex @@ -16509,7 +16527,7 @@ ScheduleNiotv() "sys_time":"'"$sys_time"'" }' fi - done < <(curl ${niotv_proxy[@]+"${niotv_proxy[@]}"} -s -Lm 10 -H "User-Agent: $USER_AGENT_BROWSER" -X POST --data "act=select&sch_id=$niotv_id&day=$today" "$SCHEDULE_LINK_NIOTV") + done < <(curl ${niotv_proxy[@]+"${niotv_proxy[@]}"} -s -Lm 10 -H "User-Agent: $USER_AGENT_BROWSER" --data "act=select&sch_id=$niotv_id&day=$today" "$SCHEDULE_LINK_NIOTV") if [ "$empty" -eq 1 ] then @@ -17878,6 +17896,463 @@ ScheduleAstro() done } +ScheduleNbcsn() +{ + printf -v today '%(%Y-%m-%d)T' -1 + sys_time=$(date -d $today +%s) + yesterday=$(date --date="yesterday" +"%Y-%m-%d") + min_sys_time=$((sys_time-7200)) + max_sys_time=$((sys_time+86400)) + timestamp=$(date -d "$yesterday 08:00:00" +%s) + + if [ ! -s "$SCHEDULE_JSON" ] + then + printf '{"%s":[]}' "nbcsn" > "$SCHEDULE_JSON" + fi + + IFS=" " read -r -a nbcsn_pro < <(curl -s -L 'https://tvlistings.gracenote.com/gapzap_webapi/api/affiliates/getaffiliatesprop/nbcsports/en-us' \ + -H "User-Agent: $USER_AGENT_BROWSER" | $JQ_FILE -r '[.defaultheadend,.defaultlanguage,.defaultpostalcode,.device,.dstend,.dststart,.dstutcoffset,.stdutcoffset]|join(" ")') + + IFS=" " read -r prgsvcid callsign < <(curl -s -L -H "User-Agent: $USER_AGENT_BROWSER" \ + -d "aid=nbcsports&prgsvcid=&headendId=${nbcsn_pro[0]}&countryCode=USA&postalCode=${nbcsn_pro[2]}&device=${nbcsn_pro[3]}&languagecode=${nbcsn_pro[1]}" \ + https://tvlistings.gracenote.com/api/grid/channelList | $JQ_FILE -r '[([.[].prgsvcid]|join("=")),([.[].callsign]|join("="))]|join(" ")') + + IFS="=" read -r -a prgsvcids <<< "$prgsvcid" + IFS="=" read -r -a callsigns <<< "$callsign" + + nbcsn_indices=("${!prgsvcids[@]}") + + for chnl in "${nbcsn_chnls[@]}" + do + chnl_id=${chnl%%:*} + nbcsn_id=${chnl#*:} + chnl_name=${nbcsn_id#*:} + nbcsn_id=${nbcsn_id%%:*} + + for nbcsn_index in "${nbcsn_indices[@]}" + do + if [ "${callsigns[nbcsn_index]}" == "$nbcsn_id" ] + then + break + fi + done + + schedule="" + + sslgrid=$(curl -s -L -H "User-Agent: $USER_AGENT_BROWSER" \ + -d "timespan=336×tamp=$timestamp&prgsvcid=${prgsvcids[nbcsn_index]}&headendId=${nbcsn_pro[0]}&countryCode=USA&postalCode=${nbcsn_pro[2]}&device=${nbcsn_pro[3]}&userId=-&aid=nbcsports&DSTUTCOffset=+420&STDUTCOffset=+480&DSTStart=$(Urlencode ${nbcsn_pro[5]})&DSTEnd=$(Urlencode ${nbcsn_pro[4]})&languagecode=en-us" \ + https://tvlistings.gracenote.com/api/sslgrid) + + yesterday_schedule=$($JQ_FILE --arg index "$yesterday" --arg min "$min_sys_time" --argjson keys '["title","time","sys_time"]' '.[$index][] | select(.startTime|tonumber > ($min|tonumber)) | .["title"] = .program.title | .["time"] = .startTimeFormatted | .["sys_time"] = .startTime | with_entries( select( .key as $k | $keys | index($k) ) )' <<< "$sslgrid") + today_schedule=$($JQ_FILE --arg index "$today" --arg max "$max_sys_time" --argjson keys '["title","time","sys_time"]' '.[$index][] | select(.startTime|tonumber < ($max|tonumber)) | .["title"] = .program.title | .["time"] = .startTimeFormatted | .["sys_time"] = .startTime | with_entries( select( .key as $k | $keys | index($k) ) )' <<< "$sslgrid") + + schedule="${yesterday_schedule:-}${today_schedule:-}" + + if [ -n "$schedule" ] + then + schedule=$($JQ_FILE -s 'unique_by(.sys_time)' <<< "$schedule") + json=true + jq_path='["'"$chnl_id"'"]' + JQ update "$SCHEDULE_JSON" "$schedule" + Println "$info $chnl_name [$chnl_id] nbcsn 节目表更新成功" + else + Println "$error $chnl_name [$chnl_id] nbcsn 节目表更新失败" + fi + done +} + +ScheduleBeinsports() +{ + if [ ! -s "$SCHEDULE_JSON" ] + then + printf '{"%s":[]}' "beinsportsenglish1" > "$SCHEDULE_JSON" + fi + + printf -v today '%(%Y-%m-%d)T' -1 + sys_time=$(date -d $today +%s) + yesterday=$(date --date="yesterday" +"%Y-%m-%d") + + bs_html=$(curl -s -Lm 20 -H "User-Agent: $USER_AGENT_BROWSER" https://epg.beinsports.com/utctime.php?offset=+8&mins=00&serviceidentity=beinsports.com&category=sports&id=123) + + for chnl in "${bs_chnls[@]}" + do + chnl_id=${chnl%%:*} + bs_id=${chnl#*:} + chnl_name=${bs_id#*:} + bs_id=${bs_id%%:*} + + schedule=() + found=0 + + while IFS= read -r line + do + if [[ $line =~ id=channels_$bs_id\> ]] + then + found=1 + elif [ "$found" -eq 1 ] + then + if [[ $line =~ class=title\>(.+)\ ]] + then + title="${BASH_REMATCH[1]}" + elif [[ $line =~ class=time\>(.+)\ \;-\ \;(.+)\ ]] + then + start_time="${BASH_REMATCH[1]}" + end_time="${BASH_REMATCH[2]}" + + if [ -z "${schedule:-}" ] && [ "${start_time%:*}" -gt "${end_time%:*}" ] + then + sys_time=$(date -d "$yesterday $start_time" +%s) + else + sys_time=$(date -d "$today $start_time" +%s) + fi + + new_schedule=$( + $JQ_FILE -n --arg schedule_title "$title" --arg schedule_time "$start_time" --arg schedule_sys_time "$sys_time" \ + '{ + title: $schedule_title, + time: $schedule_time, + sys_time: $schedule_sys_time + }' + ) + + schedule+=("$new_schedule") + elif [[ $line =~ \\ ]] + then + break + fi + fi + done <<< "$bs_html" + + if [ -n "${schedule:-}" ] + then + file=true + file_json=true + jq_path='["'"$chnl_id"'"]' + JQ update "$SCHEDULE_JSON" schedule + Println "$info $chnl_name [$chnl_id] beinsports 节目表更新成功" + else + Println "$error $chnl_name [$chnl_id] beinsports 节目表更新失败" + fi + done +} + +ScheduleBeinsportsAu() +{ + if [ ! -s "$SCHEDULE_JSON" ] + then + printf '{"%s":[]}' "beinsports1au" > "$SCHEDULE_JSON" + fi + + printf -v today '%(%Y-%m-%d)T' -1 + sys_time=$(date -d $today +%s) + yesterday=$(date --date="yesterday" +"%Y-%m-%d") + + bsau_html=$(curl -s -Lm 20 -H "User-Agent: $USER_AGENT_BROWSER" https://epg.beinsports.com/utctime_au.php?offset=+8&mins=00&id=123) + + for chnl in "${bsau_chnls[@]}" + do + chnl_id=${chnl%%:*} + bsau_id=${chnl#*:} + chnl_name=${bsau_id#*:} + bsau_id=${bsau_id%%:*} + + schedule=() + found=0 + + while IFS= read -r line + do + if [[ $line =~ $bsau_id ]] + then + found=1 + elif [ "$found" -eq 1 ] + then + if [[ $line =~ class=title\>(.+)\ ]] + then + title="${BASH_REMATCH[1]}" + elif [[ $line =~ class=format\>(.+)\ ]] + then + title="$title - ${BASH_REMATCH[1]}" + elif [[ $line =~ class=time\>(.+)\ \;-\ \;(.+)\\ "$SCHEDULE_JSON" + fi + + supersport_schedule=$(curl -s -Lm 20 -H "User-Agent: $USER_AGENT_BROWSER" -H "referer: https://supersport.com/tv-guide" "https://supersport.com/api/videos/tv-guide?timestamps[]=$(date -d 01:00:00 +%s)×tamps[]=$(date -d 23:59:59 +%s)&live=false&country_code=ZA") + + for chnl in "${su_chnls[@]}" + do + chnl_id=${chnl%%:*} + chnl_name="${chnl#*:}" + + schedule=$($JQ_FILE --arg chnl_name "$chnl_name" --argjson keys '["title","time","sys_time"]' '.[] | select(.channel == $chnl_name) | .["time"] = (.starts_at|fromdate|strflocaltime("%H:%M")) | .["sys_time"] = (.starts_at|fromdate) | with_entries( select( .key as $k | $keys | index($k) ) )' <<< "$supersport_schedule") + + if [ -n "$schedule" ] + then + schedule=$($JQ_FILE -s 'unique_by(.sys_time)' <<< "$schedule") + json=true + jq_path='["'"$chnl_id"'"]' + JQ update "$SCHEDULE_JSON" "$schedule" + Println "$info $chnl_name [$chnl_id] SuperSport 节目表更新成功" + else + Println "$error $chnl_name [$chnl_id] SuperSport 节目表更新失败" + fi + done +} + +ScheduleBtsport() +{ + if [ ! -s "$SCHEDULE_JSON" ] + then + printf '{"%s":[]}' "btsport1" > "$SCHEDULE_JSON" + fi + + printf -v today '%(%Y-%m-%d)T' -1 + yesterday=$(date --date="yesterday" +"%Y-%m-%d") + + bt_prop=$(curl -s -Lm 20 -H "User-Agent: $USER_AGENT_BROWSER" -H "referer: https://www.bt.com/" https://widgets.metabroadcast.com/config/1/btsport_v4.js) + bt_prop="${bt_prop#*=}" + bt_prop="${bt_prop%;*}" + bt_prop="${bt_prop%;*}" + bt_channels=$($JQ_FILE -r '.epg.modules.common.channels|join(",")' <<< "$bt_prop") + api_key=$($JQ_FILE -r '.epg.modules.common.apiKey' <<< "$bt_prop") + + btsport_schedule=$(curl -s -Lm 20 -H "User-Agent: $USER_AGENT_BROWSER" -H "referer: https://www.bt.com/" "https://users-atlas.metabroadcast.com/4/schedules.json?id=$bt_channels&annotations=channel,content_detail,content.broadcast_channel&from=${yesterday}T16:00:00.000Z&to=${today}T16:00:00.000Z&source=api.youview.tv&key=$api_key") + + for chnl in "${bt_chnls[@]}" + do + chnl_id=${chnl%%:*} + chnl_name="${chnl#*:}" + + schedule=$($JQ_FILE --arg channel_name "$chnl_name" --argjson keys '["title","time","sys_time"]' '.schedules[] | select(.channel.title == $channel_name).entries[] | .["time"] = (.broadcast.transmission_time|sub("(?