(self)
| 75 | return self.name |
| 76 | |
| 77 | def get_cache_file(self): |
| 78 | import mimetypes |
| 79 | |
| 80 | file_ext = ".tmp" |
| 81 | |
| 82 | if self.file_path and os.path.exists(self.file_path): |
| 83 | _, existing_ext = os.path.splitext(self.file_path) |
| 84 | if existing_ext: |
| 85 | file_ext = existing_ext |
| 86 | else: |
| 87 | mime_type, _ = mimetypes.guess_type(self.file_path) |
| 88 | if mime_type: |
| 89 | if mime_type == 'application/gzip' or mime_type == 'application/x-gzip': |
| 90 | file_ext = '.gz' |
| 91 | elif mime_type == 'application/zip': |
| 92 | file_ext = '.zip' |
| 93 | elif mime_type == 'application/xml' or mime_type == 'text/xml': |
| 94 | file_ext = '.xml' |
| 95 | else: |
| 96 | try: |
| 97 | with open(self.file_path, 'rb') as f: |
| 98 | header = f.read(4) |
| 99 | if header[:2] == b'\x1f\x8b': |
| 100 | file_ext = '.gz' |
| 101 | elif header[:2] == b'PK': |
| 102 | file_ext = '.zip' |
| 103 | elif header[:5] == b'<?xml' or header[:5] == b'<tv>': |
| 104 | file_ext = '.xml' |
| 105 | except Exception: |
| 106 | pass |
| 107 | |
| 108 | filename = f"{self.id}{file_ext}" |
| 109 | cache_dir = os.path.join(settings.MEDIA_ROOT, "cached_epg") |
| 110 | os.makedirs(cache_dir, exist_ok=True) |
| 111 | cache = os.path.join(cache_dir, filename) |
| 112 | return cache |
| 113 | |
| 114 | def save(self, *args, **kwargs): |
| 115 | if 'update_fields' in kwargs and 'updated_at' not in kwargs['update_fields']: |
no test coverage detected