Simplify None checks for file uploads
This commit is contained in:
parent
b745ce95ed
commit
516e0a13d5
@ -1783,6 +1783,9 @@ class Client(Methods, BaseClient):
|
|||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
|
if path is None:
|
||||||
|
return None
|
||||||
|
|
||||||
part_size = 512 * 1024
|
part_size = 512 * 1024
|
||||||
|
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
|
@ -109,7 +109,7 @@ class EditMessageMedia(BaseClient):
|
|||||||
peer=self.resolve_peer(chat_id),
|
peer=self.resolve_peer(chat_id),
|
||||||
media=types.InputMediaUploadedDocument(
|
media=types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(media.media) or "video/mp4",
|
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),
|
file=self.save_file(media.media),
|
||||||
attributes=[
|
attributes=[
|
||||||
types.DocumentAttributeVideo(
|
types.DocumentAttributeVideo(
|
||||||
@ -146,7 +146,7 @@ class EditMessageMedia(BaseClient):
|
|||||||
peer=self.resolve_peer(chat_id),
|
peer=self.resolve_peer(chat_id),
|
||||||
media=types.InputMediaUploadedDocument(
|
media=types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(media.media) or "audio/mpeg",
|
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),
|
file=self.save_file(media.media),
|
||||||
attributes=[
|
attributes=[
|
||||||
types.DocumentAttributeAudio(
|
types.DocumentAttributeAudio(
|
||||||
@ -182,7 +182,7 @@ class EditMessageMedia(BaseClient):
|
|||||||
peer=self.resolve_peer(chat_id),
|
peer=self.resolve_peer(chat_id),
|
||||||
media=types.InputMediaUploadedDocument(
|
media=types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(media.media) or "video/mp4",
|
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),
|
file=self.save_file(media.media),
|
||||||
attributes=[
|
attributes=[
|
||||||
types.DocumentAttributeVideo(
|
types.DocumentAttributeVideo(
|
||||||
@ -220,7 +220,7 @@ class EditMessageMedia(BaseClient):
|
|||||||
peer=self.resolve_peer(chat_id),
|
peer=self.resolve_peer(chat_id),
|
||||||
media=types.InputMediaUploadedDocument(
|
media=types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(media.media) or "application/zip",
|
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),
|
file=self.save_file(media.media),
|
||||||
attributes=[
|
attributes=[
|
||||||
types.DocumentAttributeFilename(
|
types.DocumentAttributeFilename(
|
||||||
|
@ -167,7 +167,7 @@ class SendAnimation(BaseClient):
|
|||||||
try:
|
try:
|
||||||
if isinstance(animation, str):
|
if isinstance(animation, str):
|
||||||
if os.path.isfile(animation):
|
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)
|
file = self.save_file(animation, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(animation) or "video/mp4",
|
mime_type=self.guess_mime_type(animation) or "video/mp4",
|
||||||
@ -191,7 +191,7 @@ class SendAnimation(BaseClient):
|
|||||||
else:
|
else:
|
||||||
media = utils.get_input_media_from_file_id(animation, file_ref, 10)
|
media = utils.get_input_media_from_file_id(animation, file_ref, 10)
|
||||||
else:
|
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)
|
file = self.save_file(animation, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(animation.name) or "video/mp4",
|
mime_type=self.guess_mime_type(animation.name) or "video/mp4",
|
||||||
|
@ -167,7 +167,7 @@ class SendAudio(BaseClient):
|
|||||||
try:
|
try:
|
||||||
if isinstance(audio, str):
|
if isinstance(audio, str):
|
||||||
if os.path.isfile(audio):
|
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)
|
file = self.save_file(audio, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(audio) or "audio/mpeg",
|
mime_type=self.guess_mime_type(audio) or "audio/mpeg",
|
||||||
@ -189,7 +189,7 @@ class SendAudio(BaseClient):
|
|||||||
else:
|
else:
|
||||||
media = utils.get_input_media_from_file_id(audio, file_ref, 9)
|
media = utils.get_input_media_from_file_id(audio, file_ref, 9)
|
||||||
else:
|
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)
|
file = self.save_file(audio, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(audio.name) or "audio/mpeg",
|
mime_type=self.guess_mime_type(audio.name) or "audio/mpeg",
|
||||||
|
@ -147,7 +147,7 @@ class SendDocument(BaseClient):
|
|||||||
try:
|
try:
|
||||||
if isinstance(document, str):
|
if isinstance(document, str):
|
||||||
if os.path.isfile(document):
|
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)
|
file = self.save_file(document, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(document) or "application/zip",
|
mime_type=self.guess_mime_type(document) or "application/zip",
|
||||||
@ -165,7 +165,7 @@ class SendDocument(BaseClient):
|
|||||||
else:
|
else:
|
||||||
media = utils.get_input_media_from_file_id(document, file_ref, 5)
|
media = utils.get_input_media_from_file_id(document, file_ref, 5)
|
||||||
else:
|
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)
|
file = self.save_file(document, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(document.name) or "application/zip",
|
mime_type=self.guess_mime_type(document.name) or "application/zip",
|
||||||
|
@ -119,7 +119,7 @@ class SendMediaGroup(BaseClient):
|
|||||||
peer=self.resolve_peer(chat_id),
|
peer=self.resolve_peer(chat_id),
|
||||||
media=types.InputMediaUploadedDocument(
|
media=types.InputMediaUploadedDocument(
|
||||||
file=self.save_file(i.media),
|
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",
|
mime_type=self.guess_mime_type(i.media) or "video/mp4",
|
||||||
attributes=[
|
attributes=[
|
||||||
types.DocumentAttributeVideo(
|
types.DocumentAttributeVideo(
|
||||||
|
@ -164,7 +164,7 @@ class SendVideo(BaseClient):
|
|||||||
try:
|
try:
|
||||||
if isinstance(video, str):
|
if isinstance(video, str):
|
||||||
if os.path.isfile(video):
|
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)
|
file = self.save_file(video, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(video) or "video/mp4",
|
mime_type=self.guess_mime_type(video) or "video/mp4",
|
||||||
@ -187,7 +187,7 @@ class SendVideo(BaseClient):
|
|||||||
else:
|
else:
|
||||||
media = utils.get_input_media_from_file_id(video, file_ref, 4)
|
media = utils.get_input_media_from_file_id(video, file_ref, 4)
|
||||||
else:
|
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)
|
file = self.save_file(video, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(video.name) or "video/mp4",
|
mime_type=self.guess_mime_type(video.name) or "video/mp4",
|
||||||
|
@ -131,7 +131,7 @@ class SendVideoNote(BaseClient):
|
|||||||
try:
|
try:
|
||||||
if isinstance(video_note, str):
|
if isinstance(video_note, str):
|
||||||
if os.path.isfile(video_note):
|
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)
|
file = self.save_file(video_note, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(video_note) or "video/mp4",
|
mime_type=self.guess_mime_type(video_note) or "video/mp4",
|
||||||
@ -149,7 +149,7 @@ class SendVideoNote(BaseClient):
|
|||||||
else:
|
else:
|
||||||
media = utils.get_input_media_from_file_id(video_note, file_ref, 13)
|
media = utils.get_input_media_from_file_id(video_note, file_ref, 13)
|
||||||
else:
|
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)
|
file = self.save_file(video_note, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=self.guess_mime_type(video_note.name) or "video/mp4",
|
mime_type=self.guess_mime_type(video_note.name) or "video/mp4",
|
||||||
|
Loading…
Reference in New Issue
Block a user