Watching Beijing Unicom IPTV on Apple TV

✍🏼 Written on Oct 30, 2023    💡 Updated on Jan 9, 2024
🖥  Note:This article introduces a solution for watching Beijing Unicom IPTV on Apple TV, provided as a reference for those in need.

Preface

In a previous blog post, I discussed home theater solutions, mentioning the use of IPTV program addresses (with .m3u extension) scraped by others online, which can be directly played in iPlayTV. However, these addresses often expire after some time because China Unicom’s IPTV servers periodically update the program streaming URLs, while the address entered on Apple TV remains static and cannot update in time. This article aims to solve this issue.

🚧**Important Notes Before Proceeding:** I use Beijing Unicom broadband, with the **optical modem in bridge mode, the router handling PPPoE, and a soft router R4S connected as a side router**. This tutorial is tailored to this network topology. Other setups, such as "optical modem in bridge mode + R4S as the main router for PPPoE" or "optical modem handling PPPoE + R4S as a side router," may also work, but the key R4S settings might differ slightly from this guide. I recommend researching further to grasp the core principles rather than copying my setup exactly.

🚧Similarly, if your optical modem handles PPPoE directly, you can connect a cable from the modem to a side/main router to convert multicast to unicast. Alternatively, you can play multicast streams directly on supported devices, avoiding the complexity of my method. The approach depends on your home network topology.

🚧This tutorial has only been tested successfully with Beijing Unicom IPTV. Other regions may differ. If you encounter content strongly tied to a specific region, replace it with the appropriate details for your location.

🚧Before making any changes, back up all router and device settings as a precaution.

🚧I use a soft router R4S with two network ports. If your network topology matches mine, ensure your soft router has at least two ports—one to connect to the main router and another to the optical modem.

🚧My home network setup: - Optical modem subnet: 192.168.1.x - Main router subnet: 192.168.5.x - Optical modem IP: 192.168.1.1 - R4S IP: 192.168.5.2 - Main router LAN IP: 192.168.5.1 - Router WAN IP: 192.168.1.2

Verifying Free Access Support

🚧Currently, Beijing Unicom IPTV does not enforce authentication. However, based on my research, some carriers in other regions encrypt or authenticate IPTV, requiring the use of the MAC address from the carrier-provided IPTV box (which handles decryption) to enable playback on any LAN device via a soft router without the box. Implementing this is complex and beyond the scope of this tutorial.

Download VLC in Advance

When using the optical modem in bridge mode with the router handling PPPoE, connecting directly to the modem won’t provide internet access. Therefore, download the VLC media player on your computer beforehand for testing. Download VLC here:

Official download of VLC media player, the best Open Source player - VideoLAN Official download of VLC media player, the best Open Source player https://www.videolan.org/vlc/

Connecting to the Optical Modem

