diff --git a/telegram_export/downloader.py b/telegram_export/downloader.py index bf41cc3..f1efe66 100755 --- a/telegram_export/downloader.py +++ b/telegram_export/downloader.py @@ -226,7 +226,7 @@ async def _download_media(self, media_id, context_id, sender_id, date, media_type = media_row[3].split('.') media_type, media_subtype = media_type[0], media_type[-1] if media_type not in ('photo', 'document'): - return # Only photos or documents are actually downloadable + return False # Only photos or documents are actually downloadable formatter = defaultdict( str, @@ -260,7 +260,7 @@ async def _download_media(self, media_id, context_id, sender_id, date, filename += '.{}{}'.format(media_id, ext) if os.path.isfile(filename): __log__.debug('Skipping already-existing file %s', filename) - return + return False __log__.debug('Downloading to %s', filename) os.makedirs(os.path.dirname(filename), exist_ok=True) @@ -301,16 +301,18 @@ def progress(saved, total): progress_callback=progress ) self._incomplete_download = None + return True async def _media_consumer(self, queue, bar): while self._running: start = time.time() media_id, context_id, sender_id, date = await queue.get() - await self._download_media(media_id, context_id, sender_id, + need_sleep = await self._download_media(media_id, context_id, sender_id, datetime.datetime.utcfromtimestamp(date), bar) queue.task_done() - await asyncio.sleep(max(MEDIA_DELAY - (time.time() - start), 0), + if need_sleep: + await asyncio.sleep(max(MEDIA_DELAY - (time.time() - start), 0), loop=self.loop) async def _user_consumer(self, queue, bar):