Skip to content

Commit

Permalink
Explore yourself
Browse files Browse the repository at this point in the history
ask queries in telegram group
t.me/yo_codes_support
  • Loading branch information
yashoswalyo committed Sep 10, 2022
1 parent 0f91bb7 commit 230c373
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 320 deletions.
185 changes: 113 additions & 72 deletions bot.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

update = subprocess.run([f"git init -q \
&& git config --global user.email yashoswal18@gmail.com \
&& git config --global user.name clonebot \
&& git config --global user.name mergebot \
&& git add . \
&& git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO} \
Expand All @@ -54,4 +54,4 @@
if update.returncode == 0:
LOGGER.info('Successfully updated with latest commit from UPSTREAM_REPO')
else:
LOGGER.warning('Something went wrong while updating, check UPSTREAM_REPO if valid or not!')
LOGGER.warning('Something went wrong while updating, check UPSTREAM_REPO if valid or not!')
57 changes: 41 additions & 16 deletions helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def addUser(uid, fname, lname):


async def broadcast():
a = Database.mergebot.users.find({})
a = Database.mergebot.mergeSettings.find({})
return a


Expand Down Expand Up @@ -67,8 +67,7 @@ async def getThumb(uid):


async def deleteUser(uid):
Database.mergebot.allowedUsers.delete_many({"_id": uid})
Database.mergebot.users.delete_many({"_id": uid})
Database.mergebot.mergeSettings.delete_many({"_id": uid})


async def addUserRcloneConfig(cb: CallbackQuery, fileId):
Expand All @@ -93,29 +92,46 @@ async def getUserRcloneConfig(uid):
return None


def getUserMergeMode(uid: int):
"Returns merge mode of user"
def getUserMergeSettings(uid: int):
try:
res_cur = Database.mergebot.mergeModes.find_one({"_id": uid})
return int(res_cur["mode"])
except Exception:
res_cur = Database.mergebot.mergeSettings.find_one({"_id": uid})
return res_cur
except Exception as e:
LOGGER.info(e)
return None


def setUserMergeMode(uid: int, mode: int):
def setUserMergeSettings(uid: int, name: str, mode, edit_metadata, allowed, thumbnail):
modes = Config.MODES
if mode:
if uid:
try:
Database.mergebot.mergeModes.insert_one(
document={"_id": uid, "mode":mode}
Database.mergebot.mergeSettings.insert_one(
document={
"_id": uid,
"name": name,
"user_settings": {
"merge_mode": mode,
"edit_metadata": edit_metadata,
},
"isAllowed": allowed,
"thumbnail": thumbnail,
}
)
LOGGER.info("User {} Mode updated to {}".format(uid, modes[mode-1]))
LOGGER.info("User {} Mode updated to {}".format(uid, modes[mode - 1]))
except Exception:
Database.mergebot.mergeModes.replace_one(
Database.mergebot.mergeSettings.replace_one(
filter={"_id": uid},
replacement={"mode":mode},
replacement={
"name": name,
"user_settings": {
"merge_mode": mode,
"edit_metadata": edit_metadata,
},
"isAllowed": allowed,
"thumbnail": thumbnail,
},
)
LOGGER.info("User {} Mode updated to {}".format(uid, modes[mode-1]))
LOGGER.info("User {} Mode updated to {}".format(uid, modes[mode - 1]))
MERGE_MODE[uid] = mode
# elif mode == 2:
# try:
Expand Down Expand Up @@ -145,3 +161,12 @@ def setUserMergeMode(uid: int, mode: int):
# LOGGER.info("User {} Mode updated to {}".format(uid, modes[2]))
# MERGE_MODE[uid]=3
LOGGER.info(MERGE_MODE)


def enableMetadataToggle(uid: int, value: bool):

1


def disableMetadataToggle(uid: int, value: bool):
1
6 changes: 3 additions & 3 deletions helpers/ffmpeg.py → helpers/ffmpeg_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def MergeSub(filePath: str, subPath: str, user_id):
shell=True,
)
orgFilePath = shutil.move(
f"./downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv", filePath
f"downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv", filePath
)
return orgFilePath

Expand Down Expand Up @@ -129,7 +129,7 @@ def MergeSubNew(filePath: str, subPath: str, user_id, file_list):
f"ffmpeg -hide_banner {input_files}-map 0:v:0 -map 0:a:? -map 0:s:? {maps}{metadata}-c:v copy -c:a copy -c:s srt './downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv'",
shell=True,
)
return f"./downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv"
return f"downloads/{str(user_id)}/[@yashoswalyo]_softmuxed_video.mkv"


def MergeAudio(videoPath:str,files_list:list,user_id):
Expand All @@ -154,7 +154,7 @@ def MergeAudio(videoPath:str,files_list:list,user_id):
f"ffmpeg -hide_banner {inputfiles}-map 0:v:0 -map 0:a:? {maps}-map 0:s:? -c:v copy -c:a copy -c:s copy {rmDispositions}-disposition:a:{audioTracks} default './downloads/{str(user_id)}/[@yashoswalyo]_export.mkv'",
shell=True
)
return f"./downloads/{str(user_id)}/[@yashoswalyo]_export.mkv"
return f"downloads/{str(user_id)}/[@yashoswalyo]_export.mkv"

async def cult_small_video(video_file, output_directory, start_time, end_time, format_):
# https://stackoverflow.com/a/13891070/4723940
Expand Down
12 changes: 0 additions & 12 deletions helpers/msg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ def makebuttons(self, set1: list, set2: list, isUrl=False, isCallback=True,rows
return self._make()

def _make(self):
# butt = []
# if self._isUrl:
# count=0
# for j in range(int(len(self._set1)/3)):
# buttons = []

# for i in range(3):
# buttons.append(
# InlineKeyboardButton(text=self._set1[count], url=self._set2[0])
# )
# count+=1
# butt.append(buttons)
butt = []
if self._isUrl:
while self._set1:
Expand Down
24 changes: 12 additions & 12 deletions helpers/uploader.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import asyncio
import os
import time
import asyncio

from __init__ import LOGGER
from bot import LOGCHANNEL, userBot
from config import Config
from pyrogram import Client
from pyrogram.types import (
CallbackQuery,
Message
)
from pyrogram.types import CallbackQuery, Message

from helpers.display_progress import Progress
from config import Config
from bot import userBot ,LOGCHANNEL
from __init__ import LOGGER


async def uploadVideo(
c:Client,
c: Client,
cb: CallbackQuery,
merged_video_path,
width,
Expand All @@ -22,7 +22,7 @@ async def uploadVideo(
file_size,
upload_mode: bool,
):
# Report your errors in telegram group.
# Report your errors in telegram group (@yo_codes).
if Config.IS_PREMIUM:
sent_ = None
prog = Progress(cb.from_user.id, c, cb.message)
Expand Down Expand Up @@ -59,9 +59,9 @@ async def uploadVideo(
if sent_ is not None:
await c.copy_message(
chat_id=cb.message.chat.id,
from_chat_id=sent_.chat.id ,
from_chat_id=sent_.chat.id,
message_id=sent_.id,
caption=f"`{merged_video_path.rsplit('/',1)[-1]}`"
caption=f"`{merged_video_path.rsplit('/',1)[-1]}`",
)
# await sent_.delete()
else:
Expand Down
44 changes: 42 additions & 2 deletions helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import os
import threading
import time
from pyrogram import filters

from helpers.database import setUserMergeSettings, getUserMergeSettings
SIZE_UNITS = ["B", "KB", "MB", "GB", "TB", "PB"]


Expand Down Expand Up @@ -38,3 +37,44 @@ def get_readable_time(seconds: int) -> str:
seconds = int(seconds)
result += f"{seconds}s"
return result
class UserSettings(object):
def __init__(self, uid: int, name: str):
self.user_id: int = uid
self.name: str = name
self.merge_mode: int = 1
self.edit_metadata: bool = False
self.allowed: bool = False
self.thumbnail = None
self.get()
# def __init__(self,uid:int,name:str,merge_mode:int=1,edit_metadata=False) -> None:

def get(self):
cur = getUserMergeSettings(self.user_id)
if cur is not None:
self.name = cur["name"]
self.merge_mode = cur["user_settings"]["merge_mode"]
self.edit_metadata = cur["user_settings"]["edit_metadata"]
self.allowed = cur["isAllowed"]
self.thumbnail = cur["thumbnail"]
return {
"uid": self.user_id,
"name": self.name,
"user_settings": {
"merge_mode": self.merge_mode,
"edit_metadata": self.edit_metadata,
},
"isAllowed": self.allowed,
"thumbnail": self.thumbnail,
}
else: return self.set()

def set(self):
setUserMergeSettings(
uid=self.user_id,
name=self.name,
mode=self.merge_mode,
edit_metadata=self.edit_metadata,
allowed=self.allowed,
thumbnail=self.thumbnail,
)
return self.get()
Loading

0 comments on commit 230c373

Please sign in to comment.