Karan Adhikari commited on
Commit
c1df1c3
·
unverified ·
1 Parent(s): c26ef46

fix dead link checker

Browse files
Files changed (1) hide show
  1. Backend/helper/link_checker.py +31 -19
Backend/helper/link_checker.py CHANGED
@@ -88,30 +88,42 @@ class DeadLinkChecker:
88
  LOGGER.error(f"Error scanning TV shows in DB {i}: {e}")
89
 
90
  async def _check_file_alive(self, client, quality_id: str) -> bool:
91
- """
92
- Decodes the quality_id to a Telegram chat_id and message_id,
93
- then attempts to fetch the message to see if it (and its media) still exist.
94
- """
95
  try:
96
  decoded = await decode_string(quality_id)
97
- if not decoded or "chat_id" not in decoded or "msg_id" not in decoded:
98
  return False
99
-
100
- chat_id = int(f"-100{decoded['chat_id']}")
101
- msg_id = int(decoded["msg_id"])
102
 
103
- # Use get_messages to fetch exactly one message
104
- messages = await client.get_messages(chat_id, message_ids=[msg_id])
105
- if not messages or len(messages) == 0:
106
- return False
107
-
108
- msg = messages[0]
109
- if msg.empty or (msg.document is None and msg.video is None and msg.audio is None):
110
- return False
111
-
112
- return True
 
113
 
 
 
 
 
 
 
114
  except Exception as e:
115
- # If the channel is banned, chat_id is invalid, or any other critical error occurs
116
  LOGGER.error(f"Link checker failed to resolve {quality_id}: {e}")
117
  return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  LOGGER.error(f"Error scanning TV shows in DB {i}: {e}")
89
 
90
  async def _check_file_alive(self, client, quality_id: str) -> bool:
 
 
 
 
91
  try:
92
  decoded = await decode_string(quality_id)
93
+ if not decoded:
94
  return False
 
 
 
95
 
96
+ # Split file: payload has a "parts" list of {chat_id, msg_id}
97
+ if "parts" in decoded:
98
+ parts = decoded.get("parts") or []
99
+ if not parts:
100
+ return False
101
+ for part in parts:
102
+ if not await self._check_single_message(
103
+ client, part.get("chat_id"), part.get("msg_id")
104
+ ):
105
+ return False # any missing part => dead
106
+ return True
107
 
108
+ # Single file
109
+ if "chat_id" not in decoded or "msg_id" not in decoded:
110
+ return False
111
+ return await self._check_single_message(
112
+ client, decoded["chat_id"], decoded["msg_id"]
113
+ )
114
  except Exception as e:
 
115
  LOGGER.error(f"Link checker failed to resolve {quality_id}: {e}")
116
  return False
117
+
118
+ async def _check_single_message(self, client, chat_id, msg_id) -> bool:
119
+ if chat_id is None or msg_id is None:
120
+ return False
121
+ chat_id = int(f"-100{chat_id}")
122
+ msg_id = int(msg_id)
123
+ messages = await client.get_messages(chat_id, message_ids=[msg_id])
124
+ if not messages:
125
+ return False
126
+ msg = messages[0]
127
+ if msg.empty or (msg.document is None and msg.video is None and msg.audio is None):
128
+ return False
129
+ return True