(source)
| 1199 | |
| 1200 | |
| 1201 | def parse_channels_only(source): |
| 1202 | # Use extracted file if available, otherwise use the original file path |
| 1203 | file_path = source.extracted_file_path if source.extracted_file_path else source.file_path |
| 1204 | if not file_path: |
| 1205 | file_path = source.get_cache_file() |
| 1206 | |
| 1207 | # Send initial parsing notification |
| 1208 | send_epg_update(source.id, "parsing_channels", 0) |
| 1209 | |
| 1210 | process = None |
| 1211 | should_log_memory = False |
| 1212 | |
| 1213 | try: |
| 1214 | # Check if the file exists |
| 1215 | if not os.path.exists(file_path): |
| 1216 | logger.error(f"EPG file does not exist at path: {file_path}") |
| 1217 | |
| 1218 | # Update the source's file_path to the default cache location |
| 1219 | new_path = source.get_cache_file() |
| 1220 | logger.info(f"Updating file_path from '{file_path}' to '{new_path}'") |
| 1221 | source.file_path = new_path |
| 1222 | source.save(update_fields=['file_path']) |
| 1223 | |
| 1224 | # If the source has a URL, fetch the data before continuing |
| 1225 | if source.url: |
| 1226 | logger.info(f"Fetching new EPG data from URL: {source.url}") |
| 1227 | fetch_success = fetch_xmltv(source) # Store the result |
| 1228 | |
| 1229 | # Only proceed if fetch was successful AND file exists |
| 1230 | if not fetch_success: |
| 1231 | logger.error(f"Failed to fetch EPG data from URL: {source.url}") |
| 1232 | # Update status to error |
| 1233 | source.status = 'error' |
| 1234 | source.last_message = f"Failed to fetch EPG data from URL" |
| 1235 | source.save(update_fields=['status', 'last_message']) |
| 1236 | # Send error notification |
| 1237 | send_epg_update(source.id, "parsing_channels", 100, status="error", error="Failed to fetch EPG data") |
| 1238 | return False |
| 1239 | |
| 1240 | # Verify the file was downloaded successfully |
| 1241 | if not os.path.exists(source.file_path): |
| 1242 | logger.error(f"Failed to fetch EPG data, file still missing at: {source.file_path}") |
| 1243 | # Update status to error |
| 1244 | source.status = 'error' |
| 1245 | source.last_message = f"Failed to fetch EPG data, file missing after download" |
| 1246 | source.save(update_fields=['status', 'last_message']) |
| 1247 | send_epg_update(source.id, "parsing_channels", 100, status="error", error="File not found after download") |
| 1248 | return False |
| 1249 | |
| 1250 | # Update file_path with the new location |
| 1251 | file_path = source.file_path |
| 1252 | else: |
| 1253 | logger.error(f"No URL provided for EPG source {source.name}, cannot fetch new data") |
| 1254 | # Update status to error |
| 1255 | source.status = 'error' |
| 1256 | source.last_message = f"No URL provided, cannot fetch EPG data" |
| 1257 | source.save(update_fields=['status', 'last_message']) |
| 1258 | send_epg_update( |
no test coverage detected