Karan Adhikari commited on
Fix replace mode for split file
Browse files- Backend/helper/database.py +22 -6
Backend/helper/database.py
CHANGED
|
@@ -819,18 +819,39 @@ class Database:
|
|
| 819 |
)
|
| 820 |
return await self.update_tv_show(tv_show)
|
| 821 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
async def _merge_split_part(self, qualities: List[dict], quality_to_update: dict) -> List[dict]:
|
| 823 |
group_key = quality_to_update.get("group_key")
|
| 824 |
incoming_parts = quality_to_update.get("parts") or []
|
| 825 |
if not incoming_parts:
|
| 826 |
return qualities + [quality_to_update]
|
| 827 |
new_part = incoming_parts[0]
|
|
|
|
| 828 |
|
| 829 |
merged = False
|
| 830 |
result = []
|
| 831 |
for q in qualities:
|
| 832 |
if group_key is not None and q.get("group_key") == group_key:
|
| 833 |
existing_parts = q.get("parts") or []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 834 |
existing_parts = [
|
| 835 |
p for p in existing_parts if p.get("part_number") != new_part.get("part_number")
|
| 836 |
]
|
|
@@ -851,12 +872,7 @@ class Database:
|
|
| 851 |
parts = quality.get("parts")
|
| 852 |
if parts:
|
| 853 |
for part in parts:
|
| 854 |
-
|
| 855 |
-
chat_id = int(f"-100{part['chat_id']}")
|
| 856 |
-
msg_id = int(part["msg_id"])
|
| 857 |
-
create_task(delete_message(chat_id, msg_id))
|
| 858 |
-
except Exception as e:
|
| 859 |
-
LOGGER.error(f"Failed to delete split part message: {e}")
|
| 860 |
return
|
| 861 |
|
| 862 |
old_id = quality.get("id")
|
|
|
|
| 819 |
)
|
| 820 |
return await self.update_tv_show(tv_show)
|
| 821 |
|
| 822 |
+
async def _delete_split_part(self, part: dict) -> None:
|
| 823 |
+
try:
|
| 824 |
+
chat_id = int(f"-100{part['chat_id']}")
|
| 825 |
+
msg_id = int(part["msg_id"])
|
| 826 |
+
create_task(delete_message(chat_id, msg_id))
|
| 827 |
+
except Exception as e:
|
| 828 |
+
LOGGER.error(f"Failed to delete split part message: {e}")
|
| 829 |
+
|
| 830 |
async def _merge_split_part(self, qualities: List[dict], quality_to_update: dict) -> List[dict]:
|
| 831 |
group_key = quality_to_update.get("group_key")
|
| 832 |
incoming_parts = quality_to_update.get("parts") or []
|
| 833 |
if not incoming_parts:
|
| 834 |
return qualities + [quality_to_update]
|
| 835 |
new_part = incoming_parts[0]
|
| 836 |
+
replace_mode = SettingsManager.current().replace_mode
|
| 837 |
|
| 838 |
merged = False
|
| 839 |
result = []
|
| 840 |
for q in qualities:
|
| 841 |
if group_key is not None and q.get("group_key") == group_key:
|
| 842 |
existing_parts = q.get("parts") or []
|
| 843 |
+
|
| 844 |
+
if replace_mode:
|
| 845 |
+
for old_part in existing_parts:
|
| 846 |
+
if old_part.get("part_number") != new_part.get("part_number"):
|
| 847 |
+
continue
|
| 848 |
+
if (
|
| 849 |
+
old_part.get("chat_id") == new_part.get("chat_id")
|
| 850 |
+
and old_part.get("msg_id") == new_part.get("msg_id")
|
| 851 |
+
):
|
| 852 |
+
continue
|
| 853 |
+
await self._delete_split_part(old_part)
|
| 854 |
+
|
| 855 |
existing_parts = [
|
| 856 |
p for p in existing_parts if p.get("part_number") != new_part.get("part_number")
|
| 857 |
]
|
|
|
|
| 872 |
parts = quality.get("parts")
|
| 873 |
if parts:
|
| 874 |
for part in parts:
|
| 875 |
+
await self._delete_split_part(part)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 876 |
return
|
| 877 |
|
| 878 |
old_id = quality.get("id")
|