侧边栏壁纸
博主头像
Lee's World 博主等级

长安乐,多喜宁

  • 累计撰写 23 篇文章
  • 累计创建 2 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

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

Administrator
2025-12-26 / 0 评论 / 0 点赞 / 1 阅读 / 0 字

假装自己是一个文章头图

下载地址

http://all.api.radio-browser.info/json/stations/bycountrycodeexact/CN

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

curl -L "http://all.api.radio-browser.info/json/stations/bycountrycodeexact/CN" -o china_stations.json

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

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 个有效电台。

0

评论区