Simplify None checks for file uploads

This commit is contained in:
Dan 2020-07-27 15:06:18 +02:00
parent b745ce95ed
commit 516e0a13d5
8 changed files with 18 additions and 15 deletions

View File

@ -1783,6 +1783,9 @@ class Client(Methods, BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
"""
if path is None:
return None
part_size = 512 * 1024
if isinstance(path, str):

View File

@ -109,7 +109,7 @@ class EditMessageMedia(BaseClient):
peer=self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(media.media) or "video/mp4",
thumb=None if media.thumb is None else self.save_file(media.thumb),
thumb=self.save_file(media.thumb),
file=self.save_file(media.media),
attributes=[
types.DocumentAttributeVideo(
@ -146,7 +146,7 @@ class EditMessageMedia(BaseClient):
peer=self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(media.media) or "audio/mpeg",
thumb=None if media.thumb is None else self.save_file(media.thumb),
thumb=self.save_file(media.thumb),
file=self.save_file(media.media),
attributes=[
types.DocumentAttributeAudio(
@ -182,7 +182,7 @@ class EditMessageMedia(BaseClient):
peer=self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(media.media) or "video/mp4",
thumb=None if media.thumb is None else self.save_file(media.thumb),
thumb=self.save_file(media.thumb),
file=self.save_file(media.media),
attributes=[
types.DocumentAttributeVideo(
@ -220,7 +220,7 @@ class EditMessageMedia(BaseClient):
peer=self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(media.media) or "application/zip",
thumb=None if media.thumb is None else self.save_file(media.thumb),
thumb=self.save_file(media.thumb),
file=self.save_file(media.media),
attributes=[
types.DocumentAttributeFilename(

View File

@ -167,7 +167,7 @@ class SendAnimation(BaseClient):
try:
if isinstance(animation, str):
if os.path.isfile(animation):
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(animation, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(animation) or "video/mp4",
@ -191,7 +191,7 @@ class SendAnimation(BaseClient):
else:
media = utils.get_input_media_from_file_id(animation, file_ref, 10)
else:
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(animation, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(animation.name) or "video/mp4",

View File

@ -167,7 +167,7 @@ class SendAudio(BaseClient):
try:
if isinstance(audio, str):
if os.path.isfile(audio):
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(audio, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(audio) or "audio/mpeg",
@ -189,7 +189,7 @@ class SendAudio(BaseClient):
else:
media = utils.get_input_media_from_file_id(audio, file_ref, 9)
else:
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(audio, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(audio.name) or "audio/mpeg",

View File

@ -147,7 +147,7 @@ class SendDocument(BaseClient):
try:
if isinstance(document, str):
if os.path.isfile(document):
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(document, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(document) or "application/zip",
@ -165,7 +165,7 @@ class SendDocument(BaseClient):
else:
media = utils.get_input_media_from_file_id(document, file_ref, 5)
else:
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(document, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(document.name) or "application/zip",

View File

@ -119,7 +119,7 @@ class SendMediaGroup(BaseClient):
peer=self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
file=self.save_file(i.media),
thumb=None if i.thumb is None else self.save_file(i.thumb),
thumb=self.save_file(i.thumb),
mime_type=self.guess_mime_type(i.media) or "video/mp4",
attributes=[
types.DocumentAttributeVideo(

View File

@ -164,7 +164,7 @@ class SendVideo(BaseClient):
try:
if isinstance(video, str):
if os.path.isfile(video):
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(video, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(video) or "video/mp4",
@ -187,7 +187,7 @@ class SendVideo(BaseClient):
else:
media = utils.get_input_media_from_file_id(video, file_ref, 4)
else:
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(video, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(video.name) or "video/mp4",

View File

@ -131,7 +131,7 @@ class SendVideoNote(BaseClient):
try:
if isinstance(video_note, str):
if os.path.isfile(video_note):
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(video_note, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(video_note) or "video/mp4",
@ -149,7 +149,7 @@ class SendVideoNote(BaseClient):
else:
media = utils.get_input_media_from_file_id(video_note, file_ref, 13)
else:
thumb = None if thumb is None else self.save_file(thumb)
thumb = self.save_file(thumb)
file = self.save_file(video_note, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(video_note.name) or "video/mp4",