Nekmo / telegram-upload

Upload and download files from Telegram up to 4 GiB using your account
MIT License
1.05k stars 226 forks source link

send split files with personalized caption #235

Open Aikanairo opened 10 months ago

Aikanairo commented 10 months ago

Description

Hi nekmo, thank you for the work you do

I would like to understand how your script handles the caption for files divided into multiple parts

even though I set a camption, the files are sent without a camption, i.e. only with the name in the caption.

Could you just show me the file that manages the caption for managing file uploads exceeding the limit?

thank you so much

Aikanairo commented 10 months ago

I solved it like this

def process_large_file(self, file): file_name = os.path.basename(file) total_size = os.path.getsize(file) parts = math.ceil(total_size / self.client.max_file_size) zfill = int(math.log10(10)) + 1 for part in range(parts): size = total_size - (part self.client.max_file_size) if part >= parts - 1 else self.client.max_file_size splitted_file = SplitFile(self.client, file, size, '{}.{}'.format(file_name, str(part).zfill(zfill)), caption=self.caption) splitted_file.seek(self.client.max_file_size part, split_seek=True) yield splitted_file

def __init__(self, client: 'TelegramManagerClient', file: Union[str, bytes, int], max_read_size: int, name: str, caption: Union[str, None] = None):
    super().__init__(client, file, caption=caption)  # Pass caption to the superclass
    self.max_read_size = max_read_size
    self.remaining_size = max_read_size
    self._name = name