Подскажите как быть : нужно большие объемы архивов с TG переложить на мегу , без локального скачивания. Возможно ли такое ?
from telethon.sync import TelegramClient, events
from mega import Mega
import random
api_id = ''
api_hash = ''
bot_token = ''
mega_email = ''
mega_password = ''
mega = Mega()
m = mega.login(mega_email, mega_password)
client = TelegramClient('session_name', api_id, api_hash).start(bot_token=bot_token)
channels_to_monitor = set()
@client.on(events.NewMessage(pattern='/start'))
async def start(event):
await event.respond('Bot started. Use /add_channel to add channels/groups for file upload.')
@client.on(events.NewMessage(pattern='/add_channel'))
async def add_channel(event):
await event.respond('Enter the username of the channel/group you want to monitor:')
channels_to_monitor.add(event.sender_id)
@client.on(events.NewMessage)
async def handle_new_message(event):
if event.sender_id in channels_to_monitor and event.media:
try:
if event.media.document.size <= 1024 * 1024 * 1024: # Check if file size is <= 20 GB
input_location = await event.download_media(bytes)
account_info = m.get_user()
storage_info = account_info['storage']
used_storage = storage_info['used']
total_storage = storage_info['max']
if used_storage + event.media.document.size < total_storage:
file_path = m.upload(input_location)
await event.respond(f"File successfully uploaded to Mega: {file_path}")
else:
await event.respond("Insufficient storage space in Mega account.")
else:
await event.respond("File size exceeds the limit (20 GB) and cannot be uploaded!.")
except Exception as e:
print(f"Error uploading file: {e}")
await event.respond("Error uploading file. Please try again later.")
with client:
client.run_until_disconnected()
Скачивать в любом случае придется. Вопрос только куда? Это может быть сервер, который скачивает через скрипт по API файлы с телеграм и грузит их на мегу. Качать он может частями: загружать в память, либо сохранять на диск во временную папку. В этом случае нужны API-ключи для телеграм и Mega. Ну либо ручками качать и заливать.Подскажите как быть : нужно большие объемы архивов с TG переложить на мегу , без локального скачивания. Возможно ли такое ?
you can execute that on any vps you have run until its end.