| 972 | return all_streams |
| 973 | |
| 974 | def process_xc_category_direct(account_id, batch, groups, hash_keys): |
| 975 | from django.db import connections |
| 976 | |
| 977 | # Ensure clean database connections for threading |
| 978 | connections.close_all() |
| 979 | |
| 980 | account = M3UAccount.objects.get(id=account_id) |
| 981 | |
| 982 | streams_to_create = [] |
| 983 | streams_to_update = [] |
| 984 | stream_hashes = {} |
| 985 | |
| 986 | try: |
| 987 | with XCClient( |
| 988 | account.server_url, |
| 989 | account.username, |
| 990 | account.password, |
| 991 | account.get_user_agent(), |
| 992 | ) as xc_client: |
| 993 | # Log the batch details to help with debugging |
| 994 | logger.debug(f"Processing XC batch: {batch}") |
| 995 | |
| 996 | for group_name, props in batch.items(): |
| 997 | # Check if we have a valid xc_id for this group |
| 998 | if "xc_id" not in props: |
| 999 | logger.error( |
| 1000 | f"Missing xc_id for group {group_name} in batch {batch}" |
| 1001 | ) |
| 1002 | continue |
| 1003 | |
| 1004 | # Get actual group ID from the mapping |
| 1005 | group_id = groups.get(group_name) |
| 1006 | if not group_id: |
| 1007 | logger.error(f"Group {group_name} not found in enabled groups") |
| 1008 | continue |
| 1009 | |
| 1010 | try: |
| 1011 | logger.debug( |
| 1012 | f"Fetching streams for XC category: {group_name} (ID: {props['xc_id']})" |
| 1013 | ) |
| 1014 | streams = xc_client.get_live_category_streams(props["xc_id"]) |
| 1015 | |
| 1016 | if not streams: |
| 1017 | logger.warning( |
| 1018 | f"No streams found for XC category {group_name} (ID: {props['xc_id']})" |
| 1019 | ) |
| 1020 | continue |
| 1021 | |
| 1022 | logger.debug( |
| 1023 | f"Found {len(streams)} streams for category {group_name}" |
| 1024 | ) |
| 1025 | |
| 1026 | for stream in streams: |
| 1027 | name = stream.get("name") or f"{account.name} - {stream.get('stream_id', 'Unknown')}" |
| 1028 | if not stream.get("name"): |
| 1029 | logger.warning( |
| 1030 | f"XC stream has null/empty name in category {group_name}; " |
| 1031 | f"using generated name '{name}' (stream_id={stream.get('stream_id', 'unknown')})" |