(classifier: ChannelClassifier, main_dict: dict)
| 343 | return sorted(channel_data, key=_dict_key) |
| 344 | |
| 345 | def generate_live_text(classifier: ChannelClassifier, main_dict: dict) -> tuple[list, list]: |
| 346 | bj_time = datetime.now(timezone.utc) + timedelta(hours=8) |
| 347 | formatted_time = bj_time.strftime("%Y%m%d %H:%M") |
| 348 | version = f"{formatted_time},http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226537/index.m3u8" |
| 349 | header = ["更新时间,#genre#", version, '\n'] |
| 350 | |
| 351 | # 生成lite精简版 |
| 352 | lite_lines = header.copy() |
| 353 | lite_sort_types = [ |
| 354 | "央视频道", "卫视频道", "港澳台", "电影", "电视剧", "综艺频道", |
| 355 | "NewTV", "iHOT", "体育频道", "咪咕直播", "埋堆堆", "音乐频道", "游戏频道", "解说频道" |
| 356 | ] |
| 357 | for chn_type in lite_sort_types: |
| 358 | chn_data = classifier.get_channel_data(chn_type) |
| 359 | sorted_data = sort_channel_data(chn_data, chn_type, main_dict[chn_type]) |
| 360 | lite_lines += [f"{chn_type},#genre#"] + sorted_data + ['\n'] |
| 361 | lite_lines = lite_lines[:-1] if lite_lines and lite_lines[-1] == '\n' else lite_lines |
| 362 | |
| 363 | # 补全剩余生成full版 |
| 364 | full_lines = lite_lines.copy() + ['\n'] |
| 365 | full_other_types = [ |
| 366 | "儿童频道", "国际台", "纪录片", "戏曲频道", "上海频道", "湖南频道", |
| 367 | "湖北频道", "广东频道", "浙江频道", "山东频道", "江苏频道", "安徽频道", |
| 368 | "海南频道", "内蒙频道", "辽宁频道", "陕西频道", "山西频道", "云南频道", |
| 369 | "北京频道", "重庆频道", "福建频道", "甘肃频道", "广西频道", "贵州频道", |
| 370 | "河北频道", "河南频道", "黑龙江频道", "吉林频道", "江西频道", "宁夏频道", |
| 371 | "青海频道", "四川频道", "天津频道", "新疆频道", "春晚", "直播中国", "MTV", "收音机频道" |
| 372 | ] |
| 373 | for chn_type in full_other_types: |
| 374 | chn_data = classifier.get_channel_data(chn_type) |
| 375 | sort_list = main_dict.get(chn_type, []) or classifier.local_dict.get(chn_type, []) |
| 376 | sorted_data = sort_channel_data(chn_data, chn_type, sort_list) |
| 377 | full_lines += [f"{chn_type},#genre#"] + sorted_data + ['\n'] |
| 378 | full_lines = full_lines[:-1] if full_lines and full_lines[-1] == '\n' else full_lines |
| 379 | |
| 380 | return full_lines, lite_lines |
| 381 | |
| 382 | def make_m3u(txt_file: str, m3u_file: str, tvg_url: str, logo_tpl: str): |
| 383 | try: |
no test coverage detected