Linux Shell获取CCTV5节目单
#!/bin/bash
#查询CCTV5节目表
<<'COMMENT'
API:
https://api.cntv.cn/epg/epginfo?serviceId=tvcctv&c=cctv5&d=20210617&cb=abccctv5&t=jsonp
https://api.cntv.cn/epg/epglist?serviceId=channel&t=jsonp&c=cctv5&cb=tv_box3
COMMENT
jsonp="abccctv5"
epgURL="https://api.cntv.cn/epg/epginfo?serviceId=tvcctv&c=cctv5&d=%date%&cb=abccctv5&t=jsonp"
if [ $# -eq 1 ] && [[ "${1,,}" == "n" ]]
then
today=$(date +"%Y%m%d" -d '+1 day')
else
today=$(date +"%Y%m%d")
fi
jsonData=$(curl -sSfL ${epgURL//%date%/$today}|sed -r "s/^${jsonp}\(//;s/\)\;?\$//")
echo "$jsonData"|jq -r '.cctv5.program[]|.showTime+"\t"+.t'
附:获取CCTV5+节目表代码同理:
#!/bin/bash
#查询CCTV5+节目表
<<'COMMENT'
API:
https://api.cntv.cn/epg/epginfo?serviceId=tvcctv&c=cctv5plus&d=20210617&cb=abccctv5plus&t=jsonp
https://api.cntv.cn/epg/epglist?serviceId=channel&t=jsonp&c=cctv5plus&cb=tv_box3
COMMENT
jsonp="abccctv5plus"
epgURL="https://api.cntv.cn/epg/epginfo?serviceId=tvcctv&c=cctv5plus&d=%date%&cb=abccctv5plus&t=jsonp"
if [ $# -eq 1 ] && [[ "${1,,}" == "n" ]]
then
today=$(date +"%Y%m%d" -d '+1 day')
else
today=$(date +"%Y%m%d")
fi
jsonData=$(curl -sSfL ${epgURL//%date%/$today}|sed -r "s/^${jsonp}\(//;s/\)\;?\$//")
echo "$jsonData"|jq -r '.cctv5plus.program[]|.showTime+"\t"+.t'