| 5 | import os |
| 6 | |
| 7 | class EPGSource(models.Model): |
| 8 | SOURCE_TYPE_CHOICES = [ |
| 9 | ('xmltv', 'XMLTV URL'), |
| 10 | ('schedules_direct', 'Schedules Direct API'), |
| 11 | ('dummy', 'Custom Dummy EPG'), |
| 12 | ] |
| 13 | |
| 14 | STATUS_IDLE = 'idle' |
| 15 | STATUS_FETCHING = 'fetching' |
| 16 | STATUS_PARSING = 'parsing' |
| 17 | STATUS_ERROR = 'error' |
| 18 | STATUS_SUCCESS = 'success' |
| 19 | STATUS_DISABLED = 'disabled' |
| 20 | |
| 21 | STATUS_CHOICES = [ |
| 22 | (STATUS_IDLE, 'Idle'), |
| 23 | (STATUS_FETCHING, 'Fetching'), |
| 24 | (STATUS_PARSING, 'Parsing'), |
| 25 | (STATUS_ERROR, 'Error'), |
| 26 | (STATUS_SUCCESS, 'Success'), |
| 27 | (STATUS_DISABLED, 'Disabled'), |
| 28 | ] |
| 29 | |
| 30 | name = models.CharField(max_length=255, unique=True) |
| 31 | source_type = models.CharField(max_length=20, choices=SOURCE_TYPE_CHOICES) |
| 32 | url = models.URLField(max_length=1000, blank=True, null=True) # For XMLTV |
| 33 | username = models.CharField(max_length=255, blank=True, null=True, |
| 34 | help_text='Username for credential-based EPG sources (e.g. Schedules Direct)') |
| 35 | password = models.CharField(max_length=255, blank=True, null=True, |
| 36 | help_text='Password for credential-based EPG sources (e.g. Schedules Direct)') |
| 37 | is_active = models.BooleanField(default=True) |
| 38 | file_path = models.CharField(max_length=1024, blank=True, null=True) |
| 39 | extracted_file_path = models.CharField(max_length=1024, blank=True, null=True, |
| 40 | help_text="Path to extracted XML file after decompression") |
| 41 | refresh_interval = models.IntegerField(default=0) |
| 42 | refresh_task = models.ForeignKey( |
| 43 | PeriodicTask, on_delete=models.SET_NULL, null=True, blank=True |
| 44 | ) |
| 45 | custom_properties = models.JSONField( |
| 46 | default=dict, |
| 47 | blank=True, |
| 48 | null=True, |
| 49 | help_text="Custom properties for source-specific configuration" |
| 50 | ) |
| 51 | priority = models.PositiveIntegerField( |
| 52 | default=0, |
| 53 | help_text="Priority for EPG matching (higher numbers = higher priority). Used when multiple EPG sources have matching entries for a channel." |
| 54 | ) |
| 55 | status = models.CharField( |
| 56 | max_length=20, |
| 57 | choices=STATUS_CHOICES, |
| 58 | default=STATUS_IDLE |
| 59 | ) |
| 60 | last_message = models.TextField( |
| 61 | null=True, |
| 62 | blank=True, |
| 63 | help_text="Last status message, including success results or error information" |
| 64 | ) |