Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.

media download speed ​​up:skip sleep if download not start or media type not match #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions telegram_export/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down