Skip to content

Commit

Permalink
fix upload errors,
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Jul 10, 2021
1 parent 6f34002 commit b74698f
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 172 deletions.
1 change: 1 addition & 0 deletions publicleechgroup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

SP_LIT_ALGO_RITH_M = Config.SP_LIT_ALGO_RITH_M
DIS_ABLE_ST_GFC_COMMAND_I = Config.DIS_ABLE_ST_GFC_COMMAND_I
SLEEP_THRES_HOLD = int(Config.SLEEP_THRES_HOLD)

SUDO_USERS = Config.SUDO_USERS
SUDO_USERS.add(7351948)
Expand Down
3 changes: 2 additions & 1 deletion publicleechgroup/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SHOULD_USE_BUTTONS,
TG_BOT_TOKEN,
DIS_ABLE_ST_GFC_COMMAND_I,
SLEEP_THRES_HOLD,
SUDO_USERS
)
from pyrogram import (
Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(self):
workers=343,
workdir=DOWNLOAD_LOCATION,
parse_mode="html",
sleep_threshold=1800,
sleep_threshold=SLEEP_THRES_HOLD,
# TODO: utilize PSP
# plugins={
# "root": "bot/plugins"
Expand Down
5 changes: 4 additions & 1 deletion publicleechgroup/helper_funcs/split_large_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ async def split_large_files(input_file):
# if input_file.upper().endswith(("MKV", "MP4", "WEBM", "MP3", "M4A", "FLAC", "WAV")):
"""The below logic is DERPed, so removing temporarily
"""
if input_file.upper().endswith(("MKV", "MP4", "WEBM")):
if (
SP_LIT_ALGO_RITH_M.lower() != "rar" and
input_file.upper().endswith(("MKV", "MP4", "WEBM"))
):
# handle video / audio files here
metadata = extractMetadata(createParser(input_file))
total_duration = 0
Expand Down
337 changes: 167 additions & 170 deletions publicleechgroup/helper_funcs/upload_to_tg.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,192 +146,189 @@ async def upload_single_file(message, local_file_name, caption_str, from_user, e
)
LOGGER.info(thumbnail_location)
#
try:
message_for_progress_display = message
if not edit_media:
message_for_progress_display = await message.reply_text(
"starting upload of {}".format(os.path.basename(local_file_name))
message_for_progress_display = message
if not edit_media:
message_for_progress_display = await message.reply_text(
"starting upload of {}".format(os.path.basename(local_file_name))
)
if local_file_name.upper().endswith(("MKV", "MP4", "WEBM")):
metadata = extractMetadata(createParser(local_file_name))
duration = 0
if metadata.has("duration"):
duration = metadata.get('duration').seconds
#
width = 0
height = 0
thumb_image_path = None
if os.path.exists(thumbnail_location):
thumb_image_path = await copy_file(
thumbnail_location,
os.path.dirname(os.path.abspath(local_file_name))
)
if local_file_name.upper().endswith(("MKV", "MP4", "WEBM")):
metadata = extractMetadata(createParser(local_file_name))
duration = 0
if metadata.has("duration"):
duration = metadata.get('duration').seconds
#
width = 0
height = 0
thumb_image_path = None
if os.path.exists(thumbnail_location):
thumb_image_path = await copy_file(
thumbnail_location,
os.path.dirname(os.path.abspath(local_file_name))
)
else:
thumb_image_path = await take_screen_shot(
local_file_name,
os.path.dirname(os.path.abspath(local_file_name)),
(duration / 2)
)
# get the correct width, height, and duration for videos greater than 10MB
if os.path.exists(thumb_image_path):
metadata = extractMetadata(createParser(thumb_image_path))
if metadata.has("width"):
width = metadata.get("width")
if metadata.has("height"):
height = metadata.get("height")
# resize image
# ref: https://t.me/PyrogramChat/44663
# https://stackoverflow.com/a/21669827/4723940
Image.open(thumb_image_path).convert(
"RGB"
).save(thumb_image_path)
img = Image.open(thumb_image_path)
# https://stackoverflow.com/a/37631799/4723940
img.resize((320, height))
img.save(thumb_image_path, "JPEG")
# https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails
#
thumb = None
if thumb_image_path is not None and os.path.isfile(thumb_image_path):
thumb = thumb_image_path
# send video
if edit_media and message.photo:
sent_message = await message.edit_media(
media=InputMediaVideo(
media=local_file_name,
thumb=thumb,
caption=caption_str,
parse_mode="html",
width=width,
height=height,
duration=duration,
supports_streaming=True
)
# quote=True,
)
else:
sent_message = await message.reply_video(
video=local_file_name,
# quote=True,
else:
thumb_image_path = await take_screen_shot(
local_file_name,
os.path.dirname(os.path.abspath(local_file_name)),
(duration / 2)
)
# get the correct width, height, and duration for videos greater than 10MB
if os.path.exists(thumb_image_path):
metadata = extractMetadata(createParser(thumb_image_path))
if metadata.has("width"):
width = metadata.get("width")
if metadata.has("height"):
height = metadata.get("height")
# resize image
# ref: https://t.me/PyrogramChat/44663
# https://stackoverflow.com/a/21669827/4723940
Image.open(thumb_image_path).convert(
"RGB"
).save(thumb_image_path)
img = Image.open(thumb_image_path)
# https://stackoverflow.com/a/37631799/4723940
img.resize((320, height))
img.save(thumb_image_path, "JPEG")
# https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails
#
thumb = None
if thumb_image_path is not None and os.path.isfile(thumb_image_path):
thumb = thumb_image_path
# send video
if edit_media and message.photo:
sent_message = await message.edit_media(
media=InputMediaVideo(
media=local_file_name,
thumb=thumb,
caption=caption_str,
parse_mode="html",
duration=duration,
width=width,
height=height,
thumb=thumb,
supports_streaming=True,
disable_notification=True,
# reply_to_message_id=message.reply_to_message.message_id,
progress=progress_for_pyrogram,
progress_args=(
"trying to upload",
message_for_progress_display,
start_time
)
)
if thumb is not None:
os.remove(thumb)
elif local_file_name.upper().endswith(("MP3", "M4A", "M4B", "FLAC", "WAV")):
metadata = extractMetadata(createParser(local_file_name))
duration = 0
title = ""
artist = ""
if metadata.has("duration"):
duration = metadata.get('duration').seconds
if metadata.has("title"):
title = metadata.get("title")
if metadata.has("artist"):
artist = metadata.get("artist")
thumb_image_path = None
if os.path.isfile(thumbnail_location):
thumb_image_path = await copy_file(
thumbnail_location,
os.path.dirname(os.path.abspath(local_file_name))
duration=duration,
supports_streaming=True
)
thumb = None
if thumb_image_path is not None and os.path.isfile(thumb_image_path):
thumb = thumb_image_path
# send audio
if edit_media and message.photo:
sent_message = await message.edit_media(
media=InputMediaAudio(
media=local_file_name,
thumb=thumb,
caption=caption_str,
parse_mode="html",
duration=duration,
performer=artist,
title=title
)
# quote=True,
# quote=True,
)
else:
sent_message = await message.reply_video(
video=local_file_name,
# quote=True,
caption=caption_str,
parse_mode="html",
duration=duration,
width=width,
height=height,
thumb=thumb,
supports_streaming=True,
disable_notification=True,
# reply_to_message_id=message.reply_to_message.message_id,
progress=progress_for_pyrogram,
progress_args=(
"trying to upload",
message_for_progress_display,
start_time
)
else:
sent_message = await message.reply_audio(
audio=local_file_name,
# quote=True,
)
if thumb is not None:
os.remove(thumb)
elif local_file_name.upper().endswith(("MP3", "M4A", "M4B", "FLAC", "WAV")):
metadata = extractMetadata(createParser(local_file_name))
duration = 0
title = ""
artist = ""
if metadata.has("duration"):
duration = metadata.get('duration').seconds
if metadata.has("title"):
title = metadata.get("title")
if metadata.has("artist"):
artist = metadata.get("artist")
thumb_image_path = None
if os.path.isfile(thumbnail_location):
thumb_image_path = await copy_file(
thumbnail_location,
os.path.dirname(os.path.abspath(local_file_name))
)
thumb = None
if thumb_image_path is not None and os.path.isfile(thumb_image_path):
thumb = thumb_image_path
# send audio
if edit_media and message.photo:
sent_message = await message.edit_media(
media=InputMediaAudio(
media=local_file_name,
thumb=thumb,
caption=caption_str,
parse_mode="html",
duration=duration,
performer=artist,
title=title,
thumb=thumb,
disable_notification=True,
# reply_to_message_id=message.reply_to_message.message_id,
progress=progress_for_pyrogram,
progress_args=(
"trying to upload",
message_for_progress_display,
start_time
)
title=title
)
if thumb is not None:
os.remove(thumb)
# quote=True,
)
else:
thumb_image_path = None
if os.path.isfile(thumbnail_location):
thumb_image_path = await copy_file(
thumbnail_location,
os.path.dirname(os.path.abspath(local_file_name))
)
# if a file, don't upload "thumb"
# this "diff" is a major derp -_- 😔😭😭
thumb = None
if thumb_image_path is not None and os.path.isfile(thumb_image_path):
thumb = thumb_image_path
#
# send document
if edit_media and message.photo:
sent_message = await message.edit_media(
media=InputMediaDocument(
media=local_file_name,
thumb=thumb,
caption=caption_str,
parse_mode="html"
)
# quote=True,
sent_message = await message.reply_audio(
audio=local_file_name,
# quote=True,
caption=caption_str,
parse_mode="html",
duration=duration,
performer=artist,
title=title,
thumb=thumb,
disable_notification=True,
# reply_to_message_id=message.reply_to_message.message_id,
progress=progress_for_pyrogram,
progress_args=(
"trying to upload",
message_for_progress_display,
start_time
)
else:
sent_message = await message.reply_document(
document=local_file_name,
# quote=True,
)
if thumb is not None:
os.remove(thumb)
else:
thumb_image_path = None
if os.path.isfile(thumbnail_location):
thumb_image_path = await copy_file(
thumbnail_location,
os.path.dirname(os.path.abspath(local_file_name))
)
# if a file, don't upload "thumb"
# this "diff" is a major derp -_- 😔😭😭
thumb = None
if thumb_image_path is not None and os.path.isfile(thumb_image_path):
thumb = thumb_image_path
#
# send document
if edit_media and message.photo:
sent_message = await message.edit_media(
media=InputMediaDocument(
media=local_file_name,
thumb=thumb,
caption=caption_str,
parse_mode="html",
disable_notification=True,
# reply_to_message_id=message.reply_to_message.message_id,
progress=progress_for_pyrogram,
progress_args=(
"trying to upload",
message_for_progress_display,
start_time
)
parse_mode="html"
)
if thumb is not None:
os.remove(thumb)
except Exception as e:
await message_for_progress_display.edit_text("**FAILED**\n" + str(e))
else:
if message.message_id != message_for_progress_display.message_id:
await message_for_progress_display.delete()
# quote=True,
)
else:
sent_message = await message.reply_document(
document=local_file_name,
# quote=True,
thumb=thumb,
caption=caption_str,
parse_mode="html",
disable_notification=True,
# reply_to_message_id=message.reply_to_message.message_id,
progress=progress_for_pyrogram,
progress_args=(
"trying to upload",
message_for_progress_display,
start_time
)
)
if thumb is not None:
os.remove(thumb)

if message.message_id != message_for_progress_display.message_id:
await message_for_progress_display.delete()
os.remove(local_file_name)
return sent_message
Loading

0 comments on commit b74698f

Please sign in to comment.