中国地区可收听的网络电台表


title: 中国地区可收听的网络电台表

slug: zhong-guo-di-qu-ke-shou-ting-de-wang-luo-dian-tai-biao
cover: ""
categories: []
tags: []
halo:
site: http://106.55.255.250
name: bb4d2035-d43c-400c-8324-1b42ca8ff84e
publish: true

下载地址

url 复制代码
http://all.api.radio-browser.info/json/stations/bycountrycodeexact/CN

注意,由于这个json特别庞大,直接在浏览器进行下载,大概会下载失败,推荐使用命令行下载

bash 复制代码
curl -L "http://all.api.radio-browser.info/json/stations/bycountrycodeexact/CN" -o china_stations.json

可以使用以下代码进行简单的清洗

python 复制代码
import json
import os

def clean_and_export_radio_data(input_data, output_file="radio_stations_list.md"):
    """
    清洗电台数据并导出为 Markdown 列表格式。
    """
    
    # 1. 定义白名单 (虽然是列表输出,但清洗步骤依然需要,防止报错)
    cleaned_list = []

    # 2. 遍历并清洗数据
    for station in input_data:
        if not isinstance(station, dict):
            continue

        # 过滤逻辑
        name = station.get("name")
        # 必须有名字,且 lastcheckok 必须为 1 (可用)
        if not name or str(station.get("lastcheckok")) != "1":
            continue

        # 提取需要的字段
        cleaned_list.append({
            "name": name,
            "url": station.get("url", "无链接"),
            "language": station.get("language", "未知")
        })

    # 3. 生成 Markdown 列表内容
    lines = []
    lines.append(f"# 电台列表")
    lines.append(f"\n共整理出 {len(cleaned_list)} 个有效电台。\n")

    for station in cleaned_list:
        name = station['name']
        url = station['url']
        lang = station['language']
        
        # --- 这里修改了输出格式 ---
        # 格式: - **名称**: URL (语言: xxx)
        line = f"- **{name}**: {url} (语言: {lang})"
        lines.append(line)

    md_content = "\n".join(lines)

    # 4. 写入文件
    try:
        with open(output_file, 'w', encoding='utf-8') as f:
            f.write(md_content)
        print(f"✅ 处理成功!已筛选出 {len(cleaned_list)} 个有效电台。")
        print(f"📄 文件已保存为: {os.path.abspath(output_file)}")
    except IOError as e:
        print(f"❌ 文件写入失败: {e}")

# --- 主程序 ---

if __name__ == "__main__":
    try:
        # 读取 JSON 文件 (使用 json.load 并指定 utf-8)
        with open('china_stations.json', 'r', encoding='utf-8') as f:
            data = json.load(f)
            
        clean_and_export_radio_data(data)
        
    except FileNotFoundError:
        print("❌ 错误:找不到文件 'china_stations.json'。")
    except json.JSONDecodeError as e:
        print(f"❌ JSON 解析错误: {e}")
    except Exception as e:
        print(f"❌ 发生未知错误: {e}")

最后得到的是可以播放的电台列表

电台列表

共整理出 1826 个有效电台。