Compare commits

..

No commits in common. "0c8e4d7466f497a447127073fb09816d42277cbf" and "ad17d5a4a5e6e5d321dd41a3e2964898aa464f06" have entirely different histories.

2 changed files with 2 additions and 1859 deletions

1856
mime.types

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,6 @@ from bs4 import BeautifulSoup
from telethon import TelegramClient, events from telethon import TelegramClient, events
from telethon.utils import chunks, is_list_like from telethon.utils import chunks, is_list_like
mimetypes.init(['mime.types'])
with open('config.yaml') as file: with open('config.yaml') as file:
config_data = yaml.safe_load(file) config_data = yaml.safe_load(file)
@ -220,7 +219,7 @@ async def main():
file.write(chunk) file.write(chunk)
async def _get_file_mimetype(filename): async def _get_file_mimetype(filename):
mimetype = mimetypes.guess_type(filename, strict=False)[0] mimetype = mimetypes.guess_type(filename)[0]
if not mimetype: if not mimetype:
proc = await asyncio.create_subprocess_exec('file', '--brief', '--mime-type', filename, stdout=asyncio.subprocess.PIPE) proc = await asyncio.create_subprocess_exec('file', '--brief', '--mime-type', filename, stdout=asyncio.subprocess.PIPE)
stdout, _ = await proc.communicate() stdout, _ = await proc.communicate()
@ -233,7 +232,7 @@ async def main():
ext = stdout.decode().strip().split('/', maxsplit=1)[0] ext = stdout.decode().strip().split('/', maxsplit=1)[0]
if not ext or ext == '???': if not ext or ext == '???':
mimetype = await _get_file_mimetype(filename) mimetype = await _get_file_mimetype(filename)
ext = mimetypes.guess_extension(mimetype, strict=False) or '.bin' ext = mimetypes.guess_extension(mimetype) or '.bin'
if not ext.startswith('.'): if not ext.startswith('.'):
ext = '.' + ext ext = '.' + ext
return ext return ext