Connect your computer to the IPTV port of the optical modem using a wired connection (if no IPTV port is found on the modem, it means the modem supports hybrid insertion, meaning the ports are not differentiated between broadband and IPTV—any port will work). Then, in the VLC software:

  • Go to File > Open Network.

  • Click on Open RTP/UDP Stream below.

  • Select RTP for Protocol, Multicast for Mode, and enter 239.3.1.241 (or rtp://239.3.1.241—can’t recall which one exactly) for IP Address, and 8000 for the port.

After clicking Open, if you can see Beijing TV, it means you can enjoy it for free.

VLC RTP 播放

💡Here, `rtp://239.3.1.241:8000` is the multicast address for Beijing TV. This address may change in the future. For the most accurate address, you can go to https://raw.githubusercontent.com/qwerttvv/Beijing-IPTV/master/IPTV-Unicom.m3u` and test any IP address following an rtp path.

Explanation of Basic Concepts

Skip to the next section if you’re not interested in the details.

IPTV

According to Wikipedia’s definition of IPTV:

📖Internet Protocol Television (abbreviated as IPTV) is a form of broadband television. IPTV is a system that delivers television content via broadband networks, transmitting broadcast programs through the Internet Protocol (IP) to provide digital TV services to subscribers. Since it requires internet access, IPTV service providers often bundle related services such as internet connectivity and IP telephony, also known as "Triple Play" services. As a type of digital television, conventional TVs need a corresponding set-top box to receive channels, which is why providers typically offer video-on-demand services alongside. Although it uses broadband networks and the Internet Protocol, IPTV does not necessarily rely on the public internet—it often transmits via local area networks to ensure quality.

From this, we can see that IPTV is generally a service provided by broadband providers, allowing users to watch TV through it.

Multicast

A technical method for implementing IPTV playback, known as “multicast” in English. The exact concept isn’t crucial to grasp, but it’s helpful to understand its advantages over unicast:

Advantages include:

  • Does not consume internet bandwidth.

  • The IPTV box serves as an authentication device. Since IPTV operators broadcast to a group, the load on their servers is relatively light.

Disadvantages include:

  • Must be connected via cable to the IPTV port of the optical modem (some modems support mixed ports, meaning they don’t distinguish between IPTV and broadband ports). This restricts usage to devices connected to the IPTV box, preventing WiFi-enabled devices from watching network TV.

Unicast

An older technical method for implementing IPTV playback, used when IPTV had fewer users. Compared to multicast, its disadvantages are the other’s advantages, and vice versa:

Advantages include:

  • Once connected, the local network supports WiFi, allowing any device to play the stream.

Disadvantages include:

  • Requires a one-to-one connection with the server, increasing server load. Playback may lag when there are many users.

  • Consumes broadband bandwidth, as playback is directly conducted over the internet (similar to watching live streams today).

udpxy

udpxy is **a proxy server that converts UDP streams into HTTP streams**, enabling IPTV streams to be played on various devices.

When multicast addresses cannot be obtained directly, they can be converted to unicast addresses. For example, if the multicast addresses are a:b and d:e (where a and d are IP addresses, and b and e are ports), they can be converted into uniform unicast addresses like z/a/b and z/d/e. The player simply needs to listen to the address z.

M3U

**M3U** (short for MP3 URL) is a file format designed for multimedia playlists. Initially created for audio files like MP3, it is now increasingly used by software to play video file lists.

An M3U file is a plain text file containing all the multicast addresses for playback. By reading this file on an Apple TV or computer, the player can access and stream the video addresses listed within.

EPG

EPG (Electronic Program Guide) contains program schedule information. After obtaining the M3U address in the previous step, which consists of individual IP addresses, how does one identify which channel each IP address corresponds to? This is where EPG comes into play—it pairs each address with program details, including brief channel descriptions. EPG data is typically broadcast alongside the video signal.

Network Topology

网络拓扑-主路由拨号

Hands-on Practice

🚧Before starting, check if free usage is supported as mentioned at the beginning.

Setting Up a Soft Router

Installing udpxy and luci-udpxy

This step involves standard operations. The UI installation is the most convenient method, as shown in the image (do not enable it immediately after installation; enable it in the final step):

软件安装界面

Creating/Configuring Network Interfaces

This step ensures the software router can recognize data coming from the optical modem.

  • Under Network > Interfaces, create a new interface and name it arbitrarily, such as IPTV:

新建 IPTV 接口

Pay attention to the arrow-marked part—I’ve already created it, so it shows “IPTV” in parentheses (it wasn’t there when first created). Here, eth1 is my LAN port connected to the main router, while eth0 is another interface connected to the optical modem (IPTV port). I modified this earlier—by default, eth0 is the LAN port and eth1 is the WAN port, but that’s irrelevant. This step repurposes the WAN port as the IPTV port.

  • Configure the gateway hop and firewall settings for the “IPTV” interface:

配置网关跃点

防火墙配置到 wan 上

  • Configure the gateway hop count for the WAN port:

Wan 口网关跃点

  • Configure LAN Port IGMP Snooping:

IGMP 嗅探

  • Configure network firewall

网络防火墙配置

防火墙配置2

Configuring the udpxy Service

  • Configure as shown in the diagram, noting that eth0 here refers to the WAN port—don’t mix it up:

打开 UDPXY

Finally, attempt to open [http://192.168.5.2:4022/status]([object Object]) to verify whether the udpxy service has started successfully:

看到这个就表示成功了

Afterwards, change the address rtp://239.3.1.241:8000 that was previously opened with VLC to `http://192.168.2.1:4022/rtp/239.3.1.241:8000`` and try opening it again (no need to click the “Open RTP/UDP Stream” below; just open it directly in the URL).

尝试将 RTP 变 HTTP 播放

Then simply double-click to play:

成功画面↑

Using Playback Software

I watch TV on Apple TV 4K and have tried several playback apps. Here’s a brief overview:

  • iPlayTV couldn’t play the streams—no idea why.

  • Fileball allowed channel switching up and down, but crashed immediately when selecting a channel.

  • Eventually, I chose “TV+” by the same developer as IIVA, priced at 38 HKD in the Hong Kong region (awkwardly, it went free the day after I bought it).

How to Automatically Update Addresses

The playback addresses for China Unicom’s IPTV change periodically—sometimes the port changes, sometimes the IP address. When this happens, the playback method stops working. So, what’s the solution?

Some kind folks online have performed complex monitoring operations, such as this:

光纤入户光猫改桥接+内网转发IPTV=任意设备看电视直播 - Botian's Blog Warning: This article will involve modifying your local network environment. Some operations may disrupt your internet connection. If you lack relevant networking knowledge, recovery might be difficult, potentially requiring assistance from your ISP. Proceed with caution. Note: Ensure you have your PPPoE account credentials (usually printed on the service agreement provided by your ISP). You can also contact your ISP or check your router settings to find the relevant... https://blog.friskit.me/2020/05/31/bjunicom-network.html

They captured the communication data between the IPTV set-top box and China Unicom’s servers, extracting the addresses. Thus, we can directly use them, such as:

github.com https://github.com/qwerttvv/Beijing-IPTV/blob/master/README.md https://github.com/qwerttvv/Beijing-IPTV/blob/master/README.md

However, there’s one key point here: your home’s soft router address needs to match this kind person’s address (192.168.123.1), and then change the udpxy port to 23234. This way, you can directly input this address into TV+:

raw.githubusercontent.com https://raw.githubusercontent.com/qwerttvv/Beijing-IPTV/master/IPTV-Unicom.m3u https://raw.githubusercontent.com/qwerttvv/Beijing-IPTV/master/IPTV-Unicom.m3u

Otherwise, you’ll have to actively monitor changes to this file and update accordingly.

Here, I spent ten minutes deploying an API service on Vercel while also enabling Vercel’s Cron Jobs service to periodically execute functions for detecting changes. The code is as follows—you can deploy your own setup as well:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import type { NextApiRequest, NextApiResponse } from 'next';

type ResponseData = {
msg: string,
};

/**
* 该函数用来将网友通过 IPTV 盒子抓包获取的联通单播地址,转成自己的单播地址
* 该函数每天 3 点触发一次,定时检测网友的单播地址是否有更新,使用 vercel corn 任务进行
* TODO: 该函数未做鉴权,任何人都可以手动触发检测,为了防止滥用可以加上鉴权,但是 corn 似乎没这个功能
*/
export default function handler(
request: NextApiRequest,
response: NextApiResponse<ResponseData>
) {
// Note: 步骤
// 1. 获取网友通过监听盒子数据包抓取的(自己搞比较费劲,直接用现成的了)联通 IPTV 永久地址(rtp 协议的组播地址,多用户通用),获取其内容
// 2. 添加本地 udpxy 转发地址
// 3. 获取之前的 github gist 内容以对比二者
// 4. 有差异,则更新 github gist 内容
// 5. 没有,则不做操作
// Note: 环境变量,自己在 Vercel 中设置好
const token = process.env.GITHUB_TOKEN;
const gist = process.env.GIST_URL;
const id = process.env.GIST_ID;
return fetch(
'https://raw.githubusercontent.com/qwerttvv/Beijing-IPTV/master/IPTV-Unicom.m3u'
)
.then(async (res) => {
if (!res.ok) {
console.log('获取源地址异常');
return response.status(200).json({
msg: '获取源地址异常',
});
}
const src = await res.text();
// Note: 替换网友的本地单播地址为我的,其实你也可以将自己家的路由器网段设置成跟网友的一样(192.168.123.x),udpxy 端口转发设置成跟网友一样(23234),你就可以直接使用该地址了
const newGist = src.replace(
/http\:\/\/192\.168\.123\.1\:23234/g,
'http://192.168.5.2:4022'
);
response.setHeader('Content-Type', 'text/html; charset=utf-8');
// Note: 获取 gist 的 raw 内容,需要加个 cache-bust 否则每次请求会被缓存
return fetch(`${gist}?cache-bust=${Math.floor(Math.random() * 100000)}`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.then(async (pre) => {
const preGist = await pre.text();
// console.log('preGist:', preGist);
if (JSON.stringify(newGist) !== JSON.stringify(preGist)) {
// Note: 更新 Gist
const files = {
'IPTV.m3u': {
content: newGist,
},
};
return fetch(`https://api.github.com/gists/${id}`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'text/plain',
},
body: JSON.stringify({ files }),
})
.then((s) => {
console.log(
`更新成功: ${gist}?cache-bust=${Math.floor(
Math.random() * 1000000
)}`
);
return response.status(200).json({
msg: `更新成功: ${gist}?cache-bust=${Math.floor(
Math.random() * 1000000
)}`,
});
})
.catch((e) => {
console.log(`更新失败: ${e}`);
return response.status(200).json({
msg: `更新失败: ${e}`,
});
});
}
console.log(
`未变化: ${gist}?cache-bust=${Math.floor(Math.random() * 1000000)}`
);
return response.status(200).json({
msg: `未变化: ${gist}?cache-bust=${Math.floor(
Math.random() * 1000000
)}`,
});
})
.catch((e) => {
console.log(`获取自己的 gist 失败: ${e}`);
return response.status(200).json({
msg: `获取自己的 gist 失败: ${e}`,
});
});
})
.catch((e) => {
console.log(`获取别人的源失败: ${e}`);
return response.status(200).json({
msg: `获取别人的源失败: ${e}`,
});
});
}

Corn Jobs Service Configuration:

1
2
3
4
5
6
7
8
{
"crons": [
{
"path": "/api/get",
"schedule": "0 15 * * *"
}
]
}

After pulling this file, if there are updates, the gist file will be automatically updated:

gist.githubusercontent.com https://gist.githubusercontent.com/Xheldon/73bf97cb5ac5db2f5237264556b20951/raw/ea44694028a38baefff04ea46c02795e448d76f0/IPTV.m3u https://gist.githubusercontent.com/Xheldon/73bf97cb5ac5db2f5237264556b20951/raw/ea44694028a38baefff04ea46c02795e448d76f0/IPTV.m3u

In this way, I only need to hardcode this gist address in TV+, and it will automatically update when the author updates the address.

单线融合IPTV到家庭局域网最简单的方法:路由+桥接混合模式 Contents Preface Basic Knowledge Step 1: Modem Bridge Mode Bridge Method Verify Your Network Structure Step 2: OpenWrt Router and Basic Configuration Interface Setup Gateway Hop Step 3: Multicast Proxy to Home Network Multicast Proxy Multicast to Unicast Step 4: Integrating IPTV Content Service Network into Home Network Using IPTV... https://blog.lishun.me/iptvhelper-guide

光纤入户光猫改桥接+内网转发IPTV=任意设备看电视直播 - Botian's Blog Warning: This article will introduce modifications to your local network environment. Some operations may result in loss of internet connectivity. If you lack relevant networking knowledge, recovery may be difficult and may even require assistance from your ISP. Proceed with caution. Note: Ensure you have your PPPoE account credentials (usually printed on the service contract or user receipt). You can also contact your ISP or find them in your router settings... https://blog.friskit.me/2020/05/31/bjunicom-network.html

北京联通白嫖 IPTV Beijing Unicom allows receiving TV multicast data even without an active IPTV subscription. This article explains how to freely access Beijing Unicom IPTV and enable smooth IPTV live streaming on any device within your home network. https://www.haoyizebo.com/posts/6a0c2301/

- EOF -
Originally published at: Watching Beijing Unicom IPTV on Apple TV - Xheldon Blog