diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..d1f2e667
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,4 @@
+BOT_TOKEN=
+API_ID=
+API_HASH=
+OWNER_ID=
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 4bdcd6bf..e95794e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,6 @@ yarn-error.log*
.env.test.local
.env.production.local
.env
+
+*.session
+*.session-journal
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..26d33521
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/All-Url-Uploader.iml b/.idea/All-Url-Uploader.iml
new file mode 100644
index 00000000..f35a5644
--- /dev/null
+++ b/.idea/All-Url-Uploader.iml
@@ -0,0 +1,15 @@
+
+
+
+
Here is sample edited config.py for deploy to Locally/VPS. copy and past and edit with your variables
-Go To sample_config.py and edit with your veriable
- --# sample config file - -class Config(object): - - # get a token from @BotFather - BOT_TOKEN = "5568340867:AAGuPzlgwqgHtgqmdL7yt12PRLrXFjt98Zg" - - # Get these values from my.telegram.org - API_ID = 12345 - API_HASH = "uPzlgwqgHtgqmdL7yt12PRLrXFj" - - # No need to change - DOWNLOAD_LOCATION = "./DOWNLOADS" - ADL_BOT_RQ = {} - CHUNK_SIZE = 128 - TG_MAX_FILE_SIZE = 4194304000 - HTTP_PROXY = "" - PROCESS_MAX_TIMEOUT = 3700 - - # TG Ids - LOG_CHANNEL = -1001798969594 - OWNER_ID = 1288398723 - - # bot username without @ - BOT_USERNAME = "AdvanceUrlUploaderBot" - - # auth users - AUTH_USERS = [OWNER_ID, 1288398722, 1288398724, 1288398725] -diff --git a/Uploader/button.py b/Uploader/button.py index 80f98a14..9f42d16f 100644 --- a/Uploader/button.py +++ b/Uploader/button.py @@ -25,17 +25,10 @@ import time import shutil import asyncio -import logging -import subprocess - -from pyrogram.types import * from datetime import datetime from Uploader.utitles import * -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config +from config import Config from Uploader.script import Translation from Uploader.functions.ran_text import random_char from Uploader.functions.display_progress import progress_for_pyrogram, humanbytes diff --git a/Uploader/callbacks.py b/Uploader/callbacks.py index 1719c580..c8d2a651 100644 --- a/Uploader/callbacks.py +++ b/Uploader/callbacks.py @@ -20,17 +20,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE -import os -from Uploader.functions.display_progress import progress_for_pyrogram, humanbytes -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config from Uploader.dl_button import ddl_call_back from Uploader.button import youtube_dl_call_back from Uploader.script import Translation -from pyrogram import Client, types -from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from pyrogram import Client import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') diff --git a/Uploader/commands.py b/Uploader/commands.py index 72bcac18..89990409 100644 --- a/Uploader/commands.py +++ b/Uploader/commands.py @@ -20,17 +20,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE -import os - from pyrogram import Client, filters from pyrogram.types import Message from Uploader.script import Translation -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config - @Client.on_message( filters.command("start") & filters.private, diff --git a/Uploader/dl_button.py b/Uploader/dl_button.py index aded19aa..003ee121 100644 --- a/Uploader/dl_button.py +++ b/Uploader/dl_button.py @@ -24,17 +24,13 @@ import time import aiohttp import asyncio -import logging from datetime import datetime from Uploader.functions.display_progress import progress_for_pyrogram, humanbytes, TimeFormatter from Uploader.utitles import * from Uploader.script import Translation -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config +from config import Config logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') diff --git a/Uploader/echo.py b/Uploader/echo.py index 2461f040..e3e8d505 100644 --- a/Uploader/echo.py +++ b/Uploader/echo.py @@ -20,34 +20,25 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE -import os import time import json import asyncio import logging -from opencc import OpenCC - from pyrogram.types import Thumbnail from pyrogram import Client, filters from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config +from config import Config from Uploader.script import Translation from Uploader.functions.ran_text import random_char from Uploader.functions.display_progress import humanbytes -from Uploader.functions.display_progress import humanbytes logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) logging.getLogger("pyrogram").setLevel(logging.WARNING) -s2tw = OpenCC('s2tw.json').convert - @Client.on_message(filters.private & filters.regex(pattern=".*http.*")) async def echo(bot, update): diff --git a/Uploader/functions/help_ytdl.py b/Uploader/functions/help_ytdl.py index b5f1c3aa..849e3e5a 100644 --- a/Uploader/functions/help_ytdl.py +++ b/Uploader/functions/help_ytdl.py @@ -21,8 +21,6 @@ # SOFTWARE import os -import time -import requests import logging from urllib.parse import urlparse @@ -39,6 +37,9 @@ def get_file_extension_from_url(url): def get_resolution(info_dict): + width = 0 + height = 0 + if {"width", "height"} <= info_dict.keys(): width = int(info_dict['width']) height = int(info_dict['height']) @@ -58,4 +59,4 @@ def get_resolution(info_dict): elif info_dict['height'] == 240: width = 426 height = 240 - return (width, height) + return width, height diff --git a/Uploader/thumbunali.py b/Uploader/thumbunali.py index 86cb6504..28fbf709 100644 --- a/Uploader/thumbunali.py +++ b/Uploader/thumbunali.py @@ -24,10 +24,7 @@ from pyrogram import Client, filters -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config +from config import Config @Client.on_message(filters.photo & filters.incoming & filters.private) diff --git a/Uploader/youtube.py b/Uploader/youtube.py index d1f65039..031362b2 100644 --- a/Uploader/youtube.py +++ b/Uploader/youtube.py @@ -21,25 +21,18 @@ # SOFTWARE import os -from urllib.parse import urlparse -import wget import asyncio -from opencc import OpenCC from youtube_dl import YoutubeDL -from pyrogram import Client, filters, enums +from pyrogram import enums from pyrogram.types import Message from pyrogram import Client, filters -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config +from config import Config from Uploader.functions.help_ytdl import get_file_extension_from_url, get_resolution -YTDL_REGEX = (r"^((?:https?:)?\/\/)") -s2tw = OpenCC('s2tw.json').convert +YTDL_REGEX = r"^((?:https?:)?\/\/)" @Client.on_callback_query(filters.regex("^ytdl_audio$")) @@ -84,16 +77,35 @@ async def send_audio(message: Message, info_dict, audio_file): thumb = download_location if os.path.isfile( download_location) else None webpage_url = info_dict['webpage_url'] - title = s2tw(info_dict['title']) + title = info_dict['title'] or '' caption = f'{title}' duration = int(float(info_dict['duration'])) - performer = s2tw(info_dict['uploader']) + performer = info_dict['uploader'] or '' 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) +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)}" + download_location = f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg" + thumb = download_location if os.path.isfile( + download_location) else None + webpage_url = info_dict['webpage_url'] + title = info_dict['title'] or '' + caption = f'{title}' + 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=thumb) + + os.remove(video_file) + os.remove(thumbnail_file) + + @Client.on_callback_query(filters.regex("^ytdl_video$")) async def callback_query_ytdl_video(_, callback_query): try: @@ -123,21 +135,4 @@ async def callback_query_ytdl_video(_, callback_query): except Exception as e: await message.reply_text(e) await callback_query.message.reply_to_message.delete() - await callback_query.message.delete() - - 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)}" - download_location = f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg" - thumb = download_location if os.path.isfile( - download_location) else None - webpage_url = info_dict['webpage_url'] - title = s2tw(info_dict['title']) - caption = f'{title}' - 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=thumb) - - os.remove(video_file) - os.remove(thumbnail_file) + await callback_query.message.delete() \ No newline at end of file diff --git a/app.json b/app.json index e92c3d0d..35059adc 100644 --- a/app.json +++ b/app.json @@ -15,10 +15,6 @@ "website": "kalanakt.github.io/projects/telegram/all-url-uploader ", "repository": "https://github.com/kalanakt/All-Url-Uploader", "env": { - "WEBHOOK": { - "description": "Don't Need To change - Setting this to True when in env mode", - "value": "True" - }, "BOT_TOKEN": { "description": "Your bot token, as a string.", "value": "" @@ -31,17 +27,9 @@ "description": "Get this value from https://my.telegram.org", "value": "" }, - "LOG_CHANNEL": { - "description": "Your Any Own Private Channel ID Where Your Bot As Admin With Full Permission", - "value": "" - }, "OWNER_ID": { "description": "Your Telegram ID For Broadcast", "value": "12345678" - }, - "BOT_USERNAME": { - "description": "Your Bot Username Without @", - "value": "" } }, "addons": [ diff --git a/app.py b/app.py index cb89d57b..78fa71aa 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,8 @@ from flask import Flask + app = Flask(__name__) + @app.route('/') def hello_world(): return 'Hello from Koyeb' diff --git a/bot.py b/bot.py index c483aeb7..9f616b20 100644 --- a/bot.py +++ b/bot.py @@ -25,11 +25,7 @@ from pyrogram.raw.all import layer from pyrogram import Client, idle, __version__ - -if bool(os.environ.get("WEBHOOK")): - from Uploader.config import Config -else: - from sample_config import Config +from config import Config logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') @@ -38,7 +34,20 @@ logging.getLogger("pyrogram").setLevel(logging.WARNING) if not os.path.isdir(Config.DOWNLOAD_LOCATION): - os.makedirs(Config.DOWNLOAD_LOCATION) + os.makedirs(Config.DOWNLOAD_LOCATION) + +if not Config.BOT_TOKEN: + logger.error("Please set BOT_TOKEN in config.py or as env var") + quit(1) + +if not Config.API_ID: + logger.error("Please set API_ID in config.py or as env var") + quit(1) + +if not Config.API_HASH: + logger.error("Please set API_HASH in config.py or as env var") + quit(1) + bot = Client( 'All-Url-Uploader', @@ -50,6 +59,9 @@ ) bot.start() +logger.info("Bot has started.") +logger.info(f"**Bot Started**\n\n**Pyrogram Version:** `{__version__}`\n**Layer:** `{layer}`") +logger.info("Developed by github.com/kalanakt Sponsored by www.netronk.com") idle() bot.stop() -logger.info("Bot Stoped ;)") +logger.info("Bot Stopped ;)") diff --git a/Uploader/config.py b/config.py similarity index 68% rename from Uploader/config.py rename to config.py index e97d8fce..cb9fe22d 100644 --- a/Uploader/config.py +++ b/config.py @@ -21,7 +21,7 @@ # SOFTWARE import os - +from dotenv import load_dotenv import logging logging.basicConfig( @@ -31,13 +31,14 @@ level=logging.INFO ) +load_dotenv() + class Config(object): - WEBHOOK = os.environ.get("BOT_TOKEN", False) # Get a token from @BotFather - BOT_TOKEN = os.environ.get("BOT_TOKEN", "") + BOT_TOKEN = os.environ.get("BOT_TOKEN") # The Telegram API things - API_ID = int(os.environ.get("API_ID", 12345)) + API_ID = os.environ.get("API_ID") API_HASH = os.environ.get("API_HASH") # Get these values from my.telegram.org # Array to store users who are authorized to use the bot @@ -45,28 +46,20 @@ class Config(object): # File /video download location DOWNLOAD_LOCATION = "./DOWNLOADS" - MEGA_EMAIL = os.environ.get("MEGA_EMAIL", "None") - # If deploying on vps edit the above value as example := Mega_email = "Your-Mega_email-inside-inverted-commas." - - # This is not necessary! Enter your mega password only if you have a mega.nz account with pro/business features. - MEGA_PASSWORD = os.environ.get("MEGA_PASSWORD", "None") - # If deploying on vps edit the above value as example := Mega_password = "Your-Mega_password-inside-inverted-commas." # Telegram maximum file upload size TG_MAX_FILE_SIZE = 4194304000 - # Chunk size that should be used with requests + # Chunk size that should be used with requests : default is 128KB CHUNK_SIZE = int(os.environ.get("CHUNK_SIZE", 128)) # Proxy for accessing youtube-dl in GeoRestricted Areas # Get your own proxy from https://github.com/rg3/youtube-dl/issues/1091#issuecomment-230163061 HTTP_PROXY = os.environ.get("HTTP_PROXY", "") - # Set timeout for subprcess + # Set timeout for subprocess PROCESS_MAX_TIMEOUT = 3700 - LOG_CHANNEL = int(os.environ.get("LOG_CHANNEL", -100)) - OWNER_ID = int(os.environ.get("OWNER_ID", "12356")) - BOT_USERNAME = os.environ.get("BOT_USERNAME", "") + OWNER_ID = os.environ.get("OWNER_ID") ADL_BOT_RQ = {} AUTH_USERS = list({int(x) - for x in os.environ.get("AUTH_USERS", "0").split()}) + for x in os.environ.get("AUTH_USERS", "0").split()}) AUTH_USERS.append(OWNER_ID) diff --git a/log.txt b/log.txt new file mode 100644 index 00000000..4a7f064a --- /dev/null +++ b/log.txt @@ -0,0 +1,18 @@ +__main__ - ERROR - Please set BOT_TOKEN in config.py or as env var +__main__ - ERROR - Please set BOT_TOKEN in config.py or as env var +__main__ - INFO - Bot has started. +__main__ - INFO - **Bot Started** + +**Pyrogram Version:** `2.0.106` +**Layer:** `158` +__main__ - INFO - Developed by github.com/kalanakt Sponsored by www.netronk.com +root - INFO - Stop signal received (SIGINT). Exiting... +__main__ - INFO - Bot Stopped ;) +__main__ - INFO - Bot has started. +__main__ - INFO - **Bot Started** + +**Pyrogram Version:** `2.0.106` +**Layer:** `158` +__main__ - INFO - Developed by github.com/kalanakt Sponsored by www.netronk.com +root - INFO - Stop signal received (SIGINT). Exiting... +__main__ - INFO - Bot Stopped ;) diff --git a/requirements.txt b/requirements.txt index 54de003e..2e503ca7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,26 +1,14 @@ aiohttp -beautifulsoup4 hachoir -numpy Pillow -pyrogram==2.0.43 +pyrogram requests tgcrypto -olefile -motor -pymongo -dnspython -psutil +python-dotenv loggers -filetype -tldextract -aiofiles -pyromod yt-dlp -filesplit==4.0.0 -mega.py -opencc wget youtube_dl Flask==2.3.2 gunicorn==20.1.0 +sent diff --git a/sample_config.py b/sample_config.py deleted file mode 100644 index 0341554d..00000000 --- a/sample_config.py +++ /dev/null @@ -1,50 +0,0 @@ -# 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 - -# edit this file with your veriable if you'r deploy bot via locally | vps - -class Config(object): - - # get a token from @BotFather - BOT_TOKEN = "" - - # Get these values from my.telegram.org - API_ID = 1234567 - API_HASH = "" - - # No need to change - DOWNLOAD_LOCATION = "./DOWNLOADS" - ADL_BOT_RQ = {} - CHUNK_SIZE = 128 - TG_MAX_FILE_SIZE = 4194304000 - HTTP_PROXY = "" - PROCESS_MAX_TIMEOUT = 3700 - - # TG Ids - LOG_CHANNEL = -1007119867241 - OWNER_ID = 1288398723 - - # bot username without @ - BOT_USERNAME = "AdvanceUrlUploaderBot" - - # auth users - AUTH_USERS = [OWNER_ID]