Beispiel #1
0
 async def send(self):
     if self.thumbnailLocation:
         await self.setStatus('Sending thumbnail ...')
         title = self.title.replace('.mp3', '')
         if self.channel_name is not None:
             caption = f'<b>{title}\n{self.channel_name}\n{self.upload_date}</b>'
         else:
             caption = f'<b>{title}\n{self.artist}\n{self.upload_date}</b>'
         self.ts(
             self.client.send_file(self.targetChannelLink,
                                   self.thumbnailLocation,
                                   caption=caption), self.client.loop)
         await self.setStatus('Thumbnail sent!')
     if not validSize(self.fileLocation):
         await self.setStatus('Too large to upload!')
     toSend = open(self.fileLocation, 'rb')
     try:
         try:
             title = self.title.split('\n')[0]
             fastFile = self.ts(
                 upload_file(self.client,
                             toSend,
                             fileName=title,
                             progress_callback=self.uploadPcb),
                 self.client.loop).result()
         except ValueError:
             await self.setStatus(
                 f'The file {self.title} is too large to upload!')
             return
         metadata = getMetadata(self.fileLocation)
         data = TinyTag.get(self.fileLocation)
         try:
             performer = metadata.tags.artist[0] if metadata else None
             title = metadata.tags.title[
                 0] if metadata else self.title.split('\n')[0]
             duration = metadata.streaminfo.duration if metadata else data.duration
         except AttributeError:
             performer = None
             title = self.title
             duration = data.duration
         attributes = [
             DocumentAttributeAudio(int(duration),
                                    performer=performer,
                                    voice=False,
                                    title=f'{title}.mp3')
         ]
         while not self.tracker.request_allowed(self.targetChannelLink):
             await asyncio.sleep(1)
         self.ts(self.client.send_file(self.targetChannelLink,
                                       fastFile,
                                       attributes=attributes,
                                       supports_streaming=True),
                 loop=self.client.loop).result()
     except errors.rpcerrorlist.FloodWaitError as e:
         await asyncio.sleep(int(e.seconds) + 5)
Beispiel #2
0
 async def send(self):
     if self.thumbnailLocation:
         await self.setStatus('Sending thumbnail ...')
         title = self.title.replace('.mp3', '')
         caption = f'<b>{self.title}</b>'
         self.ts(
             self.client.send_file(self.targetChannelLink,
                                   self.thumbnailLocation,
                                   caption=caption), self.client.loop)
         await self.setStatus('Thumbnail sent!')
     if not validSize(self.fileLocation):
         await self.setStatus('Too large to upload!')
     toSend = open(self.fileLocation, 'rb')
     try:
         print('Sending as streamable...')
         try:
             title = self.fileLocation.split('/')[-1]
             fastFile = self.ts(
                 upload_file(self.client,
                             toSend,
                             fileName=title,
                             progress_callback=self.uploadPcb),
                 self.client.loop).result()
         except ValueError:
             await self.setStatus(
                 f'The file {self.title} is too large to upload!')
             return
         duration, width, height = getVideoMetadata(self.fileLocation)
         attributes = [
             DocumentAttributeVideo(duration,
                                    width,
                                    height,
                                    supports_streaming=True)
         ]
         while not self.tracker.request_allowed(self.targetChannelLink):
             await asyncio.sleep(1)
         self.ts(
             self.client.send_file(self.targetChannelLink,
                                   fastFile,
                                   supports_streaming=True,
                                   attributes=attributes),
             self.client.loop).result()
     except errors.rpcerrorlist.FloodWaitError as e:
         await asyncio.sleep(int(e.seconds) + 5)
