Skip to content

Commit

Permalink
custom thumbunali support v2.0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kalanakt committed Aug 25, 2022
1 parent a481715 commit f8a1266
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 14 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
| -------------------- | --------------------- | ------------------------------------------------------------------------------ |
| v 1.0.0 | Stable | Upload all ytdl links, direct links |
| v 2.0.0 | Stable | Upload all ytdl links, direct links, google drive etc. (Speed is much higher than version 1) |
| - | - | - |
| v 2.0.1 | stable | custom thumbunali support, fixed youtube download |

<h3>To do</h3>

* [x] deploy to vps setup
* [ ] brodcast message to users
* [ ] users counter
* [ ] custom thumbunali support
* [x] custom thumbunali support
* [ ] custom caption support
* [ ] mega.nz support
* [ ] pdisk support

<h3>Deploy</h3>

Expand Down Expand Up @@ -88,6 +88,7 @@ python3 bot.py
<p>Detailed changes for each release are documented in the <a href="https://github.com/kalanakt/All-Url-Uploader/commits/main" target="_blank" rel="noopener noreferrer">main commits</a></p>
<code>Full Changelog: <a href="https://github.com/kalanakt/All-Url-Uploader/commits/v1.0.0">v1.0.0</a></code>
<code>Full Changelog: <a href="https://github.com/kalanakt/All-Url-Uploader/compare/v1.0.0...v2.0.0">v1.0.0...v2.0.0</a></code>
<code>Full Changelog: <a href="https://github.com/kalanakt/All-Url-Uploader/compare/v2.0.0...v2.0.1">v2.0.0...v2.0.1</a></code>

<h3>Stay In Touch</h3>

Expand Down
10 changes: 10 additions & 0 deletions Uploader/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ async def youtube_dl_call_back(bot, update):
download_directory)[0] + "." + "mkv"
# https://stackoverflow.com/a/678242/4723940
file_size = os.stat(download_directory).st_size

if download_location := f"{Config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg":
thumb = download_location
else:
thumb = None

if ((file_size > Config.TG_MAX_FILE_SIZE)):
await update.message.edit_caption(

Expand All @@ -223,6 +229,7 @@ async def youtube_dl_call_back(bot, update):
caption=description,
# parse_mode=enums.ParseMode.HTML,
# reply_to_message_id=update.id,
thumb=thumb,
progress=progress_for_pyrogram,
progress_args=(
Translation.UPLOAD_START,
Expand All @@ -240,6 +247,7 @@ async def youtube_dl_call_back(bot, update):
width=width,
height=height,
supports_streaming=True,
thumb=thumb,
# reply_to_message_id=update.id,
progress=progress_for_pyrogram,
progress_args=(
Expand All @@ -255,6 +263,7 @@ async def youtube_dl_call_back(bot, update):
audio=download_directory,
caption=description,
duration=duration,
thumb=thumb,
# reply_to_message_id=update.id,
progress=progress_for_pyrogram,
progress_args=(
Expand All @@ -270,6 +279,7 @@ async def youtube_dl_call_back(bot, update):
video_note=download_directory,
duration=duration,
length=width,
thumb=thumb,
# reply_to_message_id=update.id,
progress=progress_for_pyrogram,
progress_args=(
Expand Down
12 changes: 8 additions & 4 deletions Uploader/dl_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ async def ddl_call_back(bot, update): # sourcery skip: low-code-quality
return False
if os.path.exists(download_directory):
save_ytdl_json_path = f"{Config.DOWNLOAD_LOCATION}/{str(update.message.chat.id)}.json"
if download_location := f"{Config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg":
thumb = download_location
else:
thumb = None

if os.path.exists(save_ytdl_json_path):
os.remove(save_ytdl_json_path)
Expand All @@ -116,18 +120,18 @@ async def ddl_call_back(bot, update): # sourcery skip: low-code-quality
start_time = time.time()
if tg_send_type == "video":
width, height, duration = await Mdata01(download_directory)
await bot.send_video(chat_id=update.message.chat.id, video=download_directory, caption=description, duration=duration, width=width, height=height, supports_streaming=True, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))
await bot.send_video(chat_id=update.message.chat.id, video=download_directory, thumb=thumb, caption=description, duration=duration, width=width, height=height, supports_streaming=True, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))

elif tg_send_type == "audio":
duration = await Mdata03(download_directory)
await bot.send_audio(chat_id=update.message.chat.id, audio=download_directory, caption=description, duration=duration, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))
await bot.send_audio(chat_id=update.message.chat.id, audio=download_directory, thumb=thumb, caption=description, duration=duration, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))

elif tg_send_type == "vm":
width, duration = await Mdata02(download_directory)
await bot.send_video_note(chat_id=update.message.chat.id, video_note=download_directory, duration=duration, length=width, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))
await bot.send_video_note(chat_id=update.message.chat.id, video_note=download_directory, thumb=thumb, duration=duration, length=width, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))

