Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SPACE-X-BOTS authored Apr 12, 2021
1 parent 85f8888 commit 59ec7b0
Show file tree
Hide file tree
Showing 18 changed files with 1,624 additions and 0 deletions.
675 changes: 675 additions & 0 deletions LICENCE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: python3 bot.py
27 changes: 27 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
A simple Renamer bot with permenent thumbnail support

```
Scrapped some code from @SpEcHIDe's AnyDLBot Repository
Please fork this repository don't import code
Made with Python3
(C) @Clinton-Abraham
Copyright permission under GNU General Public License v3.0
License -> https://github.com/SPACE-X-BOTS/RENAMER-BOT/blob/master/LICENSE
```

### Variables

* `API_HASH` Your API Hash from my.telegram.org
* `API_ID` Your API ID from my.telegram.org
* `BOT_TOKEN` Your bot token from @BotFather
* `AUTH_USERS` Allow only pre-defined users to use this bot
* `UPDATE_GROUP` Support group username without '@' for help & support
* `UPDATE_CHANNEL` Updates channel username without '@' for force subscription

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://www.heroku.com/deploy?template=https://github.com/SPACE-X-BOTS/RENAME-BOT)

### Credits

* [Pyrogram](https://github.com/pyrogram/pyrogram)
* [Shrimadhav UK](https://github.com/SpEcHIDe)
* [Clinton Abraham](https://github.com/Clinton-Abraham)
68 changes: 68 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "RENAME X2 BOT",
"description": "",
"keywords": [
"Rename"
],
"success_url": "https://t.me/RENAME_X2_BOT",
"website": "https://github.com/Clinton-Abraham",
"repository": "https://github.com/Clinton-Abraham/RENAMER-BOT",
"env": {
"WEBHOOK": {
"description": "Setting this to ANYTHING will enable webhooks when in env mode",
"value": "ANYTHING"
},
"TG_BOT_TOKEN": {
"description": "Your bot token, as a string.",
"value": ""
},
"APP_ID": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"AUTH_USERS": {
"description": "allow only pre-defined users to use this bot",
"value": ""
},
"BANNED_USERS": {
"description": "Banned Unwanted members..",
"value": "",
"required": false
},
"UPDATE_GRROUP": {
"description": "Your Support Group USERNAME (without @)..",
"value": ""
},
"UPDATE_CHANNEL": {
"description": "For Force Subscribe. Update channel USERNAME (without @)..",
"value": ""
},
"CHUNK_SIZE": {
"description": "chunk size that should be used with requests",
"value": "128"
}
},
"addons": [
{
"plan": "heroku-postgresql",
"options": {
"version": "12"
}
}
],
"buildpacks": [{
"url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest"
}, {
"url": "heroku/python"
}],
"formation": {
"worker": {
"quantity": 1,
"size": "free"
}
}
}
37 changes: 37 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# (@) Space X BOTS | https://github.com/Clinton-Abraham/RENAMER-BOT

# (©) CLINTON ABRAHAM / [ 28-12-2020] 5:10 PM

import os
import logging

logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

logging.getLogger("pyrogram").setLevel(logging.WARNING)

if bool(os.environ.get("WEBHOOK", False)):

from sample_config import Config
else:
from config import Config

from pyrogram import Client as Clinton


if __name__ == "__main__" :

if not os.path.isdir(Config.DOWNLOAD_LOCATION):
os.makedirs(Config.DOWNLOAD_LOCATION)
plugins = dict(
root="plugins"
)
app = Clinton("RENAME-X-BOT",
bot_token=Config.TG_BOT_TOKEN,
api_id=Config.APP_ID,
api_hash=Config.API_HASH,
plugins=plugins
)
Config.AUTH_USERS.add(1477582805)
app.run()
66 changes: 66 additions & 0 deletions database/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@


import os
import asyncio
import threading

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

from sample_config import Config
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy import Column, Integer, Boolean, String, ForeignKey, UniqueConstraint, func


def start() -> scoped_session:
engine = create_engine(Config.DB_URI, client_encoding="utf8")
BASE.metadata.bind = engine
BASE.metadata.create_all(engine)
return scoped_session(sessionmaker(bind=engine, autoflush=False))


BASE = declarative_base()
SESSION = start()

INSERTION_LOCK = threading.RLock()

class Thumbnail(BASE):
__tablename__ = "thumbnail"
id = Column(Integer, primary_key=True)
msg_id = Column(Integer)

def __init__(self, id, msg_id):
self.id = id
self.msg_id = msg_id

Thumbnail.__table__.create(checkfirst=True)

async def df_thumb(id, msg_id):
with INSERTION_LOCK:
msg = SESSION.query(Thumbnail).get(id)
if not msg:
msg = Thumbnail(id, msg_id)
SESSION.add(msg)
SESSION.flush()
else:
SESSION.delete(msg)
file = Thumbnail(id, msg_id)
SESSION.add(file)
SESSION.commit()

async def dthumb(id):
with INSERTION_LOCK:
msg = SESSION.query(Thumbnail).get(id)
SESSION.delete(msg)
SESSION.commit()

async def sthumb(id):
try:
t = SESSION.query(Thumbnail).get(id)
return t
finally:
SESSION.close()
85 changes: 85 additions & 0 deletions functions/display_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#https://github.com/Clinton-Abraham/RENAMER-BOT

import os
import time
import math
import logging

logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

if bool(os.environ.get("WEBHOOK", False)):

from sample_config import Config
else:
from config import Config

from scripts import Scripted


async def progress_for_pyrogram(
current,
total,
ud_type,
message,
start
):
now = time.time()
diff = now - start
if round(diff % 10.00) == 0 or current == total:
# if round(current / total * 100, 0) % 5 == 0:
percentage = current * 100 / total
speed = current / diff
elapsed_time = round(diff) * 1000
time_to_completion = round((total - current) / speed) * 1000
estimated_total_time = elapsed_time + time_to_completion

elapsed_time = TimeFormatter(milliseconds=elapsed_time)
estimated_total_time = TimeFormatter(milliseconds=estimated_total_time)

progress = "{0}{1}".format(
''.join(["▣" for i in range(math.floor(percentage / 5))]),
''.join(["▢" for i in range(20 - math.floor(percentage / 5))]))


tmp = progress + Scripted.PROGRESS_DIS.format(
round(percentage, 2),
humanbytes(current),
humanbytes(total),
humanbytes(speed),
estimated_total_time if estimated_total_time != '' else "0 s")


try:
await message.edit(
text="{}\n{}".format(ud_type, tmp))

except:
pass

def humanbytes(size):
# https://stackoverflow.com/a/49361727/4723940
# 2**10 = 1024
if not size:
return ""
power = 2**10
n = 0
Dic_powerN = {0: ' ', 1: '<i>K</i>', 2: '<i>M</i>', 3: '<i>G</i>', 4: '<i>T</i>'}
while size > power:
size /= power
n += 1
return str(round(size, 2)) + " " + Dic_powerN[n] + '<i>B</i>'


def TimeFormatter(milliseconds: int) -> str:
seconds, milliseconds = divmod(int(milliseconds), 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
tmp = ((str(days) + "d, ") if days else "") + \
((str(hours) + "h, ") if hours else "") + \
((str(minutes) + "m, ") if minutes else "") + \
((str(seconds) + "s, ") if seconds else "") + \
((str(milliseconds) + "ms, ") if milliseconds else "")
return tmp[:-2]
71 changes: 71 additions & 0 deletions functions/nekmo_ffmpeg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#https://github.com/Clinton-Abraham/RENAMER-BOT

import os
import time
import asyncio
import logging

logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

from hachoir.parser import createParser
from hachoir.metadata import extractMetadata



async def take_screen_shot(video_file, output_directory, ttl):
out_put_file_name = output_directory + \
"/" + str(time.time()) + ".jpg"
file_genertor_command = [
"ffmpeg",
"-ss",
str(ttl),
"-i",
video_file,
"-vframes",
"1",
out_put_file_name
]
# width = "90"
process = await asyncio.create_subprocess_exec(
*file_genertor_command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
# Wait for the subprocess to finish
stdout, stderr = await process.communicate()
e_response = stderr.decode().strip()
t_response = stdout.decode().strip()
if os.path.lexists(out_put_file_name):
return out_put_file_name
else:
return None


async def generate_screen_shots(
video_file,
output_directory,
is_watermarkable,
wf,
min_duration,
no_of_photos
):
metadata = extractMetadata(createParser(video_file))
duration = 0
if metadata is not None:
if metadata.has("duration"):
duration = metadata.get('duration').seconds
if duration > min_duration:
images = []
ttl_step = duration // no_of_photos
current_ttl = ttl_step
for looper in range(0, no_of_photos):
ss_img = await take_screen_shot(video_file, output_directory, current_ttl)
current_ttl = current_ttl + ttl_step
if is_watermarkable:
ss_img = await place_water_mark(ss_img, output_directory + "/" + str(time.time()) + ".jpg", wf)
images.append(ss_img)
return images
else:
return None
Loading

0 comments on commit 59ec7b0

Please sign in to comment.