Beispiel #3
0
 async def direct_sender(self, targetChannelLink, fileDownloadLink,
                         extension, voicePlayable, streamableFiles, f):
     try:
         if extension in voicePlayable:
             while not self.tracker.request_allowed(targetChannelLink):
                 await asyncio.sleep(1)
             self.ts(
                 self.client.send_file(targetChannelLink,
                                       fileDownloadLink,
                                       supports_streaming=True,
                                       progress_callback=self.uploadPcb),
                 self.client.loop).result()
         elif extension in streamableFiles:
             while not self.tracker.request_allowed(targetChannelLink):
                 await asyncio.sleep(1)
             self.ts(
                 self.client.send_file(targetChannelLink,
                                       fileDownloadLink,
                                       supports_streaming=True,
                                       progress_callback=self.uploadPcb),
                 self.client.loop).result()
         else:
             while not self.tracker.request_allowed(targetChannelLink):
                 await asyncio.sleep(1)
             self.ts(
                 self.client.send_file(targetChannelLink,
                                       fileDownloadLink,
                                       progress_callback=self.uploadPcb),
                 self.client.loop).result()
     except errors.rpcerrorlist.ExternalUrlInvalidError:
         downloadedFile = await self.seedr.downloadFile(
             f.get('id'), f'{self.downloadLocation}/{f.get("name")}')
         if not self.validSize(downloadedFile):
             self.logger.info('File size is not valid ...')
         toSend = open(downloadedFile, 'rb')
         try:
             fastFile = self.ts(
                 upload_file(self.client,
                             toSend,
                             fileName=f.get("name"),
                             progress_callback=self.uploadPcb),
                 self.client.loop).result()
             self.logger.info('Fast file created!')
         except ValueError:
             await asyncio.sleep(0.8)
             await self.setStatus(
                 f'The file {f.get("name")} is too large to upload!')
             self.logger.info(
                 f'File is too larget to upload:  {self.fileName}')
             return
         try:
             await self.local_sender(extension, voicePlayable,
                                     streamableFiles, downloadedFile,
                                     targetChannelLink, fastFile)
         except errors.rpcerrorlist.FloodWaitError as e:
             self.logger.info(
                 f'Flood wait error! \nWaiting for {e.seconds} seconds before retry!'
             )
             await asyncio.sleep(int(e.seconds) + 5)
             await self.local_sender(extension, voicePlayable,
                                     streamableFiles, downloadedFile,
                                     targetChannelLink, fastFile)
         os.remove(downloadedFile)
Beispiel #4
0
 async def send(self):
     voicePlayable = ['flac', 'mp3', 'MP3']
     streamableFiles = ['mp4', 'MP4', 'Mp4', 'mP4']
     if not validSize(self.fileLocation):
         await self.setStatus('Too large to upload!')
     toSend = open(self.fileLocation, 'rb')
     try:
         title = self.title.split('\n')[0]
         print('Creating fast file ...')
         fastFile = self.ts(
             upload_file(self.client,
                         toSend,
                         fileName=title,
                         progress_callback=self.uploadPcb),
             self.client.loop).result()
     except ValueError:
         await self.setStatus(
             f'The file {self.title} is too large to upload!')
         return
     extension = self.fileName.split('.')[-1]
     while True:
         try:
             if extension in voicePlayable:
                 print('Sending as audio')
                 metadata = getMetadata(self.fileLocation)
                 data = TinyTag.get(self.fileLocation)
                 try:
                     performer = metadata.tags.artist[
                         0] if metadata else None
                     title = metadata.tags.title[
                         0] if metadata else self.title.split('\n')[0]
                     duration = metadata.streaminfo.duration if metadata else data.duration
                 except AttributeError:
                     performer = None
                     title = self.title
                     duration = data.duration
                 attributes = [
                     DocumentAttributeAudio(int(duration),
                                            performer=performer,
                                            voice=False,
                                            title=f'{title}.mp3')
                 ]
                 while not self.tracker.request_allowed(
                         self.targetChannelLink):
                     await asyncio.sleep(1)
                 self.ts(self.client.send_file(self.targetChannelLink,
                                               fastFile,
                                               attributes=attributes,
                                               supports_streaming=True),
                         loop=self.client.loop).result()
                 break
             elif extension in streamableFiles:
                 duration, width, height = getVideoMetadata(
                     self.fileLocation)
                 attributes = [
                     DocumentAttributeVideo(duration,
                                            width,
                                            height,
                                            supports_streaming=True)
                 ]
                 while not self.tracker.request_allowed(
                         self.targetChannelLink):
                     await asyncio.sleep(1)
                 print('Sending as streamable...')
                 self.ts(
                     self.client.send_file(self.targetChannelLink,
                                           fastFile,
                                           supports_streaming=True,
                                           attributes=attributes),
                     self.client.loop).result()
                 break
             else:
                 while not self.tracker.request_allowed(
                         self.targetChannelLink):
                     await asyncio.sleep(1)
                 print('Sending as file ..')
                 self.ts(
                     self.client.send_file(self.targetChannelLink,
                                           fastFile),
                     self.client.loop).result()
                 break
         except errors.rpcerrorlist.FloodWaitError as e:
             await asyncio.sleep(int(e.seconds) + 5)
