Build station_map / epg_id_map for all channels mapped to this SD source.
(source, token, sd_headers_fn)
| 2459 | |
| 2460 | |
| 2461 | def _sd_setup_mapped_guide_fetch(source, token, sd_headers_fn): |
| 2462 | """Build station_map / epg_id_map for all channels mapped to this SD source.""" |
| 2463 | from apps.channels.models import Channel |
| 2464 | |
| 2465 | mapped_epg_ids = set( |
| 2466 | Channel.objects.filter( |
| 2467 | epg_data__epg_source=source, |
| 2468 | epg_data__isnull=False, |
| 2469 | ).values_list('epg_data_id', flat=True) |
| 2470 | ) |
| 2471 | if not mapped_epg_ids: |
| 2472 | msg = "No channels mapped to this Schedules Direct source." |
| 2473 | logger.info(msg) |
| 2474 | source.last_message = msg |
| 2475 | source.save(update_fields=['last_message']) |
| 2476 | send_epg_update(source.id, "parsing_programs", 100, status="idle", message=msg) |
| 2477 | return None |
| 2478 | |
| 2479 | station_map = {} |
| 2480 | epg_id_map = {} |
| 2481 | for epg in EPGData.objects.filter(id__in=mapped_epg_ids, epg_source=source): |
| 2482 | if not epg.tvg_id: |
| 2483 | continue |
| 2484 | station_map[epg.tvg_id] = { |
| 2485 | 'name': epg.name or epg.tvg_id, |
| 2486 | 'logo_url': epg.icon_url, |
| 2487 | } |
| 2488 | epg_id_map[epg.tvg_id] = epg.id |
| 2489 | |
| 2490 | if not station_map: |
| 2491 | msg = "Mapped channels have no valid Schedules Direct station IDs." |
| 2492 | logger.warning(msg) |
| 2493 | source.last_message = msg |
| 2494 | source.save(update_fields=['last_message']) |
| 2495 | send_epg_update(source.id, "parsing_programs", 100, status="error", error=msg) |
| 2496 | return None |
| 2497 | |
| 2498 | sd_lineup_country = _sd_fetch_lineup_country(token, sd_headers_fn) |
| 2499 | send_epg_update( |
| 2500 | source.id, "parsing_programs", 15, |
| 2501 | message=f"Fetching guide data for {len(station_map)} mapped stations...", |
| 2502 | ) |
| 2503 | return station_map, epg_id_map, sd_lineup_country |
| 2504 | |
| 2505 | |
| 2506 | def dispatch_program_refresh_for_epg_ids(epg_ids): |
no test coverage detected