Streaming Media Rules
Relevant source files
The following files were used as context for generating this wiki page:The Self-Rule repository provides a collection of rule sets for the Clash proxy client, specifically designed to manage network traffic for various international streaming media services. The primary purpose of these rules is to automatically route traffic for services like Netflix, Disney+, YouTube, and BBC iPlayer through a proxy, enabling access to geo-restricted content. This is achieved by defining lists of domain names and IP address ranges associated with these services.
These rule sets are provided as individual YAML files, which can be used as rule-providers in a Clash configuration. The repository also includes an aggregated provider, ProxyMedia.yaml, which combines rules for a wide array of services into a single, comprehensive list. The generation of these YAML files is automated by a Python script, which converts simple .list files into the required Clash provider format.
Core Concepts
The streaming media rules are defined in YAML files, each containing a payload section. This section lists various rule definitions that Clash uses to match and route network requests.
Sources: Clash/Providers/Netflix.yaml, Clash/Providers/Ruleset/DisneyPlus.yaml, update_providers.py:18-19
Rule Types
The rule sets primarily use four types of rules to identify traffic belonging to streaming services.
| Rule Type | Description | Example |
|---|---|---|
DOMAIN-SUFFIX | Matches any domain ending with the specified suffix. This is the most common rule type. | DOMAIN-SUFFIX,netflix.com |
DOMAIN-KEYWORD | Matches if the specified keyword is found anywhere in the domain name. | DOMAIN-KEYWORD,youtube |
DOMAIN | Matches an exact domain name. | DOMAIN,cdn.registerdisney.go.com |
IP-CIDR | Matches if the destination IP address falls within the specified CIDR block. | IP-CIDR,23.246.0.0/18,no-resolve |
Sources: Clash/Providers/ProxyMedia.yaml:1-406, Clash/Providers/Netflix.yaml:3-35, Clash/Providers/Ruleset/DisneyPlus.yaml:5-26
Traffic Matching Flow
The following diagram illustrates how Clash uses these rules to process an outgoing network request.
This diagram shows that if a request's destination matches any rule in the provider file, it is routed through the designated proxy group.
Sources: Clash/Providers/ProxyMedia.yaml, Clash/Providers/Netflix.yaml
Service-Specific Rule Sets
The repository contains dedicated rule sets for major streaming platforms, ensuring precise and efficient routing.
Netflix
The Netflix.yaml provider contains rules specifically for Netflix traffic. A notable feature of this rule set is its extensive use of IP-CIDR rules in addition to DOMAIN-SUFFIX rules. This strategy helps capture traffic that might not be caught by domain matching alone, as streaming content is often served from a wide range of IP addresses.
# Clash/Providers/Netflix.yaml
payload:
# Netflix
# USER-AGENT,Argo*
- DOMAIN-SUFFIX,fast.com
- DOMAIN-SUFFIX,netflix.com
- DOMAIN-SUFFIX,netflix.net
# ... more domain rules
- IP-CIDR,23.246.0.0/18,no-resolve
- IP-CIDR,37.77.184.0/21,no-resolve
- IP-CIDR,45.57.0.0/17,no-resolve
# ... more IP CIDR rules
Sources: Clash/Providers/Netflix.yaml:1-35
The combination of domain and IP rules provides robust coverage for Netflix services.
| Rule Type | Example Value |
|---|---|
DOMAIN-SUFFIX | nflxvideo.net |
DOMAIN-SUFFIX | nflximg.net |
IP-CIDR | 108.175.32.0/20 |
Sources: Clash/Providers/Netflix.yaml:18, Clash/Providers/Netflix.yaml:17, Clash/Providers/Netflix.yaml:27
Disney+
The DisneyPlus.yaml provider focuses on domains related to Disney's streaming service. It uses DOMAIN and DOMAIN-SUFFIX rules to match authentication, API, and content delivery network (CDN) endpoints.
# Clash/Providers/Ruleset/DisneyPlus.yaml
payload:
# 内容:DisneyPlus
# 数量:22条
- DOMAIN,cdn.registerdisney.go.com
- DOMAIN-SUFFIX,adobedtm.com
- DOMAIN-SUFFIX,bamgrid.com
- DOMAIN-SUFFIX,disneyplus.com
- DOMAIN-SUFFIX,dssott.com
Sources: Clash/Providers/Ruleset/DisneyPlus.yaml:1-19
YouTube
The YouTube.yaml rule set is designed to capture all YouTube-related traffic, including the main site, mobile clients, and various content delivery domains. It heavily relies on the DOMAIN-KEYWORD and DOMAIN-SUFFIX rule types.
| Rule Type | Example Value |
|---|---|
DOMAIN-KEYWORD | youtube |
DOMAIN-SUFFIX | googlevideo.com |
DOMAIN-SUFFIX | ytimg.com |
DOMAIN | youtubei.googleapis.com |
Sources: Clash/Providers/Ruleset/YouTube.yaml:6, Clash/Providers/Ruleset/YouTube.yaml:8, Clash/Providers/Ruleset/YouTube.yaml:16, Clash/Providers/Ruleset/YouTube.yaml:7
BBC iPlayer
The BBCiPlayer.yaml provider targets the British Broadcasting Corporation's streaming services. It uses a mix of DOMAIN-KEYWORD and DOMAIN-SUFFIX rules to identify live and on-demand content, including traffic directed to Akamai's CDN.
| Rule Type | Example Value |
|---|---|
DOMAIN-KEYWORD | uk-live |
DOMAIN-SUFFIX | bbc.co.uk |
DOMAIN-SUFFIX | bbci.co.uk |
DOMAIN | aod-dash-uk-live.akamaized.net |
Sources: Clash/Providers/Ruleset/BBCiPlayer.yaml:6, Clash/Providers/Ruleset/BBCiPlayer.yaml:10, Clash/Providers/Ruleset/BBCiPlayer.yaml:14, Clash/Providers/Ruleset/BBCiPlayer.yaml:7
Aggregated Media Rules
The ProxyMedia.yaml file serves as a master list, aggregating rules for a large number of foreign media services beyond the major platforms. This includes services like HBO, Hulu, AbemaTV, TikTok, and even AI platforms like OpenAI and Claude, which are included to ensure they are routed through the proxy.
This file is a convenient way to apply a broad set of rules for media consumption without needing to manage dozens of individual provider files.
The diagram below shows how ProxyMedia.yaml conceptually groups rules for various services.
Sources: Clash/Providers/ProxyMedia.yaml
A sample of services covered in ProxyMedia.yaml:
| Service | Example Rule |
|---|---|
| AbemaTV | DOMAIN-SUFFIX,abema.tv |
| Hulu | DOMAIN-SUFFIX,hulu.com |
| HBO | DOMAIN-SUFFIX,hbomax.com |
| TikTok | DOMAIN-KEYWORD,tiktokcdn |
| AI (OpenAI/Claude) | DOMAIN-KEYWORD,openai |
Sources: Clash/Providers/ProxyMedia.yaml:50, Clash/Providers/ProxyMedia.yaml:209, Clash/Providers/ProxyMedia.yaml:198, Clash/Providers/ProxyMedia.yaml:381, Clash/Providers/ProxyMedia.yaml:13
Rule Generation
The YAML provider files in this repository are not manually maintained. They are generated from simpler .list files using the update_providers.py script. This script reads each line from a .list file, formats it as a Clash rule, and writes it into a corresponding .yaml file under the payload: key.
This automation simplifies rule management, as maintainers only need to edit the basic .list files.
Sources: update_providers.py
The generation process is as follows:
Sources: update_providers.py:13-33
For example, a line like DOMAIN-SUFFIX,netflix.com in a .list file is converted into - DOMAIN-SUFFIX,netflix.com in the final .yaml file. The script also handles comments and ignores certain rule types like USER-AGENT by commenting them out in the output file.
Sources: update_providers.py:25-31