Beispiel #5
0
    async def sendToTarget(self, folderId, targetChannelLink, status):
        await self.seedr.filterDownloadedContent(folderId)
        cover_extensions = ['jpg', 'JPG', 'jpeg', 'JPEG', 'PNG', 'png']
        folderContent = await self.seedr.getFolderContent(folderID=folderId)
        for f in folderContent['files']:
            self.logger.info(f'Sending file : {f.get("name")}')
            extension = f.get('name').split('.')[-1].lower()
            if extension in cover_extensions:
                await asyncio.sleep(0.8)
                await self.setStatus('Sending the cover image ...')
                fileDownloadLink = await self.seedr.getDownloadLink(f['id'])
                try:
                    while not self.tracker.request_allowed(targetChannelLink):
                        await asyncio.sleep(1)
                    self.ts(
                        self.client.send_file(targetChannelLink,
                                              fileDownloadLink),
                        self.client.loop)
                except errors.rpcerrorlist.WebpageCurlFailedError:
                    downloadedFile = await self.seedr.downloadFile(
                        f.get('id'),
                        f'{self.downloadLocation}/{f.get("name")}')
                    toSend = open(downloadedFile, 'rb')
                    while not self.tracker.request_allowed(targetChannelLink):
                        await asyncio.sleep(1)
                    self.ts(self.client.send_file(targetChannelLink, toSend),
                            self.client.loop).result()
                    os.remove(downloadedFile)
                await asyncio.sleep(0.8)
                self.logger.info(f'File sent : {f.get("name")}')
                await self.setStatus('Cover image sent!')
        if len(folderContent['folders']) != 0:
            for folder in folderContent['folders']:
                await self.sendToTarget(folder['id'], targetChannelLink,
                                        status)
        files = sorted(folderContent['files'], key=itemgetter('name'))
        for f in files:
            self.fileName = f.get("name")
            voicePlayable = ['flac', 'mp3', 'MP3']
            streamableFiles = ['mp4', 'MP4', 'Mp4', 'mP4']
            await asyncio.sleep(0.8)
            await self.setStatus(f'Sending file : {f.get("name")}')
            extension = f.get('name').split('.')[-1]
            if extension in cover_extensions:
                continue
            try:
                fileDownloadLink = await self.seedr.getDownloadLink(f['id'])
                try:
                    while not self.tracker.request_allowed(targetChannelLink):
                        await asyncio.sleep(1)
                    await self.direct_sender(targetChannelLink,
                                             fileDownloadLink, extension,
                                             voicePlayable, streamableFiles, f)
                except errors.rpcerrorlist.FloodWaitError as e:
                    self.logger.info(
                        f'Flood wait error!\nWaiting for {e.seconds} seconds before retry!'
                    )
                    await asyncio.sleep(int(e.seconds) + 5)
                    while not self.tracker.request_allowed(targetChannelLink):
                        await asyncio.sleep(1)
                    await self.direct_sender(targetChannelLink,
                                             fileDownloadLink, extension,
                                             voicePlayable, streamableFiles, f)

            except (errors.rpcerrorlist.WebpageCurlFailedError,
                    errors.rpcerrorlist.ExternalUrlInvalidError):
                downloadedFile = await self.seedr.downloadFile(
                    f.get('id'), f'{self.downloadLocation}/{f.get("name")}')
                if not self.validSize(downloadedFile):
                    self.logger.info('File size is not valid ...')
                    continue
                toSend = open(downloadedFile, 'rb')
                try:
                    fastFile = self.ts(
                        upload_file(self.client,
                                    toSend,
                                    fileName=f.get("name"),
                                    progress_callback=self.uploadPcb),
                        self.client.loop).result()
                    self.logger.info('Fast file created!')
                except ValueError:
                    await asyncio.sleep(0.8)
                    await self.setStatus(
                        f'The file {f.get("name")} is too large to upload!')
                    self.logger.info(
                        f'File is too larget to upload:  {self.fileName}')
                    continue
                try:
                    while not self.tracker.request_allowed(targetChannelLink):
                        await asyncio.sleep(1)
                    await self.local_sender(extension, voicePlayable,
                                            streamableFiles, downloadedFile,
                                            targetChannelLink, fastFile)
                except errors.rpcerrorlist.FloodWaitError as e:
                    self.logger.info(
                        f'Flood wait error! \nWaiting for {e.seconds} seconds before retry!'
                    )
                    await asyncio.sleep(int(e.seconds) + 5)
                    while not self.tracker.request_allowed(targetChannelLink):
                        await asyncio.sleep(1)
                    await self.local_sender(extension, voicePlayable,
                                            streamableFiles, downloadedFile,
                                            targetChannelLink, fastFile)
                os.remove(downloadedFile)