def getByteStream(self, fileinfo): message = slskmessages.SlskMessage() stream = bytes([1]) + message.packObject( fileinfo[0]) + message.packObject(NetworkLongLongType(fileinfo[1])) if fileinfo[2] is not None: try: msgbytes = b'' msgbytes += message.packObject('mp3') + message.packObject(3) msgbytes += ( message.packObject(0) + message.packObject(NetworkIntType(fileinfo[2][0])) + message.packObject(1) + message.packObject(NetworkIntType(fileinfo[3])) + message.packObject(2) + message.packObject(NetworkIntType(fileinfo[2][1]))) stream += msgbytes except Exception: log.addwarning( _( "Found meta data that couldn't be encoded, possible corrupt file: '%(file)s' has a bitrate of %(bitrate)s kbs, a length of %(length)s seconds and a VBR of %(vbr)s" % { 'file': fileinfo[0], 'bitrate': fileinfo[2][0], 'length': fileinfo[3], 'vbr': fileinfo[2][1] })) stream += message.packObject('') + message.packObject(0) else: stream += message.packObject('') + message.packObject(0) return stream
def getDirStream(self, dir): msg = slskmessages.SlskMessage() stream = msg.packObject(NetworkIntType(len(dir))) for file_and_meta in dir: stream += self.getByteStream(file_and_meta) return stream
def getDirStream(self, dir): stream = bytearray() stream.extend(slskmessages.SlskMessage().packObject( NetworkIntType(len(dir)))) for file_and_meta in dir: stream.extend(self.getByteStream(file_and_meta)) return stream
def get_dir_stream(self, folder): """ Pack all files and metadata in directory """ message = slskmessages.SlskMessage() stream = bytearray() stream.extend(message.pack_object(len(folder), unsignedint=True)) for fileinfo in folder: stream.extend(bytes([1])) stream.extend(message.pack_object(fileinfo[0])) stream.extend( message.pack_object(fileinfo[1], unsignedlonglong=True)) if fileinfo[2] is not None and fileinfo[3] is not None: stream.extend(message.pack_object('mp3')) stream.extend(message.pack_object(3)) stream.extend(message.pack_object(0)) try: stream.extend( message.pack_object(fileinfo[2][0], unsignedint=True)) except Exception: # Invalid bitrate stream.extend(message.pack_object(0)) stream.extend(message.pack_object(1)) try: stream.extend( message.pack_object(fileinfo[3], unsignedint=True)) except Exception: # Invalid length stream.extend(message.pack_object(0)) stream.extend(message.pack_object(2)) try: stream.extend(message.pack_object(fileinfo[2][1])) except Exception: # Invalid VBR value stream.extend(message.pack_object(0)) else: stream.extend(message.pack_object('')) stream.extend(message.pack_object(0)) return stream
def get_dir_stream(self, dir): """ Pack all files and metadata in directory """ message = slskmessages.SlskMessage() stream = bytearray() stream.extend(message.packObject(len(dir))) for fileinfo in dir: stream.extend(bytes([1])) stream.extend(message.packObject(fileinfo[0])) stream.extend( message.packObject(fileinfo[1], unsignedlonglong=True)) if fileinfo[2] is not None: try: stream.extend(message.packObject('mp3')) stream.extend(message.packObject(3)) stream.extend(message.packObject(0)) stream.extend(message.packObject(fileinfo[2][0])) stream.extend(message.packObject(1)) stream.extend(message.packObject(fileinfo[3])) stream.extend(message.packObject(2)) stream.extend(message.packObject(fileinfo[2][1])) except Exception: log.add( _( "Found meta data that couldn't be encoded, possible corrupt file: '%(file)s' has a bitrate of %(bitrate)s kbs, a length of %(length)s seconds and a VBR of %(vbr)s" % { 'file': fileinfo[0], 'bitrate': fileinfo[2][0], 'length': fileinfo[3], 'vbr': fileinfo[2][1] })) stream.extend(message.packObject('')) stream.extend(message.packObject(0)) else: stream.extend(message.packObject('')) stream.extend(message.packObject(0)) return stream