Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Add a new bot client to check download files
Browse files Browse the repository at this point in the history
  • Loading branch information
Divkix committed Feb 28, 2023
1 parent 709dd7e commit b82f88f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions WebStreamer/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@
sleep_threshold=Vars.SLEEP_THRESHOLD,
workers=Vars.WORKERS,
)

# @MisS_AliTaBot client for downloading files
MissAliTaBot = Client(
"Miss AliTa Bot",
api_id=Vars.API_ID,
api_hash=Vars.API_HASH,
bot_token=Vars.MISSALITABOT_TOKEN,
sleep_threshold=Vars.SLEEP_THRESHOLD,
workers=Vars.WORKERS,
)
6 changes: 4 additions & 2 deletions WebStreamer/server/stream_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pypers.formatters import Formatters

from WebStreamer import StartTime
from WebStreamer.bot import StreamBot
from WebStreamer.bot import MissAliTaBot, StreamBot
from WebStreamer.db import Downloads, Users
from WebStreamer.logger import LOGGER
from WebStreamer.utils.custom_dl import TGCustomYield, chunk_size, offset_fix
Expand Down Expand Up @@ -113,7 +113,9 @@ async def media_streamer(request, message_id: int) -> web.StreamResponse:
"""
range_header = request.headers.get("Range", 0)
media_msg = await StreamBot.get_messages(Vars.LOG_CHANNEL, message_id)
file_properties = await TGCustomYield().generate_file_properties(media_msg)
file_properties = await TGCustomYield(MissAliTaBot).generate_file_properties(
media_msg,
)
file_size = file_properties.file_size

if range_header:
Expand Down
4 changes: 2 additions & 2 deletions WebStreamer/utils/custom_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class TGCustomYield:
class to get the file from telegram servers
"""

def __init__(self):
def __init__(self, main_bot: Client = StreamBot):
"""
A custom method to stream files from telegram. functions: generate_file_properties: returns the properties
for a media on a specific message contained in FileId class. generate_media_session: returns the media
session for the DC that contains the media file on the message. yield_file: yield a file from telegram
servers for streaming.
"""
# NOTE: This is the default bot, can add a list and iterate over it to switch to different bots, need to add clients to 'bot/__init__.py'
self.main_bot = StreamBot
self.main_bot = main_bot

@staticmethod
async def generate_file_properties(m: Message):
Expand Down
1 change: 1 addition & 0 deletions WebStreamer/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Vars:
API_ID = int(config("API_ID", default=None))
API_HASH = str(config("API_HASH", default=None))
BOT_TOKEN = str(config("BOT_TOKEN", default=None))
MISSALITABOT_TOKEN = str(config("MISSALITABOT_TOKEN", default=None))
SLEEP_THRESHOLD = int(config("SLEEP_THRESHOLD", default=60))
WORKERS = int(config("WORKERS", default=8))
LOG_CHANNEL = int(config("LOG_CHANNEL", default=-100))
Expand Down

0 comments on commit b82f88f

Please sign in to comment.