Spaces:
Paused
Paused
Commit
·
013b9a2
1
Parent(s):
1e52124
Upload 6 files
Browse files- plugins/cb_buttons.py +127 -0
- plugins/custom_thumbnail.py +120 -0
- plugins/dl_button.py +326 -0
- plugins/help_text.py +61 -0
- plugins/youtube_dl_button.py +365 -0
- plugins/youtube_dl_echo.py +376 -0
plugins/cb_buttons.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# (c) Shrimadhav U K
|
| 4 |
+
|
| 5 |
+
# the logging things
|
| 6 |
+
import logging
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
import json
|
| 12 |
+
import math
|
| 13 |
+
import os
|
| 14 |
+
import shutil
|
| 15 |
+
import subprocess
|
| 16 |
+
import time
|
| 17 |
+
|
| 18 |
+
# the secret configuration specific things
|
| 19 |
+
if bool(os.environ.get("WEBHOOK", False)):
|
| 20 |
+
from sample_config import Config
|
| 21 |
+
else:
|
| 22 |
+
from config import Config
|
| 23 |
+
|
| 24 |
+
# the Strings used for this "thing"
|
| 25 |
+
from translation import Translation
|
| 26 |
+
|
| 27 |
+
import pyrogram
|
| 28 |
+
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
| 29 |
+
|
| 30 |
+
from helper_funcs.display_progress import progress_for_pyrogram, humanbytes
|
| 31 |
+
from plugins.youtube_dl_button import youtube_dl_call_back
|
| 32 |
+
from plugins.dl_button import ddl_call_back
|
| 33 |
+
from hachoir.metadata import extractMetadata
|
| 34 |
+
from hachoir.parser import createParser
|
| 35 |
+
# https://stackoverflow.com/a/37631799/4723940
|
| 36 |
+
from PIL import Image
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@pyrogram.Client.on_callback_query()
|
| 40 |
+
async def button(bot, update):
|
| 41 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 42 |
+
# logger.info(update)
|
| 43 |
+
cb_data = update.data
|
| 44 |
+
if ":" in cb_data:
|
| 45 |
+
# unzip formats
|
| 46 |
+
extract_dir_path = Config.DOWNLOAD_LOCATION + \
|
| 47 |
+
"/" + str(update.from_user.id) + "zipped" + "/"
|
| 48 |
+
if not os.path.isdir(extract_dir_path):
|
| 49 |
+
await bot.delete_messages(
|
| 50 |
+
chat_id=update.message.chat.id,
|
| 51 |
+
message_ids=update.message.message_id,
|
| 52 |
+
revoke=True
|
| 53 |
+
)
|
| 54 |
+
return False
|
| 55 |
+
zip_file_contents = os.listdir(extract_dir_path)
|
| 56 |
+
type_of_extract, index_extractor, undefined_tcartxe = cb_data.split(":")
|
| 57 |
+
if index_extractor == "NONE":
|
| 58 |
+
try:
|
| 59 |
+
shutil.rmtree(extract_dir_path)
|
| 60 |
+
except:
|
| 61 |
+
pass
|
| 62 |
+
await bot.edit_message_text(
|
| 63 |
+
chat_id=update.message.chat.id,
|
| 64 |
+
text=Translation.CANCEL_STR,
|
| 65 |
+
message_id=update.message.message_id
|
| 66 |
+
)
|
| 67 |
+
elif index_extractor == "ALL":
|
| 68 |
+
i = 0
|
| 69 |
+
for file_content in zip_file_contents:
|
| 70 |
+
current_file_name = os.path.join(extract_dir_path, file_content)
|
| 71 |
+
start_time = time.time()
|
| 72 |
+
await bot.send_document(
|
| 73 |
+
chat_id=update.message.chat.id,
|
| 74 |
+
document=current_file_name,
|
| 75 |
+
# thumb=thumb_image_path,
|
| 76 |
+
caption=file_content,
|
| 77 |
+
# reply_markup=reply_markup,
|
| 78 |
+
reply_to_message_id=update.message.message_id,
|
| 79 |
+
progress=progress_for_pyrogram,
|
| 80 |
+
progress_args=(
|
| 81 |
+
Translation.UPLOAD_START,
|
| 82 |
+
update.message,
|
| 83 |
+
start_time
|
| 84 |
+
)
|
| 85 |
+
)
|
| 86 |
+
i = i + 1
|
| 87 |
+
os.remove(current_file_name)
|
| 88 |
+
try:
|
| 89 |
+
shutil.rmtree(extract_dir_path)
|
| 90 |
+
except:
|
| 91 |
+
pass
|
| 92 |
+
await bot.edit_message_text(
|
| 93 |
+
chat_id=update.message.chat.id,
|
| 94 |
+
text=Translation.ZIP_UPLOADED_STR.format(i, "0"),
|
| 95 |
+
message_id=update.message.message_id
|
| 96 |
+
)
|
| 97 |
+
else:
|
| 98 |
+
file_content = zip_file_contents[int(index_extractor)]
|
| 99 |
+
current_file_name = os.path.join(extract_dir_path, file_content)
|
| 100 |
+
start_time = time.time()
|
| 101 |
+
await bot.send_document(
|
| 102 |
+
chat_id=update.message.chat.id,
|
| 103 |
+
document=current_file_name,
|
| 104 |
+
# thumb=thumb_image_path,
|
| 105 |
+
caption=file_content,
|
| 106 |
+
# reply_markup=reply_markup,
|
| 107 |
+
reply_to_message_id=update.message.message_id,
|
| 108 |
+
progress=progress_for_pyrogram,
|
| 109 |
+
progress_args=(
|
| 110 |
+
Translation.UPLOAD_START,
|
| 111 |
+
update.message,
|
| 112 |
+
start_time
|
| 113 |
+
)
|
| 114 |
+
)
|
| 115 |
+
try:
|
| 116 |
+
shutil.rmtree(extract_dir_path)
|
| 117 |
+
except:
|
| 118 |
+
pass
|
| 119 |
+
await bot.edit_message_text(
|
| 120 |
+
chat_id=update.message.chat.id,
|
| 121 |
+
text=Translation.ZIP_UPLOADED_STR.format("1", "0"),
|
| 122 |
+
message_id=update.message.message_id
|
| 123 |
+
)
|
| 124 |
+
elif "|" in cb_data:
|
| 125 |
+
await youtube_dl_call_back(bot, update)
|
| 126 |
+
elif "=" in cb_data:
|
| 127 |
+
await ddl_call_back(bot, update)
|
plugins/custom_thumbnail.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# (c) Shrimadhav U K
|
| 4 |
+
|
| 5 |
+
# the logging things
|
| 6 |
+
import logging
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
import numpy
|
| 12 |
+
import os
|
| 13 |
+
from PIL import Image
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
+
# the secret configuration specific things
|
| 17 |
+
if bool(os.environ.get("WEBHOOK", False)):
|
| 18 |
+
from sample_config import Config
|
| 19 |
+
else:
|
| 20 |
+
from config import Config
|
| 21 |
+
|
| 22 |
+
# the Strings used for this "thing"
|
| 23 |
+
from translation import Translation
|
| 24 |
+
|
| 25 |
+
import pyrogram
|
| 26 |
+
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@pyrogram.Client.on_message(pyrogram.filters.command(["genthumbnail"]))
|
| 30 |
+
async def generate_custom_thumbnail(bot, update):
|
| 31 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 32 |
+
if update.reply_to_message is not None:
|
| 33 |
+
reply_message = update.reply_to_message
|
| 34 |
+
if reply_message.media_group_id is not None:
|
| 35 |
+
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + "/" + str(reply_message.media_group_id) + "/"
|
| 36 |
+
save_final_image = download_location + str(round(time.time())) + ".jpg"
|
| 37 |
+
list_im = os.listdir(download_location)
|
| 38 |
+
if len(list_im) == 2:
|
| 39 |
+
imgs = [ Image.open(download_location + i) for i in list_im ]
|
| 40 |
+
inm_aesph = sorted([(numpy.sum(i.size), i.size) for i in imgs])
|
| 41 |
+
min_shape = inm_aesph[1][1]
|
| 42 |
+
imgs_comb = numpy.hstack(numpy.asarray(i.resize(min_shape)) for i in imgs)
|
| 43 |
+
imgs_comb = Image.fromarray(imgs_comb)
|
| 44 |
+
# combine: https://stackoverflow.com/a/30228789/4723940
|
| 45 |
+
imgs_comb.save(save_final_image)
|
| 46 |
+
# send
|
| 47 |
+
user = await bot.get_me()
|
| 48 |
+
mention = user["mention"]
|
| 49 |
+
await bot.send_photo(
|
| 50 |
+
chat_id=update.chat.id,
|
| 51 |
+
photo=save_final_image,
|
| 52 |
+
caption=Translation.CUSTOM_CAPTION_UL_FILE.format(mention),
|
| 53 |
+
reply_to_message_id=update.message_id
|
| 54 |
+
)
|
| 55 |
+
else:
|
| 56 |
+
await bot.send_message(
|
| 57 |
+
chat_id=update.chat.id,
|
| 58 |
+
text=Translation.ERR_ONLY_TWO_MEDIA_IN_ALBUM,
|
| 59 |
+
reply_to_message_id=update.message_id
|
| 60 |
+
)
|
| 61 |
+
try:
|
| 62 |
+
[os.remove(download_location + i) for i in list_im ]
|
| 63 |
+
os.remove(download_location)
|
| 64 |
+
except:
|
| 65 |
+
pass
|
| 66 |
+
else:
|
| 67 |
+
await bot.send_message(
|
| 68 |
+
chat_id=update.chat.id,
|
| 69 |
+
text=Translation.REPLY_TO_MEDIA_ALBUM_TO_GEN_THUMB,
|
| 70 |
+
reply_to_message_id=update.message_id
|
| 71 |
+
)
|
| 72 |
+
else:
|
| 73 |
+
await bot.send_message(
|
| 74 |
+
chat_id=update.chat.id,
|
| 75 |
+
text=Translation.REPLY_TO_MEDIA_ALBUM_TO_GEN_THUMB,
|
| 76 |
+
reply_to_message_id=update.message_id
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@pyrogram.Client.on_message(pyrogram.filters.photo)
|
| 81 |
+
async def save_photo(bot, update):
|
| 82 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 83 |
+
if update.media_group_id is not None:
|
| 84 |
+
# album is sent
|
| 85 |
+
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + "/" + str(update.media_group_id) + "/"
|
| 86 |
+
# create download directory, if not exist
|
| 87 |
+
if not os.path.isdir(download_location):
|
| 88 |
+
os.makedirs(download_location)
|
| 89 |
+
await bot.download_media(
|
| 90 |
+
message=update,
|
| 91 |
+
file_name=download_location
|
| 92 |
+
)
|
| 93 |
+
else:
|
| 94 |
+
# received single photo
|
| 95 |
+
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
|
| 96 |
+
await bot.download_media(
|
| 97 |
+
message=update,
|
| 98 |
+
file_name=download_location
|
| 99 |
+
)
|
| 100 |
+
await bot.send_message(
|
| 101 |
+
chat_id=update.chat.id,
|
| 102 |
+
text=Translation.SAVED_CUSTOM_THUMB_NAIL,
|
| 103 |
+
reply_to_message_id=update.message_id
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
@pyrogram.Client.on_message(pyrogram.filters.command(["delthumbnail"]))
|
| 108 |
+
async def delthumbnail(bot, update):
|
| 109 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 110 |
+
download_location = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id)
|
| 111 |
+
try:
|
| 112 |
+
os.remove(download_location + ".jpg")
|
| 113 |
+
# os.remove(download_location + ".json")
|
| 114 |
+
except:
|
| 115 |
+
pass
|
| 116 |
+
await bot.send_message(
|
| 117 |
+
chat_id=update.chat.id,
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# (c) Shrimadhav U K
|
| 4 |
+
|
| 5 |
+
# the logging things
|
| 6 |
+
import logging
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
import asyncio
|
| 12 |
+
import aiohttp
|
| 13 |
+
import json
|
| 14 |
+
import math
|
| 15 |
+
import os
|
| 16 |
+
import shutil
|
| 17 |
+
import time
|
| 18 |
+
from datetime import datetime
|
| 19 |
+
|
| 20 |
+
# the secret configuration specific things
|
| 21 |
+
if bool(os.environ.get("WEBHOOK", False)):
|
| 22 |
+
from sample_config import Config
|
| 23 |
+
else:
|
| 24 |
+
from config import Config
|
| 25 |
+
|
| 26 |
+
# the Strings used for this "thing"
|
| 27 |
+
from translation import Translation
|
| 28 |
+
|
| 29 |
+
import pyrogram
|
| 30 |
+
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
| 31 |
+
|
| 32 |
+
from helper_funcs.display_progress import progress_for_pyrogram, humanbytes, TimeFormatter
|
| 33 |
+
from hachoir.metadata import extractMetadata
|
| 34 |
+
from hachoir.parser import createParser
|
| 35 |
+
# https://stackoverflow.com/a/37631799/4723940
|
| 36 |
+
from PIL import Image
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
async def ddl_call_back(bot, update):
|
| 40 |
+
logger.info(update)
|
| 41 |
+
cb_data = update.data
|
| 42 |
+
# youtube_dl extractors
|
| 43 |
+
tg_send_type, youtube_dl_format, youtube_dl_ext = cb_data.split("=")
|
| 44 |
+
thumb_image_path = Config.DOWNLOAD_LOCATION + \
|
| 45 |
+
"/" + str(update.from_user.id) + ".jpg"
|
| 46 |
+
youtube_dl_url = update.message.reply_to_message.text
|
| 47 |
+
custom_file_name = os.path.basename(youtube_dl_url)
|
| 48 |
+
if "|" in youtube_dl_url:
|
| 49 |
+
url_parts = youtube_dl_url.split("|")
|
| 50 |
+
if len(url_parts) == 2:
|
| 51 |
+
youtube_dl_url = url_parts[0]
|
| 52 |
+
custom_file_name = url_parts[1]
|
| 53 |
+
else:
|
| 54 |
+
for entity in update.message.reply_to_message.entities:
|
| 55 |
+
if entity.type == "text_link":
|
| 56 |
+
youtube_dl_url = entity.url
|
| 57 |
+
elif entity.type == "url":
|
| 58 |
+
o = entity.offset
|
| 59 |
+
l = entity.length
|
| 60 |
+
youtube_dl_url = youtube_dl_url[o:o + l]
|
| 61 |
+
if youtube_dl_url is not None:
|
| 62 |
+
youtube_dl_url = youtube_dl_url.strip()
|
| 63 |
+
if custom_file_name is not None:
|
| 64 |
+
custom_file_name = custom_file_name.strip()
|
| 65 |
+
# https://stackoverflow.com/a/761825/4723940
|
| 66 |
+
logger.info(youtube_dl_url)
|
| 67 |
+
logger.info(custom_file_name)
|
| 68 |
+
else:
|
| 69 |
+
for entity in update.message.reply_to_message.entities:
|
| 70 |
+
if entity.type == "text_link":
|
| 71 |
+
youtube_dl_url = entity.url
|
| 72 |
+
elif entity.type == "url":
|
| 73 |
+
o = entity.offset
|
| 74 |
+
l = entity.length
|
| 75 |
+
youtube_dl_url = youtube_dl_url[o:o + l]
|
| 76 |
+
user = await bot.get_me()
|
| 77 |
+
mention = user["mention"]
|
| 78 |
+
description = Translation.CUSTOM_CAPTION_UL_FILE.format(mention)
|
| 79 |
+
start = datetime.now()
|
| 80 |
+
await bot.edit_message_text(
|
| 81 |
+
text=Translation.DOWNLOAD_START,
|
| 82 |
+
chat_id=update.message.chat.id,
|
| 83 |
+
message_id=update.message.message_id
|
| 84 |
+
)
|
| 85 |
+
tmp_directory_for_each_user = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id)
|
| 86 |
+
if not os.path.isdir(tmp_directory_for_each_user):
|
| 87 |
+
os.makedirs(tmp_directory_for_each_user)
|
| 88 |
+
download_directory = tmp_directory_for_each_user + "/" + custom_file_name
|
| 89 |
+
command_to_exec = []
|
| 90 |
+
async with aiohttp.ClientSession() as session:
|
| 91 |
+
c_time = time.time()
|
| 92 |
+
try:
|
| 93 |
+
await download_coroutine(
|
| 94 |
+
bot,
|
| 95 |
+
session,
|
| 96 |
+
youtube_dl_url,
|
| 97 |
+
download_directory,
|
| 98 |
+
update.message.chat.id,
|
| 99 |
+
update.message.message_id,
|
| 100 |
+
c_time
|
| 101 |
+
)
|
| 102 |
+
except asyncio.TimeoutError:
|
| 103 |
+
await bot.edit_message_text(
|
| 104 |
+
text=Translation.SLOW_URL_DECED,
|
| 105 |
+
chat_id=update.message.chat.id,
|
| 106 |
+
message_id=update.message.message_id
|
| 107 |
+
)
|
| 108 |
+
return False
|
| 109 |
+
if os.path.exists(download_directory):
|
| 110 |
+
end_one = datetime.now()
|
| 111 |
+
await bot.edit_message_text(
|
| 112 |
+
text=Translation.UPLOAD_START,
|
| 113 |
+
chat_id=update.message.chat.id,
|
| 114 |
+
message_id=update.message.message_id
|
| 115 |
+
)
|
| 116 |
+
file_size = Config.TG_MAX_FILE_SIZE + 1
|
| 117 |
+
try:
|
| 118 |
+
file_size = os.stat(download_directory).st_size
|
| 119 |
+
except FileNotFoundError as exc:
|
| 120 |
+
download_directory = os.path.splitext(download_directory)[0] + "." + "mkv"
|
| 121 |
+
# https://stackoverflow.com/a/678242/4723940
|
| 122 |
+
file_size = os.stat(download_directory).st_size
|
| 123 |
+
if file_size > Config.TG_MAX_FILE_SIZE:
|
| 124 |
+
await bot.edit_message_text(
|
| 125 |
+
chat_id=update.message.chat.id,
|
| 126 |
+
text=Translation.RCHD_TG_API_LIMIT,
|
| 127 |
+
message_id=update.message.message_id
|
| 128 |
+
)
|
| 129 |
+
else:
|
| 130 |
+
# get the correct width, height, and duration for videos greater than 10MB
|
| 131 |
+
# ref: message from @BotSupport
|
| 132 |
+
width = 0
|
| 133 |
+
height = 0
|
| 134 |
+
duration = 0
|
| 135 |
+
if tg_send_type != "file":
|
| 136 |
+
metadata = extractMetadata(createParser(download_directory))
|
| 137 |
+
if metadata is not None:
|
| 138 |
+
if metadata.has("duration"):
|
| 139 |
+
duration = metadata.get('duration').seconds
|
| 140 |
+
# get the correct width, height, and duration for videos greater than 10MB
|
| 141 |
+
if os.path.exists(thumb_image_path):
|
| 142 |
+
width = 0
|
| 143 |
+
height = 0
|
| 144 |
+
metadata = extractMetadata(createParser(thumb_image_path))
|
| 145 |
+
if metadata.has("width"):
|
| 146 |
+
width = metadata.get("width")
|
| 147 |
+
if metadata.has("height"):
|
| 148 |
+
height = metadata.get("height")
|
| 149 |
+
if tg_send_type == "vm":
|
| 150 |
+
height = width
|
| 151 |
+
# resize image
|
| 152 |
+
# ref: https://t.me/PyrogramChat/44663
|
| 153 |
+
# https://stackoverflow.com/a/21669827/4723940
|
| 154 |
+
Image.open(thumb_image_path).convert(
|
| 155 |
+
"RGB").save(thumb_image_path)
|
| 156 |
+
img = Image.open(thumb_image_path)
|
| 157 |
+
# https://stackoverflow.com/a/37631799/4723940
|
| 158 |
+
# img.thumbnail((90, 90))
|
| 159 |
+
if tg_send_type == "file":
|
| 160 |
+
img.resize((320, height))
|
| 161 |
+
else:
|
| 162 |
+
img.resize((90, height))
|
| 163 |
+
img.save(thumb_image_path, "JPEG")
|
| 164 |
+
# https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails
|
| 165 |
+
else:
|
| 166 |
+
thumb_image_path = None
|
| 167 |
+
start_time = time.time()
|
| 168 |
+
# try to upload file
|
| 169 |
+
if tg_send_type == "audio":
|
| 170 |
+
user = await bot.get_me()
|
| 171 |
+
mention = user["mention"]
|
| 172 |
+
audio = await bot.send_audio(
|
| 173 |
+
chat_id=update.message.chat.id,
|
| 174 |
+
audio=download_directory,
|
| 175 |
+
caption=description + f"\n\nSubmitted by {update.from_user.mention}\nUploaded by {mention}",
|
| 176 |
+
duration=duration,
|
| 177 |
+
# performer=response_json["uploader"],
|
| 178 |
+
# title=response_json["title"],
|
| 179 |
+
# reply_markup=reply_markup,
|
| 180 |
+
thumb=thumb_image_path,
|
| 181 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 182 |
+
progress=progress_for_pyrogram,
|
| 183 |
+
progress_args=(
|
| 184 |
+
Translation.UPLOAD_START,
|
| 185 |
+
update.message,
|
| 186 |
+
start_time
|
| 187 |
+
)
|
| 188 |
+
)
|
| 189 |
+
await audio.forward(Config.LOG_CHANNEL)
|
| 190 |
+
elif tg_send_type == "file":
|
| 191 |
+
user = await bot.get_me()
|
| 192 |
+
mention = user["mention"]
|
| 193 |
+
document = await bot.send_document(
|
| 194 |
+
chat_id=update.message.chat.id,
|
| 195 |
+
document=download_directory,
|
| 196 |
+
thumb=thumb_image_path,
|
| 197 |
+
caption=description + f"\n\nSubmitted by {update.from_user.mention}\nUploaded by {mention}",
|
| 198 |
+
# reply_markup=reply_markup,
|
| 199 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 200 |
+
progress=progress_for_pyrogram,
|
| 201 |
+
progress_args=(
|
| 202 |
+
Translation.UPLOAD_START,
|
| 203 |
+
update.message,
|
| 204 |
+
start_time
|
| 205 |
+
)
|
| 206 |
+
)
|
| 207 |
+
await document.forward(Config.LOG_CHANNEL)
|
| 208 |
+
elif tg_send_type == "vm":
|
| 209 |
+
user = await bot.get_me()
|
| 210 |
+
mention = user["mention"]
|
| 211 |
+
video_note = await bot.send_video_note(
|
| 212 |
+
chat_id=update.message.chat.id,
|
| 213 |
+
video_note=download_directory,
|
| 214 |
+
duration=duration,
|
| 215 |
+
length=width,
|
| 216 |
+
thumb=thumb_image_path,
|
| 217 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 218 |
+
progress=progress_for_pyrogram,
|
| 219 |
+
progress_args=(
|
| 220 |
+
Translation.UPLOAD_START,
|
| 221 |
+
update.message,
|
| 222 |
+
start_time
|
| 223 |
+
)
|
| 224 |
+
)
|
| 225 |
+
vm = await video_note.forward(Config.LOG_CHANNEL)
|
| 226 |
+
await vm.reply_text(f"Submitted by {update.from_user.mention}\nUploaded by {mention}")
|
| 227 |
+
elif tg_send_type == "video":
|
| 228 |
+
user = await bot.get_me()
|
| 229 |
+
mention = user["mention"]
|
| 230 |
+
video = await bot.send_video(
|
| 231 |
+
chat_id=update.message.chat.id,
|
| 232 |
+
video=download_directory,
|
| 233 |
+
caption=description + f"\n\nSubmitted by {update.from_user.mention}\nUploaded by {mention}",
|
| 234 |
+
duration=duration,
|
| 235 |
+
width=width,
|
| 236 |
+
height=height,
|
| 237 |
+
supports_streaming=True,
|
| 238 |
+
# reply_markup=reply_markup,
|
| 239 |
+
thumb=thumb_image_path,
|
| 240 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 241 |
+
progress=progress_for_pyrogram,
|
| 242 |
+
progress_args=(
|
| 243 |
+
Translation.UPLOAD_START,
|
| 244 |
+
update.message,
|
| 245 |
+
start_time
|
| 246 |
+
)
|
| 247 |
+
)
|
| 248 |
+
await video.forward(Config.LOG_CHANNEL)
|
| 249 |
+
else:
|
| 250 |
+
logger.info("Did this happen? :\\")
|
| 251 |
+
end_two = datetime.now()
|
| 252 |
+
try:
|
| 253 |
+
os.remove(download_directory)
|
| 254 |
+
os.remove(thumb_image_path)
|
| 255 |
+
except:
|
| 256 |
+
pass
|
| 257 |
+
time_taken_for_download = (end_one - start).seconds
|
| 258 |
+
time_taken_for_upload = (end_two - end_one).seconds
|
| 259 |
+
await bot.edit_message_text(
|
| 260 |
+
text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG_WITH_TS.format(time_taken_for_download, time_taken_for_upload),
|
| 261 |
+
chat_id=update.message.chat.id,
|
| 262 |
+
message_id=update.message.message_id,
|
| 263 |
+
disable_web_page_preview=True
|
| 264 |
+
)
|
| 265 |
+
else:
|
| 266 |
+
await bot.edit_message_text(
|
| 267 |
+
text=Translation.NO_VOID_FORMAT_FOUND.format("Incorrect Link"),
|
| 268 |
+
chat_id=update.message.chat.id,
|
| 269 |
+
message_id=update.message.message_id,
|
| 270 |
+
disable_web_page_preview=True
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
async def download_coroutine(bot, session, url, file_name, chat_id, message_id, start):
|
| 275 |
+
downloaded = 0
|
| 276 |
+
display_message = ""
|
| 277 |
+
async with session.get(url, timeout=Config.PROCESS_MAX_TIMEOUT) as response:
|
| 278 |
+
total_length = int(response.headers["Content-Length"])
|
| 279 |
+
content_type = response.headers["Content-Type"]
|
| 280 |
+
if "text" in content_type and total_length < 500:
|
| 281 |
+
return await response.release()
|
| 282 |
+
await bot.edit_message_text(
|
| 283 |
+
chat_id,
|
| 284 |
+
message_id,
|
| 285 |
+
text="""Initiating Download
|
| 286 |
+
URL: {}
|
| 287 |
+
File Size: {}""".format(url, humanbytes(total_length))
|
| 288 |
+
)
|
| 289 |
+
with open(file_name, "wb") as f_handle:
|
| 290 |
+
while True:
|
| 291 |
+
chunk = await response.content.read(Config.CHUNK_SIZE)
|
| 292 |
+
if not chunk:
|
| 293 |
+
break
|
| 294 |
+
f_handle.write(chunk)
|
| 295 |
+
downloaded += Config.CHUNK_SIZE
|
| 296 |
+
now = time.time()
|
| 297 |
+
diff = now - start
|
| 298 |
+
if round(diff % 5.00) == 0 or downloaded == total_length:
|
| 299 |
+
percentage = downloaded * 100 / total_length
|
| 300 |
+
speed = downloaded / diff
|
| 301 |
+
elapsed_time = round(diff) * 1000
|
| 302 |
+
time_to_completion = round(
|
| 303 |
+
(total_length - downloaded) / speed) * 1000
|
| 304 |
+
estimated_total_time = elapsed_time + time_to_completion
|
| 305 |
+
try:
|
| 306 |
+
current_message = """**Download Status**
|
| 307 |
+
URL: {}
|
| 308 |
+
File Size: {}
|
| 309 |
+
Downloaded: {}
|
| 310 |
+
ETA: {}""".format(
|
| 311 |
+
url,
|
| 312 |
+
humanbytes(total_length),
|
| 313 |
+
humanbytes(downloaded),
|
| 314 |
+
TimeFormatter(estimated_total_time)
|
| 315 |
+
)
|
| 316 |
+
if current_message != display_message:
|
| 317 |
+
await bot.edit_message_text(
|
| 318 |
+
chat_id,
|
| 319 |
+
message_id,
|
| 320 |
+
text=current_message
|
| 321 |
+
)
|
| 322 |
+
display_message = current_message
|
| 323 |
+
except Exception as e:
|
| 324 |
+
logger.info(str(e))
|
| 325 |
+
pass
|
| 326 |
+
return await response.release()
|
plugins/help_text.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# (c) Shrimadhav U K
|
| 4 |
+
|
| 5 |
+
# the logging things
|
| 6 |
+
import logging
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import sqlite3
|
| 13 |
+
|
| 14 |
+
# the secret configuration specific things
|
| 15 |
+
if bool(os.environ.get("WEBHOOK", False)):
|
| 16 |
+
from sample_config import Config
|
| 17 |
+
else:
|
| 18 |
+
from config import Config
|
| 19 |
+
|
| 20 |
+
# the Strings used for this "thing"
|
| 21 |
+
from translation import Translation
|
| 22 |
+
|
| 23 |
+
import pyrogram
|
| 24 |
+
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
| 25 |
+
|
| 26 |
+
from pyrogram.types.bots_and_keyboards import InlineKeyboardButton, InlineKeyboardMarkup
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@pyrogram.Client.on_message(pyrogram.filters.command(["help"]))
|
| 30 |
+
async def help_user(bot, update):
|
| 31 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 32 |
+
# logger.info(update)
|
| 33 |
+
await bot.send_message(
|
| 34 |
+
chat_id=update.chat.id,
|
| 35 |
+
text=Translation.HELP_USER,
|
| 36 |
+
parse_mode="html",
|
| 37 |
+
disable_web_page_preview=True,
|
| 38 |
+
reply_to_message_id=update.message_id
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
@pyrogram.Client.on_message(pyrogram.filters.command(["start"]))
|
| 43 |
+
async def start(bot, update):
|
| 44 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 45 |
+
# logger.info(update)
|
| 46 |
+
await bot.send_message(
|
| 47 |
+
chat_id=update.chat.id,
|
| 48 |
+
text=Translation.START_TEXT.format(update.from_user.first_name),
|
| 49 |
+
reply_markup=InlineKeyboardMarkup(
|
| 50 |
+
[
|
| 51 |
+
[
|
| 52 |
+
InlineKeyboardButton(
|
| 53 |
+
"Source", url="https://github.com/X-Gorn/X-URL-Uploader"
|
| 54 |
+
),
|
| 55 |
+
InlineKeyboardButton("Project Channel", url="https://t.me/xTeamBots"),
|
| 56 |
+
],
|
| 57 |
+
[InlineKeyboardButton("Author", url="https://t.me/xgorn")],
|
| 58 |
+
]
|
| 59 |
+
),
|
| 60 |
+
reply_to_message_id=update.message_id
|
| 61 |
+
)
|
plugins/youtube_dl_button.py
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# (c) Shrimadhav U K
|
| 4 |
+
|
| 5 |
+
# the logging things
|
| 6 |
+
import logging
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
import asyncio
|
| 12 |
+
import json
|
| 13 |
+
import math
|
| 14 |
+
import os
|
| 15 |
+
import shutil
|
| 16 |
+
import time
|
| 17 |
+
from datetime import datetime
|
| 18 |
+
|
| 19 |
+
# the secret configuration specific things
|
| 20 |
+
if bool(os.environ.get("WEBHOOK", False)):
|
| 21 |
+
from sample_config import Config
|
| 22 |
+
else:
|
| 23 |
+
from config import Config
|
| 24 |
+
|
| 25 |
+
# the Strings used for this "thing"
|
| 26 |
+
from translation import Translation
|
| 27 |
+
|
| 28 |
+
import pyrogram
|
| 29 |
+
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
| 30 |
+
|
| 31 |
+
from pyrogram.types import InputMediaPhoto
|
| 32 |
+
from helper_funcs.display_progress import progress_for_pyrogram, humanbytes
|
| 33 |
+
from hachoir.metadata import extractMetadata
|
| 34 |
+
from hachoir.parser import createParser
|
| 35 |
+
# https://stackoverflow.com/a/37631799/4723940
|
| 36 |
+
from PIL import Image
|
| 37 |
+
from helper_funcs.help_Nekmo_ffmpeg import generate_screen_shots
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
async def youtube_dl_call_back(bot, update):
|
| 41 |
+
cb_data = update.data
|
| 42 |
+
# youtube_dl extractors
|
| 43 |
+
tg_send_type, youtube_dl_format, youtube_dl_ext = cb_data.split("|")
|
| 44 |
+
thumb_image_path = Config.DOWNLOAD_LOCATION + \
|
| 45 |
+
"/" + str(update.from_user.id) + ".jpg"
|
| 46 |
+
save_ytdl_json_path = Config.DOWNLOAD_LOCATION + \
|
| 47 |
+
"/" + str(update.from_user.id) + ".json"
|
| 48 |
+
try:
|
| 49 |
+
with open(save_ytdl_json_path, "r", encoding="utf8") as f:
|
| 50 |
+
response_json = json.load(f)
|
| 51 |
+
except (FileNotFoundError) as e:
|
| 52 |
+
await bot.delete_messages(
|
| 53 |
+
chat_id=update.message.chat.id,
|
| 54 |
+
message_ids=update.message.message_id,
|
| 55 |
+
revoke=True
|
| 56 |
+
)
|
| 57 |
+
return False
|
| 58 |
+
youtube_dl_url = update.message.reply_to_message.text
|
| 59 |
+
custom_file_name = str(response_json.get("title")) + \
|
| 60 |
+
"_" + youtube_dl_format + "." + youtube_dl_ext
|
| 61 |
+
youtube_dl_username = None
|
| 62 |
+
youtube_dl_password = None
|
| 63 |
+
if "|" in youtube_dl_url:
|
| 64 |
+
url_parts = youtube_dl_url.split("|")
|
| 65 |
+
if len(url_parts) == 2:
|
| 66 |
+
youtube_dl_url = url_parts[0]
|
| 67 |
+
custom_file_name = url_parts[1]
|
| 68 |
+
elif len(url_parts) == 4:
|
| 69 |
+
youtube_dl_url = url_parts[0]
|
| 70 |
+
custom_file_name = url_parts[1]
|
| 71 |
+
youtube_dl_username = url_parts[2]
|
| 72 |
+
youtube_dl_password = url_parts[3]
|
| 73 |
+
else:
|
| 74 |
+
for entity in update.message.reply_to_message.entities:
|
| 75 |
+
if entity.type == "text_link":
|
| 76 |
+
youtube_dl_url = entity.url
|
| 77 |
+
elif entity.type == "url":
|
| 78 |
+
o = entity.offset
|
| 79 |
+
l = entity.length
|
| 80 |
+
youtube_dl_url = youtube_dl_url[o:o + l]
|
| 81 |
+
if youtube_dl_url is not None:
|
| 82 |
+
youtube_dl_url = youtube_dl_url.strip()
|
| 83 |
+
if custom_file_name is not None:
|
| 84 |
+
custom_file_name = custom_file_name.strip()
|
| 85 |
+
# https://stackoverflow.com/a/761825/4723940
|
| 86 |
+
if youtube_dl_username is not None:
|
| 87 |
+
youtube_dl_username = youtube_dl_username.strip()
|
| 88 |
+
if youtube_dl_password is not None:
|
| 89 |
+
youtube_dl_password = youtube_dl_password.strip()
|
| 90 |
+
logger.info(youtube_dl_url)
|
| 91 |
+
logger.info(custom_file_name)
|
| 92 |
+
else:
|
| 93 |
+
for entity in update.message.reply_to_message.entities:
|
| 94 |
+
if entity.type == "text_link":
|
| 95 |
+
youtube_dl_url = entity.url
|
| 96 |
+
elif entity.type == "url":
|
| 97 |
+
o = entity.offset
|
| 98 |
+
l = entity.length
|
| 99 |
+
youtube_dl_url = youtube_dl_url[o:o + l]
|
| 100 |
+
await bot.edit_message_text(
|
| 101 |
+
text=Translation.DOWNLOAD_START,
|
| 102 |
+
chat_id=update.message.chat.id,
|
| 103 |
+
message_id=update.message.message_id
|
| 104 |
+
)
|
| 105 |
+
user = await bot.get_me()
|
| 106 |
+
mention = user["mention"]
|
| 107 |
+
description = Translation.CUSTOM_CAPTION_UL_FILE.format(mention)
|
| 108 |
+
if "fulltitle" in response_json:
|
| 109 |
+
description = response_json["fulltitle"][0:1021]
|
| 110 |
+
# escape Markdown and special characters
|
| 111 |
+
tmp_directory_for_each_user = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id)
|
| 112 |
+
if not os.path.isdir(tmp_directory_for_each_user):
|
| 113 |
+
os.makedirs(tmp_directory_for_each_user)
|
| 114 |
+
download_directory = tmp_directory_for_each_user + "/" + custom_file_name
|
| 115 |
+
command_to_exec = []
|
| 116 |
+
if tg_send_type == "audio":
|
| 117 |
+
command_to_exec = [
|
| 118 |
+
"yt-dlp",
|
| 119 |
+
"-c",
|
| 120 |
+
"--max-filesize", str(Config.TG_MAX_FILE_SIZE),
|
| 121 |
+
"--prefer-ffmpeg",
|
| 122 |
+
"--extract-audio",
|
| 123 |
+
"--audio-format", youtube_dl_ext,
|
| 124 |
+
"--audio-quality", youtube_dl_format,
|
| 125 |
+
youtube_dl_url,
|
| 126 |
+
"-o", download_directory
|
| 127 |
+
]
|
| 128 |
+
else:
|
| 129 |
+
# command_to_exec = ["youtube-dl", "-f", youtube_dl_format, "--hls-prefer-ffmpeg", "--recode-video", "mp4", "-k", youtube_dl_url, "-o", download_directory]
|
| 130 |
+
minus_f_format = youtube_dl_format
|
| 131 |
+
if "youtu" in youtube_dl_url:
|
| 132 |
+
minus_f_format = youtube_dl_format + "+bestaudio"
|
| 133 |
+
command_to_exec = [
|
| 134 |
+
"yt-dlp",
|
| 135 |
+
"-c",
|
| 136 |
+
"--max-filesize", str(Config.TG_MAX_FILE_SIZE),
|
| 137 |
+
"--embed-subs",
|
| 138 |
+
"-f", minus_f_format,
|
| 139 |
+
"--hls-prefer-ffmpeg", youtube_dl_url,
|
| 140 |
+
"-o", download_directory
|
| 141 |
+
]
|
| 142 |
+
if Config.HTTP_PROXY != "":
|
| 143 |
+
command_to_exec.append("--proxy")
|
| 144 |
+
command_to_exec.append(Config.HTTP_PROXY)
|
| 145 |
+
if youtube_dl_username is not None:
|
| 146 |
+
command_to_exec.append("--username")
|
| 147 |
+
command_to_exec.append(youtube_dl_username)
|
| 148 |
+
if youtube_dl_password is not None:
|
| 149 |
+
command_to_exec.append("--password")
|
| 150 |
+
command_to_exec.append(youtube_dl_password)
|
| 151 |
+
command_to_exec.append("--no-warnings")
|
| 152 |
+
# command_to_exec.append("--quiet")
|
| 153 |
+
logger.info(command_to_exec)
|
| 154 |
+
start = datetime.now()
|
| 155 |
+
process = await asyncio.create_subprocess_exec(
|
| 156 |
+
*command_to_exec,
|
| 157 |
+
# stdout must a pipe to be accessible as process.stdout
|
| 158 |
+
stdout=asyncio.subprocess.PIPE,
|
| 159 |
+
stderr=asyncio.subprocess.PIPE,
|
| 160 |
+
)
|
| 161 |
+
# Wait for the subprocess to finish
|
| 162 |
+
stdout, stderr = await process.communicate()
|
| 163 |
+
e_response = stderr.decode().strip()
|
| 164 |
+
t_response = stdout.decode().strip()
|
| 165 |
+
logger.info(e_response)
|
| 166 |
+
logger.info(t_response)
|
| 167 |
+
ad_string_to_replace = "please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output."
|
| 168 |
+
if e_response and ad_string_to_replace in e_response:
|
| 169 |
+
error_message = e_response.replace(ad_string_to_replace, "")
|
| 170 |
+
await bot.edit_message_text(
|
| 171 |
+
chat_id=update.message.chat.id,
|
| 172 |
+
message_id=update.message.message_id,
|
| 173 |
+
text=error_message
|
| 174 |
+
)
|
| 175 |
+
return False
|
| 176 |
+
if t_response:
|
| 177 |
+
# logger.info(t_response)
|
| 178 |
+
os.remove(save_ytdl_json_path)
|
| 179 |
+
end_one = datetime.now()
|
| 180 |
+
time_taken_for_download = (end_one -start).seconds
|
| 181 |
+
file_size = Config.TG_MAX_FILE_SIZE + 1
|
| 182 |
+
try:
|
| 183 |
+
file_size = os.stat(download_directory).st_size
|
| 184 |
+
except FileNotFoundError as exc:
|
| 185 |
+
download_directory = os.path.splitext(download_directory)[0] + "." + "mkv"
|
| 186 |
+
# https://stackoverflow.com/a/678242/4723940
|
| 187 |
+
file_size = os.stat(download_directory).st_size
|
| 188 |
+
if file_size > Config.TG_MAX_FILE_SIZE:
|
| 189 |
+
await bot.edit_message_text(
|
| 190 |
+
chat_id=update.message.chat.id,
|
| 191 |
+
text=Translation.RCHD_TG_API_LIMIT.format(time_taken_for_download, humanbytes(file_size)),
|
| 192 |
+
message_id=update.message.message_id
|
| 193 |
+
)
|
| 194 |
+
else:
|
| 195 |
+
is_w_f = False
|
| 196 |
+
images = await generate_screen_shots(
|
| 197 |
+
download_directory,
|
| 198 |
+
tmp_directory_for_each_user,
|
| 199 |
+
is_w_f,
|
| 200 |
+
Config.DEF_WATER_MARK_FILE,
|
| 201 |
+
300,
|
| 202 |
+
9
|
| 203 |
+
)
|
| 204 |
+
logger.info(images)
|
| 205 |
+
await bot.edit_message_text(
|
| 206 |
+
text=Translation.UPLOAD_START,
|
| 207 |
+
chat_id=update.message.chat.id,
|
| 208 |
+
message_id=update.message.message_id
|
| 209 |
+
)
|
| 210 |
+
# get the correct width, height, and duration for videos greater than 10MB
|
| 211 |
+
# ref: message from @BotSupport
|
| 212 |
+
width = 0
|
| 213 |
+
height = 0
|
| 214 |
+
duration = 0
|
| 215 |
+
if tg_send_type != "file":
|
| 216 |
+
metadata = extractMetadata(createParser(download_directory))
|
| 217 |
+
if metadata is not None:
|
| 218 |
+
if metadata.has("duration"):
|
| 219 |
+
duration = metadata.get('duration').seconds
|
| 220 |
+
# get the correct width, height, and duration for videos greater than 10MB
|
| 221 |
+
if os.path.exists(thumb_image_path):
|
| 222 |
+
width = 0
|
| 223 |
+
height = 0
|
| 224 |
+
metadata = extractMetadata(createParser(thumb_image_path))
|
| 225 |
+
if metadata.has("width"):
|
| 226 |
+
width = metadata.get("width")
|
| 227 |
+
if metadata.has("height"):
|
| 228 |
+
height = metadata.get("height")
|
| 229 |
+
if tg_send_type == "vm":
|
| 230 |
+
height = width
|
| 231 |
+
# resize image
|
| 232 |
+
# ref: https://t.me/PyrogramChat/44663
|
| 233 |
+
# https://stackoverflow.com/a/21669827/4723940
|
| 234 |
+
Image.open(thumb_image_path).convert(
|
| 235 |
+
"RGB").save(thumb_image_path)
|
| 236 |
+
img = Image.open(thumb_image_path)
|
| 237 |
+
# https://stackoverflow.com/a/37631799/4723940
|
| 238 |
+
# img.thumbnail((90, 90))
|
| 239 |
+
if tg_send_type == "file":
|
| 240 |
+
img.resize((320, height))
|
| 241 |
+
else:
|
| 242 |
+
img.resize((90, height))
|
| 243 |
+
img.save(thumb_image_path, "JPEG")
|
| 244 |
+
# https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails
|
| 245 |
+
|
| 246 |
+
else:
|
| 247 |
+
thumb_image_path = None
|
| 248 |
+
start_time = time.time()
|
| 249 |
+
# try to upload file
|
| 250 |
+
if tg_send_type == "audio":
|
| 251 |
+
await bot.send_audio(
|
| 252 |
+
chat_id=update.message.chat.id,
|
| 253 |
+
audio=download_directory,
|
| 254 |
+
caption=description,
|
| 255 |
+
parse_mode="HTML",
|
| 256 |
+
duration=duration,
|
| 257 |
+
# performer=response_json["uploader"],
|
| 258 |
+
# title=response_json["title"],
|
| 259 |
+
# reply_markup=reply_markup,
|
| 260 |
+
thumb=thumb_image_path,
|
| 261 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 262 |
+
progress=progress_for_pyrogram,
|
| 263 |
+
progress_args=(
|
| 264 |
+
Translation.UPLOAD_START,
|
| 265 |
+
update.message,
|
| 266 |
+
start_time
|
| 267 |
+
)
|
| 268 |
+
)
|
| 269 |
+
elif tg_send_type == "file":
|
| 270 |
+
await bot.send_document(
|
| 271 |
+
chat_id=update.message.chat.id,
|
| 272 |
+
document=download_directory,
|
| 273 |
+
thumb=thumb_image_path,
|
| 274 |
+
caption=description,
|
| 275 |
+
parse_mode="HTML",
|
| 276 |
+
# reply_markup=reply_markup,
|
| 277 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 278 |
+
progress=progress_for_pyrogram,
|
| 279 |
+
progress_args=(
|
| 280 |
+
Translation.UPLOAD_START,
|
| 281 |
+
update.message,
|
| 282 |
+
start_time
|
| 283 |
+
)
|
| 284 |
+
)
|
| 285 |
+
elif tg_send_type == "vm":
|
| 286 |
+
await bot.send_video_note(
|
| 287 |
+
chat_id=update.message.chat.id,
|
| 288 |
+
video_note=download_directory,
|
| 289 |
+
duration=duration,
|
| 290 |
+
length=width,
|
| 291 |
+
thumb=thumb_image_path,
|
| 292 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 293 |
+
progress=progress_for_pyrogram,
|
| 294 |
+
progress_args=(
|
| 295 |
+
Translation.UPLOAD_START,
|
| 296 |
+
update.message,
|
| 297 |
+
start_time
|
| 298 |
+
)
|
| 299 |
+
)
|
| 300 |
+
elif tg_send_type == "video":
|
| 301 |
+
await bot.send_video(
|
| 302 |
+
chat_id=update.message.chat.id,
|
| 303 |
+
video=download_directory,
|
| 304 |
+
caption=description,
|
| 305 |
+
parse_mode="HTML",
|
| 306 |
+
duration=duration,
|
| 307 |
+
width=width,
|
| 308 |
+
height=height,
|
| 309 |
+
supports_streaming=True,
|
| 310 |
+
# reply_markup=reply_markup,
|
| 311 |
+
thumb=thumb_image_path,
|
| 312 |
+
reply_to_message_id=update.message.reply_to_message.message_id,
|
| 313 |
+
progress=progress_for_pyrogram,
|
| 314 |
+
progress_args=(
|
| 315 |
+
Translation.UPLOAD_START,
|
| 316 |
+
update.message,
|
| 317 |
+
start_time
|
| 318 |
+
)
|
| 319 |
+
)
|
| 320 |
+
else:
|
| 321 |
+
logger.info("Did this happen? :\\")
|
| 322 |
+
end_two = datetime.now()
|
| 323 |
+
time_taken_for_upload = (end_two - end_one).seconds
|
| 324 |
+
#
|
| 325 |
+
media_album_p = []
|
| 326 |
+
if images is not None:
|
| 327 |
+
i = 0
|
| 328 |
+
caption = "© @xTeamBots"
|
| 329 |
+
if is_w_f:
|
| 330 |
+
caption = "@xurluploaderbot"
|
| 331 |
+
for image in images:
|
| 332 |
+
if os.path.exists(str(image)):
|
| 333 |
+
if i == 0:
|
| 334 |
+
media_album_p.append(
|
| 335 |
+
InputMediaPhoto(
|
| 336 |
+
media=image,
|
| 337 |
+
caption=caption,
|
| 338 |
+
parse_mode="html"
|
| 339 |
+
)
|
| 340 |
+
)
|
| 341 |
+
else:
|
| 342 |
+
media_album_p.append(
|
| 343 |
+
InputMediaPhoto(
|
| 344 |
+
media=image
|
| 345 |
+
)
|
| 346 |
+
)
|
| 347 |
+
i = i + 1
|
| 348 |
+
await bot.send_media_group(
|
| 349 |
+
chat_id=update.message.chat.id,
|
| 350 |
+
disable_notification=True,
|
| 351 |
+
reply_to_message_id=update.message.message_id,
|
| 352 |
+
media=media_album_p
|
| 353 |
+
)
|
| 354 |
+
#
|
| 355 |
+
try:
|
| 356 |
+
shutil.rmtree(tmp_directory_for_each_user)
|
| 357 |
+
os.remove(thumb_image_path)
|
| 358 |
+
except:
|
| 359 |
+
pass
|
| 360 |
+
await bot.edit_message_text(
|
| 361 |
+
text=Translation.AFTER_SUCCESSFUL_UPLOAD_MSG_WITH_TS.format(time_taken_for_download, time_taken_for_upload),
|
| 362 |
+
chat_id=update.message.chat.id,
|
| 363 |
+
message_id=update.message.message_id,
|
| 364 |
+
disable_web_page_preview=True
|
| 365 |
+
)
|
plugins/youtube_dl_echo.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# (c) Shrimadhav U K | X-Noid
|
| 4 |
+
|
| 5 |
+
# the logging things
|
| 6 |
+
import logging
|
| 7 |
+
logging.basicConfig(level=logging.DEBUG,
|
| 8 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
import lk21, urllib.parse, filetype, shutil, time, tldextract, asyncio, json, math, os, requests
|
| 11 |
+
from PIL import Image
|
| 12 |
+
# the secret configuration specific things
|
| 13 |
+
if bool(os.environ.get("WEBHOOK", False)):
|
| 14 |
+
from sample_config import Config
|
| 15 |
+
else:
|
| 16 |
+
from config import Config
|
| 17 |
+
|
| 18 |
+
# the Strings used for this "thing"
|
| 19 |
+
from translation import Translation
|
| 20 |
+
|
| 21 |
+
import pyrogram
|
| 22 |
+
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
| 23 |
+
from helper_funcs.display_progress import humanbytes
|
| 24 |
+
from helper_funcs.help_uploadbot import DownLoadFile
|
| 25 |
+
from helper_funcs.display_progress import progress_for_pyrogram
|
| 26 |
+
from hachoir.metadata import extractMetadata
|
| 27 |
+
from hachoir.parser import createParser
|
| 28 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
| 29 |
+
from pyrogram.errors import UserNotParticipant
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@pyrogram.Client.on_message(pyrogram.filters.regex(pattern=".*http.*"))
|
| 33 |
+
async def echo(bot, update):
|
| 34 |
+
if update.from_user.id in Config.AUTH_USERS:
|
| 35 |
+
logger.info(update.from_user)
|
| 36 |
+
url = update.text
|
| 37 |
+
youtube_dl_username = None
|
| 38 |
+
youtube_dl_password = None
|
| 39 |
+
file_name = None
|
| 40 |
+
folder = f'./lk21/{update.from_user.id}/'
|
| 41 |
+
bypass = ['zippyshare', 'hxfile', 'mediafire', 'anonfiles', 'antfiles']
|
| 42 |
+
ext = tldextract.extract(url)
|
| 43 |
+
if ext.domain in bypass:
|
| 44 |
+
pablo = await update.reply_text('LK21 link detected')
|
| 45 |
+
time.sleep(2.5)
|
| 46 |
+
if os.path.isdir(folder):
|
| 47 |
+
await update.reply_text("Don't spam, wait till your previous task done.")
|
| 48 |
+
await pablo.delete()
|
| 49 |
+
return
|
| 50 |
+
os.makedirs(folder)
|
| 51 |
+
await pablo.edit_text('Downloading...')
|
| 52 |
+
bypasser = lk21.Bypass()
|
| 53 |
+
xurl = bypasser.bypass_url(url)
|
| 54 |
+
if ' | ' in url:
|
| 55 |
+
url_parts = url.split(' | ')
|
| 56 |
+
url = url_parts[0]
|
| 57 |
+
file_name = url_parts[1]
|
| 58 |
+
else:
|
| 59 |
+
if xurl.find('/'):
|
| 60 |
+
urlname = xurl.rsplit('/', 1)[1]
|
| 61 |
+
file_name = urllib.parse.unquote(urlname)
|
| 62 |
+
if '+' in file_name:
|
| 63 |
+
file_name = file_name.replace('+', ' ')
|
| 64 |
+
dldir = f'{folder}{file_name}'
|
| 65 |
+
r = requests.get(xurl, allow_redirects=True)
|
| 66 |
+
open(dldir, 'wb').write(r.content)
|
| 67 |
+
try:
|
| 68 |
+
file = filetype.guess(dldir)
|
| 69 |
+
xfiletype = file.mime
|
| 70 |
+
except AttributeError:
|
| 71 |
+
xfiletype = file_name
|
| 72 |
+
if xfiletype in ['video/mp4', 'video/x-matroska', 'video/webm', 'audio/mpeg']:
|
| 73 |
+
metadata = extractMetadata(createParser(dldir))
|
| 74 |
+
if metadata is not None:
|
| 75 |
+
if metadata.has("duration"):
|
| 76 |
+
duration = metadata.get('duration').seconds
|
| 77 |
+
await pablo.edit_text('Uploading...')
|
| 78 |
+
start_time = time.time()
|
| 79 |
+
if xfiletype in ['video/mp4', 'video/x-matroska', 'video/webm']:
|
| 80 |
+
await bot.send_video(
|
| 81 |
+
chat_id=update.chat.id,
|
| 82 |
+
video=dldir,
|
| 83 |
+
caption=file_name,
|
| 84 |
+
duration=duration,
|
| 85 |
+
reply_to_message_id=update.message_id,
|
| 86 |
+
progress=progress_for_pyrogram,
|
| 87 |
+
progress_args=(
|
| 88 |
+
Translation.UPLOAD_START,
|
| 89 |
+
pablo,
|
| 90 |
+
start_time
|
| 91 |
+
)
|
| 92 |
+
)
|
| 93 |
+
elif xfiletype == 'audio/mpeg':
|
| 94 |
+
await bot.send_audio(
|
| 95 |
+
chat_id=update.chat.id,
|
| 96 |
+
audio=dldir,
|
| 97 |
+
caption=file_name,
|
| 98 |
+
duration=duration,
|
| 99 |
+
reply_to_message_id=update.message_id,
|
| 100 |
+
progress=progress_for_pyrogram,
|
| 101 |
+
progress_args=(
|
| 102 |
+
Translation.UPLOAD_START,
|
| 103 |
+
pablo,
|
| 104 |
+
start_time
|
| 105 |
+
)
|
| 106 |
+
)
|
| 107 |
+
else:
|
| 108 |
+
await bot.send_document(
|
| 109 |
+
chat_id=update.chat.id,
|
| 110 |
+
document=dldir,
|
| 111 |
+
caption=file_name,
|
| 112 |
+
reply_to_message_id=update.message_id,
|
| 113 |
+
progress=progress_for_pyrogram,
|
| 114 |
+
progress_args=(
|
| 115 |
+
Translation.UPLOAD_START,
|
| 116 |
+
pablo,
|
| 117 |
+
start_time
|
| 118 |
+
)
|
| 119 |
+
)
|
| 120 |
+
await pablo.delete()
|
| 121 |
+
shutil.rmtree(folder)
|
| 122 |
+
return
|
| 123 |
+
if "|" in url:
|
| 124 |
+
url_parts = url.split("|")
|
| 125 |
+
if len(url_parts) == 2:
|
| 126 |
+
url = url_parts[0]
|
| 127 |
+
file_name = url_parts[1]
|
| 128 |
+
elif len(url_parts) == 4:
|
| 129 |
+
url = url_parts[0]
|
| 130 |
+
file_name = url_parts[1]
|
| 131 |
+
youtube_dl_username = url_parts[2]
|
| 132 |
+
youtube_dl_password = url_parts[3]
|
| 133 |
+
else:
|
| 134 |
+
for entity in update.entities:
|
| 135 |
+
if entity.type == "text_link":
|
| 136 |
+
url = entity.url
|
| 137 |
+
elif entity.type == "url":
|
| 138 |
+
o = entity.offset
|
| 139 |
+
l = entity.length
|
| 140 |
+
url = url[o:o + l]
|
| 141 |
+
if url is not None:
|
| 142 |
+
url = url.strip()
|
| 143 |
+
if file_name is not None:
|
| 144 |
+
file_name = file_name.strip()
|
| 145 |
+
# https://stackoverflow.com/a/761825/4723940
|
| 146 |
+
if youtube_dl_username is not None:
|
| 147 |
+
youtube_dl_username = youtube_dl_username.strip()
|
| 148 |
+
if youtube_dl_password is not None:
|
| 149 |
+
youtube_dl_password = youtube_dl_password.strip()
|
| 150 |
+
logger.info(url)
|
| 151 |
+
logger.info(file_name)
|
| 152 |
+
else:
|
| 153 |
+
for entity in update.entities:
|
| 154 |
+
if entity.type == "text_link":
|
| 155 |
+
url = entity.url
|
| 156 |
+
elif entity.type == "url":
|
| 157 |
+
o = entity.offset
|
| 158 |
+
l = entity.length
|
| 159 |
+
url = url[o:o + l]
|
| 160 |
+
if Config.HTTP_PROXY != "":
|
| 161 |
+
command_to_exec = [
|
| 162 |
+
"yt-dlp",
|
| 163 |
+
"--no-warnings",
|
| 164 |
+
"--youtube-skip-dash-manifest",
|
| 165 |
+
"-j",
|
| 166 |
+
url,
|
| 167 |
+
"--proxy", Config.HTTP_PROXY
|
| 168 |
+
]
|
| 169 |
+
else:
|
| 170 |
+
command_to_exec = [
|
| 171 |
+
"yt-dlp",
|
| 172 |
+
"--no-warnings",
|
| 173 |
+
"--youtube-skip-dash-manifest",
|
| 174 |
+
"-j",
|
| 175 |
+
url
|
| 176 |
+
]
|
| 177 |
+
if youtube_dl_username is not None:
|
| 178 |
+
command_to_exec.append("--username")
|
| 179 |
+
command_to_exec.append(youtube_dl_username)
|
| 180 |
+
if youtube_dl_password is not None:
|
| 181 |
+
command_to_exec.append("--password")
|
| 182 |
+
command_to_exec.append(youtube_dl_password)
|
| 183 |
+
# logger.info(command_to_exec)
|
| 184 |
+
process = await asyncio.create_subprocess_exec(
|
| 185 |
+
*command_to_exec,
|
| 186 |
+
# stdout must a pipe to be accessible as process.stdout
|
| 187 |
+
stdout=asyncio.subprocess.PIPE,
|
| 188 |
+
stderr=asyncio.subprocess.PIPE,
|
| 189 |
+
)
|
| 190 |
+
# Wait for the subprocess to finish
|
| 191 |
+
stdout, stderr = await process.communicate()
|
| 192 |
+
e_response = stderr.decode().strip()
|
| 193 |
+
# logger.info(e_response)
|
| 194 |
+
t_response = stdout.decode().strip()
|
| 195 |
+
# logger.info(t_response)
|
| 196 |
+
# https://github.com/rg3/youtube-dl/issues/2630#issuecomment-38635239
|
| 197 |
+
if e_response and "nonnumeric port" not in e_response:
|
| 198 |
+
# logger.warn("Status : FAIL", exc.returncode, exc.output)
|
| 199 |
+
error_message = e_response.replace("please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.", "")
|
| 200 |
+
if "This video is only available for registered users." in error_message:
|
| 201 |
+
error_message += Translation.SET_CUSTOM_USERNAME_PASSWORD
|
| 202 |
+
await bot.send_message(
|
| 203 |
+
chat_id=update.chat.id,
|
| 204 |
+
text=Translation.NO_VOID_FORMAT_FOUND.format(str(error_message)),
|
| 205 |
+
reply_to_message_id=update.message_id,
|
| 206 |
+
parse_mode="html",
|
| 207 |
+
disable_web_page_preview=True
|
| 208 |
+
)
|
| 209 |
+
return False
|
| 210 |
+
if t_response:
|
| 211 |
+
# logger.info(t_response)
|
| 212 |
+
x_reponse = t_response
|
| 213 |
+
if "\n" in x_reponse:
|
| 214 |
+
x_reponse, _ = x_reponse.split("\n")
|
| 215 |
+
response_json = json.loads(x_reponse)
|
| 216 |
+
save_ytdl_json_path = Config.DOWNLOAD_LOCATION + \
|
| 217 |
+
"/" + str(update.from_user.id) + ".json"
|
| 218 |
+
with open(save_ytdl_json_path, "w", encoding="utf8") as outfile:
|
| 219 |
+
json.dump(response_json, outfile, ensure_ascii=False)
|
| 220 |
+
# logger.info(response_json)
|
| 221 |
+
inline_keyboard = []
|
| 222 |
+
duration = None
|
| 223 |
+
if "duration" in response_json:
|
| 224 |
+
duration = response_json["duration"]
|
| 225 |
+
if "formats" in response_json:
|
| 226 |
+
for formats in response_json["formats"]:
|
| 227 |
+
format_id = formats.get("format_id")
|
| 228 |
+
format_string = formats.get("format_note")
|
| 229 |
+
if format_string is None:
|
| 230 |
+
format_string = formats.get("format")
|
| 231 |
+
format_ext = formats.get("ext")
|
| 232 |
+
approx_file_size = ""
|
| 233 |
+
if "filesize" in formats:
|
| 234 |
+
approx_file_size = humanbytes(formats["filesize"])
|
| 235 |
+
cb_string_video = "{}|{}|{}".format(
|
| 236 |
+
"video", format_id, format_ext)
|
| 237 |
+
cb_string_file = "{}|{}|{}".format(
|
| 238 |
+
"file", format_id, format_ext)
|
| 239 |
+
if format_string is not None and not "audio only" in format_string:
|
| 240 |
+
ikeyboard = [
|
| 241 |
+
InlineKeyboardButton(
|
| 242 |
+
"S " + format_string + " video " + approx_file_size + " ",
|
| 243 |
+
callback_data=(cb_string_video).encode("UTF-8")
|
| 244 |
+
),
|
| 245 |
+
InlineKeyboardButton(
|
| 246 |
+
"D " + format_ext + " " + approx_file_size + " ",
|
| 247 |
+
callback_data=(cb_string_file).encode("UTF-8")
|
| 248 |
+
)
|
| 249 |
+
]
|
| 250 |
+
"""if duration is not None:
|
| 251 |
+
cb_string_video_message = "{}|{}|{}".format(
|
| 252 |
+
"vm", format_id, format_ext)
|
| 253 |
+
ikeyboard.append(
|
| 254 |
+
InlineKeyboardButton(
|
| 255 |
+
"VM",
|
| 256 |
+
callback_data=(
|
| 257 |
+
cb_string_video_message).encode("UTF-8")
|
| 258 |
+
)
|
| 259 |
+
)"""
|
| 260 |
+
else:
|
| 261 |
+
# special weird case :\
|
| 262 |
+
ikeyboard = [
|
| 263 |
+
InlineKeyboardButton(
|
| 264 |
+
"SVideo [" +
|
| 265 |
+
"] ( " +
|
| 266 |
+
approx_file_size + " )",
|
| 267 |
+
callback_data=(cb_string_video).encode("UTF-8")
|
| 268 |
+
),
|
| 269 |
+
InlineKeyboardButton(
|
| 270 |
+
"DFile [" +
|
| 271 |
+
"] ( " +
|
| 272 |
+
approx_file_size + " )",
|
| 273 |
+
callback_data=(cb_string_file).encode("UTF-8")
|
| 274 |
+
)
|
| 275 |
+
]
|
| 276 |
+
inline_keyboard.append(ikeyboard)
|
| 277 |
+
if duration is not None:
|
| 278 |
+
cb_string_64 = "{}|{}|{}".format("audio", "64k", "mp3")
|
| 279 |
+
cb_string_128 = "{}|{}|{}".format("audio", "128k", "mp3")
|
| 280 |
+
cb_string = "{}|{}|{}".format("audio", "320k", "mp3")
|
| 281 |
+
inline_keyboard.append([
|
| 282 |
+
InlineKeyboardButton(
|
| 283 |
+
"MP3 " + "(" + "64 kbps" + ")", callback_data=cb_string_64.encode("UTF-8")),
|
| 284 |
+
InlineKeyboardButton(
|
| 285 |
+
"MP3 " + "(" + "128 kbps" + ")", callback_data=cb_string_128.encode("UTF-8"))
|
| 286 |
+
])
|
| 287 |
+
inline_keyboard.append([
|
| 288 |
+
InlineKeyboardButton(
|
| 289 |
+
"MP3 " + "(" + "320 kbps" + ")", callback_data=cb_string.encode("UTF-8"))
|
| 290 |
+
])
|
| 291 |
+
else:
|
| 292 |
+
format_id = response_json["format_id"]
|
| 293 |
+
format_ext = response_json["ext"]
|
| 294 |
+
cb_string_file = "{}|{}|{}".format(
|
| 295 |
+
"file", format_id, format_ext)
|
| 296 |
+
cb_string_video = "{}|{}|{}".format(
|
| 297 |
+
"video", format_id, format_ext)
|
| 298 |
+
inline_keyboard.append([
|
| 299 |
+
InlineKeyboardButton(
|
| 300 |
+
"SVideo",
|
| 301 |
+
callback_data=(cb_string_video).encode("UTF-8")
|
| 302 |
+
),
|
| 303 |
+
InlineKeyboardButton(
|
| 304 |
+
"DFile",
|
| 305 |
+
callback_data=(cb_string_file).encode("UTF-8")
|
| 306 |
+
)
|
| 307 |
+
])
|
| 308 |
+
cb_string_file = "{}={}={}".format(
|
| 309 |
+
"file", format_id, format_ext)
|
| 310 |
+
cb_string_video = "{}={}={}".format(
|
| 311 |
+
"video", format_id, format_ext)
|
| 312 |
+
inline_keyboard.append([
|
| 313 |
+
InlineKeyboardButton(
|
| 314 |
+
"video",
|
| 315 |
+
callback_data=(cb_string_video).encode("UTF-8")
|
| 316 |
+
),
|
| 317 |
+
InlineKeyboardButton(
|
| 318 |
+
"file",
|
| 319 |
+
callback_data=(cb_string_file).encode("UTF-8")
|
| 320 |
+
)
|
| 321 |
+
])
|
| 322 |
+
reply_markup = InlineKeyboardMarkup(inline_keyboard)
|
| 323 |
+
# logger.info(reply_markup)
|
| 324 |
+
thumbnail = Config.DEF_THUMB_NAIL_VID_S
|
| 325 |
+
thumbnail_image = Config.DEF_THUMB_NAIL_VID_S
|
| 326 |
+
if "thumbnail" in response_json:
|
| 327 |
+
if response_json["thumbnail"] is not None:
|
| 328 |
+
thumbnail = response_json["thumbnail"]
|
| 329 |
+
thumbnail_image = response_json["thumbnail"]
|
| 330 |
+
thumb_image_path = DownLoadFile(
|
| 331 |
+
thumbnail_image,
|
| 332 |
+
Config.DOWNLOAD_LOCATION + "/" +
|
| 333 |
+
str(update.from_user.id) + ".webp",
|
| 334 |
+
Config.CHUNK_SIZE,
|
| 335 |
+
None, # bot,
|
| 336 |
+
Translation.DOWNLOAD_START,
|
| 337 |
+
update.message_id,
|
| 338 |
+
update.chat.id
|
| 339 |
+
)
|
| 340 |
+
if os.path.exists(thumb_image_path):
|
| 341 |
+
im = Image.open(thumb_image_path).convert("RGB")
|
| 342 |
+
im.save(thumb_image_path.replace(".webp", ".jpg"), "jpeg")
|
| 343 |
+
else:
|
| 344 |
+
thumb_image_path = None
|
| 345 |
+
await bot.send_message(
|
| 346 |
+
chat_id=update.chat.id,
|
| 347 |
+
text=Translation.FORMAT_SELECTION.format(thumbnail) + "\n" + Translation.SET_CUSTOM_USERNAME_PASSWORD,
|
| 348 |
+
reply_markup=reply_markup,
|
| 349 |
+
parse_mode="html",
|
| 350 |
+
reply_to_message_id=update.message_id
|
| 351 |
+
)
|
| 352 |
+
else:
|
| 353 |
+
# fallback for nonnumeric port a.k.a seedbox.io
|
| 354 |
+
inline_keyboard = []
|
| 355 |
+
cb_string_file = "{}={}={}".format(
|
| 356 |
+
"file", "LFO", "NONE")
|
| 357 |
+
cb_string_video = "{}={}={}".format(
|
| 358 |
+
"video", "OFL", "ENON")
|
| 359 |
+
inline_keyboard.append([
|
| 360 |
+
InlineKeyboardButton(
|
| 361 |
+
"SVideo",
|
| 362 |
+
callback_data=(cb_string_video).encode("UTF-8")
|
| 363 |
+
),
|
| 364 |
+
InlineKeyboardButton(
|
| 365 |
+
"DFile",
|
| 366 |
+
callback_data=(cb_string_file).encode("UTF-8")
|
| 367 |
+
)
|
| 368 |
+
])
|
| 369 |
+
reply_markup = InlineKeyboardMarkup(inline_keyboard)
|
| 370 |
+
await bot.send_message(
|
| 371 |
+
chat_id=update.chat.id,
|
| 372 |
+
text=Translation.FORMAT_SELECTION.format(""),
|
| 373 |
+
reply_markup=reply_markup,
|
| 374 |
+
parse_mode="html",
|
| 375 |
+
reply_to_message_id=update.message_id
|
| 376 |
+
)
|