Skip to content

Commit 7d16ad1

Browse files
author
Sam-Max
committed
minor fix
1 parent dcfd03f commit 7d16ad1

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

bot/helper/mirror_leech_utils/upload_utils/telegram_uploader.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,21 @@ async def upload(self):
9696
await self.__listener.onUploadComplete(None, size, self.__msgs_dict, self.__total_files, self.__corrupted, self.name)
9797

9898
async def __upload_file(self, up_path, file):
99-
thumb_path = self.__thumb
99+
thumb = self.__thumb
100100
self.__is_corrupted = False
101101
cap_mono= f"<code>{file}</code>"
102102
try:
103103
is_video, is_audio, is_image = await get_document_type(up_path)
104104

105-
if not is_image and thumb_path is None:
105+
if not is_image and thumb is None:
106106
file_name = ospath.splitext(file)[0]
107107
thumb_path = f"{self.__path}/yt-dlp-thumb/{file_name}.jpg"
108+
if ospath.isfile(thumb_path):
109+
thumb = thumb_path
108110

109111
if self.__as_doc or (not is_video and not is_audio and not is_image):
110-
if is_video and thumb_path is None:
111-
thumb_path = await take_ss(up_path, None)
112+
if is_video and thumb is None:
113+
thumb = await take_ss(up_path, None)
112114
if self.__is_cancelled:
113115
return
114116
if config_dict['LEECH_LOG']:
@@ -117,7 +119,7 @@ async def __upload_file(self, up_path, file):
117119
chat_id= int(chat),
118120
document=up_path,
119121
caption=cap_mono,
120-
thumb=thumb_path,
122+
thumb=thumb,
121123
disable_notification=True,
122124
progress=self.__upload_progress)
123125
if config_dict['BOT_PM']:
@@ -133,7 +135,7 @@ async def __upload_file(self, up_path, file):
133135
document= up_path,
134136
caption= cap_mono,
135137
quote=True,
136-
thumb= thumb_path,
138+
thumb=thumb,
137139
disable_notification=True,
138140
progress= self.__upload_progress)
139141
if is_video:
@@ -142,10 +144,10 @@ async def __upload_file(self, up_path, file):
142144
osrename(up_path, new_path)
143145
up_path = new_path
144146
duration= (await get_media_info(up_path))[0]
145-
if thumb_path is None:
146-
thumb_path = await take_ss(up_path, duration)
147-
if thumb_path is not None:
148-
with Image.open(thumb_path) as img:
147+
if thumb is None:
148+
thumb = await take_ss(up_path, duration)
149+
if thumb is not None:
150+
with Image.open(thumb) as img:
149151
width, height = img.size
150152
else:
151153
width = 480
@@ -161,7 +163,7 @@ async def __upload_file(self, up_path, file):
161163
duration=duration,
162164
width=width,
163165
height=height,
164-
thumb=thumb_path,
166+
thumb=thumb,
165167
supports_streaming=True,
166168
disable_notification=True,
167169
progress=self.__upload_progress)
@@ -181,7 +183,7 @@ async def __upload_file(self, up_path, file):
181183
caption= cap_mono,
182184
quote=True,
183185
disable_notification=True,
184-
thumb= thumb_path,
186+
thumb=thumb,
185187
supports_streaming= True,
186188
duration= duration,
187189
progress= self.__upload_progress)
@@ -197,7 +199,7 @@ async def __upload_file(self, up_path, file):
197199
duration=duration,
198200
performer=artist,
199201
title=title,
200-
thumb=thumb_path,
202+
thumb=thumb,
201203
progress=self.__upload_progress)
202204
if config_dict['BOT_PM']:
203205
try:
@@ -215,7 +217,7 @@ async def __upload_file(self, up_path, file):
215217
duration=duration,
216218
performer=artist,
217219
title=title,
218-
thumb= thumb_path,
220+
thumb=thumb,
219221
disable_notification=True,
220222
progress=self.__upload_progress)
221223
elif is_image:
@@ -244,14 +246,14 @@ async def __upload_file(self, up_path, file):
244246
quote= True,
245247
disable_notification= True,
246248
progress= self.__upload_progress)
247-
if self.__thumb is None and thumb_path is not None and ospath.lexists(thumb_path):
248-
osremove(thumb_path)
249+
if self.__thumb is None and thumb is not None and ospath.exists(thumb):
250+
osremove(thumb)
249251
except FloodWait as f:
250252
LOGGER.warning(str(f))
251253
await sleep(f.value)
252254
except Exception as err:
253-
if self.__thumb is None and thumb_path is not None and ospath.lexists(thumb_path):
254-
osremove(thumb_path)
255+
if self.__thumb is None and thumb is not None and ospath.exists(thumb):
256+
osremove(thumb)
255257
err_type = "RPCError: " if isinstance(err, RPCError) else ""
256258
LOGGER.error(f"{err_type}{err}. Path: {up_path}")
257259
raise err
@@ -279,7 +281,7 @@ def __user_settings(self):
279281
user_id = self.__listener.message.from_user.id
280282
user_dict = user_data.get(user_id, {})
281283
self.__as_doc = user_dict.get('as_doc') or config_dict['AS_DOCUMENT']
282-
if not ospath.lexists(self.__thumb):
284+
if not ospath.exists(self.__thumb):
283285
self.__thumb = None
284286

285287
async def __prepare_file(self, file_, dirpath):

0 commit comments

Comments
 (0)