Exemplo n.º 1
0
 async def decrypt(self, segment: Segment) -> bool:
     '''
     解密部分
     '''
     if segment.is_encrypt() and segment.is_supported_encryption():
         cipher = CommonAES(segment.xkey.key,
                            binascii.a2b_hex(segment.xkey.iv))
         return cipher.decrypt(segment)
     else:
         return segment.dump()
Exemplo n.º 2
0
 def decrypt(self, segment: Segment) -> bool:
     '''
     解密 落盘
     '''
     try:
         cipher = AES.new(self.aes_key, AES.MODE_CBC, iv=self.aes_iv)
         content = cipher.decrypt(b''.join(segment.content))
         segment.content = []
     except Exception as e:
         print(f'decrypt {segment.name} error -> {e}')
         return False
     else:
         segment.get_path().write_bytes(content)
         return True
Exemplo n.º 3
0
 async def decrypt(self, segment: Segment, stream: Stream) -> bool:
     '''
     解密部分
     '''
     if self.args.disable_auto_decrypt is True:
         logger.debug(f'--disable-auto-decrypt, skip decrypt')
         return segment.dump()
     if segment.is_encrypt() and segment.is_supported_encryption():
         logger.debug(
             f'common aes decrypt, key {segment.xkey.key.hex()} iv {segment.xkey.iv}'
         )
         cipher = CommonAES(segment.xkey.key,
                            binascii.a2b_hex(segment.xkey.iv))
         return cipher.decrypt(segment)
     else:
         return segment.dump()
Exemplo n.º 4
0
 async def download(self, client: ClientSession, stream: Stream,
                    segment: Segment):
     status, flag = 'EXIT', True
     try:
         async with client.get(
                 segment.url + self.args.url_patch,
                 headers=self.args.headers) as resp:  # type: ClientResponse
             _flag = True
             if self.log_detail or resp.status != 200:
                 logger.debug(
                     f'{segment.name} status {resp.status}, {segment.url + self.args.url_patch}'
                 )
             if resp.status in [403, 404]:
                 status = 'STATUS_SKIP'
                 flag = False
                 self.xprogress.decrease_total_count()
                 segment.skip_concat = True
                 if resp.status == 404:
                     segment.max_retry_404 -= 1
             if resp.status == 405:
                 status = 'STATUS_CODE_ERROR'
                 flag = False
             if resp.status in self.args.redl_code:
                 status = 'RE-DOWNLOAD'
                 flag = None
             if resp.headers.get('Content-length') is not None:
                 # 对于 filesize 不为 0 后面再另外考虑
                 size = int(resp.headers["Content-length"])
                 stream.filesize += size
                 logger.debug(
                     f'{segment.name} response Content-length => {size}')
                 self.xprogress.update_total_size(stream.filesize)
             else:
                 size = -1
                 logger.debug(
                     f'{segment.name} response header has no Content-length {dict(resp.headers)}'
                 )
                 _flag = False
             if flag:
                 while self.terminate is False:
                     data = await resp.content.read(512)
                     if not data:
                         break
                     segment.content.append(data)
                     self.xprogress.add_downloaded_size(len(data))
                     if _flag is False:
                         stream.filesize += len(data)
                         logger.debug(
                             f'{segment.name} recv {size} byte data')
                         self.xprogress.update_total_size(stream.filesize)
     except TimeoutError:
         return segment, 'TimeoutError', None
     except client_exceptions.ClientConnectorError:
         return segment, 'ClientConnectorError', None
     except client_exceptions.ClientPayloadError:
         return segment, 'ClientPayloadError', None
     except client_exceptions.ClientOSError:
         return segment, 'ClientOSError', None
     except client_exceptions.ServerDisconnectedError:
         return segment, 'ServerDisconnectedError', None
     except client_exceptions.InvalidURL:
         return segment, 'EXIT', False
     except CancelledError:
         return segment, 'EXIT', False
     except Exception as e:
         logger.error(f'! -> {segment.url}', exc_info=e)
         return segment, status, False
     if self.terminate:
         return segment, 'EXIT', False
     if segment.skip_concat:
         return segment, status, True
     if flag is None:
         return segment, status, None
     if flag is False:
         return segment, status, False
     self.xprogress.add_downloaded_count(1)
     logger.debug(
         f'{segment.name} download end, size => {sum([len(data) for data in segment.content])}'
     )
     return segment, 'SUCCESS', await self.decrypt(segment, stream)