else:
await bot.send_document(chat_id=update.message.chat.id, document=download_directory, caption=description, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))
await bot.send_document(chat_id=update.message.chat.id, document=download_directory, thumb=thumb, caption=description, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time))

end_two = datetime.now()
try:
Expand Down
56 changes: 56 additions & 0 deletions Uploader/thumbunali.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# MIT License

# Copyright (c) 2022 Hash Minner

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE

import os

from pyrogram import Client, filters

if bool(os.environ.get("WEBHOOK")):
from Uploader.config import Config
else:
from sample_config import Config


@Client.on_message(filters.photo & filters.incoming & filters.private)
async def save_photo(bot, message):
download_location = f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg"
await message.download(file_name=download_location)

await message.reply_text(
text="your custom thumbunali is saved",
quote=True
)


@Client.on_message(filters.command("thumb") & filters.incoming & filters.private)
async def send_photo(bot, message):
if download_location := f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg":
await message.reply_photo(
photo=download_location,
caption="your custom thumbunali",
quote=True
)
else:
await message.reply_text(
text="you don't have set thumbunali yet!. send .jpg img to save as thumbunali.",
quote=True
)
22 changes: 16 additions & 6 deletions Uploader/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
import wget
import asyncio

from opencc import OpenCC
from youtube_dl import YoutubeDL
from pyrogram import Client, filters, enums
from pyrogram.types import Message
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardMarkup, KeyboardButton

if bool(os.environ.get("WEBHOOK")):
from Uploader.config import Config
else:
from sample_config import Config
from functions.help_ytdl import get_file_extension_from_url, get_resolution

from opencc import OpenCC
from youtube_dl import YoutubeDL

YTDL_REGEX = (r"^((?:https?:)?\/\/)")
s2tw = OpenCC('s2tw.json').convert

Expand Down Expand Up @@ -76,12 +78,16 @@ async def send_audio(message: Message, info_dict, audio_file):
audio_file = audio_file_weba
thumbnail_url = info_dict['thumbnail']
thumbnail_file = f"{basename}.{get_file_extension_from_url(thumbnail_url)}"
if download_location := f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg":
thumb = download_location
else:
thumb = thumbnail_file
webpage_url = info_dict['webpage_url']
title = s2tw(info_dict['title'])
caption = f'<b><a href=\"{webpage_url}\">{title}</a></b>'
duration = int(float(info_dict['duration']))
performer = s2tw(info_dict['uploader'])
await message.reply_audio(audio_file, caption=caption, duration=duration, performer=performer, title=title, parse_mode=enums.ParseMode.HTML, thumb=thumbnail_file)
await message.reply_audio(audio_file, caption=caption, duration=duration, performer=performer, title=title, parse_mode=enums.ParseMode.HTML, thumb=thumb)

os.remove(audio_file)
os.remove(thumbnail_file)
Expand Down Expand Up @@ -122,12 +128,16 @@ async def send_video(message: Message, info_dict, video_file):
basename = video_file.rsplit(".", 1)[-2]
thumbnail_url = info_dict['thumbnail']
thumbnail_file = f"{basename}.{get_file_extension_from_url(thumbnail_url)}"
if download_location := f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg":
thumb = download_location
else:
thumb = thumbnail_file
webpage_url = info_dict['webpage_url']
title = s2tw(info_dict['title'])
caption = f'<b><a href=\"{webpage_url}\">{title}</a></b>'
duration = int(float(info_dict['duration']))
width, height = get_resolution(info_dict)
await message.reply_video(video_file, caption=caption, duration=duration, width=width, height=height, parse_mode=enums.ParseMode.HTML, thumb=thumbnail_file)
await message.reply_video(video_file, caption=caption, duration=duration, width=width, height=height, parse_mode=enums.ParseMode.HTML, thumb=thumb)

os.remove(video_file)
os.remove(thumbnail_file)

0 comments on commit f8a1266

Please sign in to comment.