Skip to content

Instantly share code, notes, and snippets.

@riverscn
Last active December 19, 2023 17:34
Show Gist options
  • Save riverscn/e19479e9ca02867a49fe68558762ee2c to your computer and use it in GitHub Desktop.
Save riverscn/e19479e9ca02867a49fe68558762ee2c to your computer and use it in GitHub Desktop.
中国电信IPTV抓包数据转m3u8播放列表
#!/bin/bash
# Usage: bash gen_iptv_m3u8.sh iptv.pcap
udpxy=192.168.5.1:7088
input=$1
workdir=${input%%.*}
tshark -r $1 -Y 'http.response_for.uri contains getchannellist' -T jsonraw -j data-text-lines_raw \
| awk '/"data-text-lines_raw"/{getline; print}' \
| sed -E 's/"|,//g' \
| xxd -r -p \
| tee \
>(awk -F '[,=?|:"]' '/ChannelName=/ {printf "#EXTINF:-1 tvg-name=\"%s\",%s\nrtp:%s:%s\n", $9, $9, $18, $19}' \
> ${workdir}_rtp.m3u8) \
>(awk -F '[,=?|:"]' '/ChannelName=/ {printf "#EXTINF:-1 tvg-name=\"%s\",%s\nhttp://'"$udpxy"'/udp%s:%s\n", $9, $9, $18, $19}' \
| sed -E 's/udp\/\//udp\//g' > ${workdir}_rtp_http.m3u8) \
>(awk -F '[,=?|:"]' '/ChannelName=/ {printf "#EXTINF:-1 tvg-name=\"%s\",%s\n%s:%s\n", $9, $9, $20, $21}' \
> ${workdir}_rtsp.m3u8) \
>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment