diff --git a/removeads.py b/removeads.py index b8320fb..4af6baa 100755 --- a/removeads.py +++ b/removeads.py @@ -480,11 +480,11 @@ def parseRBSPTrailingBits(buf, bitPosition): bitPosition, one = readBit(buf, bitPosition) if one==0: - raise(Exception('Stop bit should be equal to one. Read: %d' % one)) + raise Exception('Stop bit should be equal to one. Read: %d' % one) while bitPosition%8 != 0: bitPosition, zero = readBit(buf, bitPosition) if zero==1: - raise(Exception('Trailing bit should be equal to zero')) + raise Exception('Trailing bit should be equal to zero') return bitPosition @@ -514,7 +514,7 @@ def moreRBSPData(buf, bitPosition): break if not found: - raise(Exception('Impossible to find trailing stop bit !')) + raise Exception('Impossible to find trailing stop bit !') # No more data if bitPosition == pos: @@ -910,13 +910,13 @@ class SPS: # NAL Unit SPS bitPosition, zero = readBit(buf, bitPosition) if zero != 0: - raise(Exception('Reserved bit is not equal to 0: %d' % zero )) + raise Exception('Reserved bit is not equal to 0: %d' % zero ) bitPosition, nal_ref_idc = readBits(buf, bitPosition,2) if nal_ref_idc != 3: - raise(Exception('NAL ref idc is not equal to 3: %d' % nal_ref_idc )) + raise Exception('NAL ref idc is not equal to 3: %d' % nal_ref_idc ) bitPosition, nal_unit_type = readBits(buf, bitPosition,5) if nal_unit_type != 7: - raise(Exception('NAL unit type is not a SPS: %d' % nal_unit_type )) + raise Exception('NAL unit type is not a SPS: %d' % nal_unit_type ) bitPosition, self.profile_idc = readByte(buf, bitPosition) bitPosition, self.constraint_set0_flag = readBit(buf,bitPosition) @@ -927,7 +927,7 @@ class SPS: bitPosition, self.constraint_set5_flag = readBit(buf,bitPosition) bitPosition, v = readBits(buf, bitPosition, 2) if v!=0: - raise(Exception('Reserved bits different from 0b00: %x' % v)) + raise Exception('Reserved bits different from 0b00: %x' % v) bitPosition, self.level_idc = readByte(buf, bitPosition) bitPosition, self.seq_parameter_set_id = readUnsignedExpGolomb(buf, bitPosition) if self.profile_idc in [44, 83, 86, 100, 110, 118, 122, 128, 134, 135, 138, 139, 244]: @@ -1111,13 +1111,13 @@ class PPS: # NAL Unit PPS bitPosition, zero = readBit(buf, bitPosition) if zero != 0: - raise(Exception('Reserved bit is not equal to 0: %d' % zero )) + raise Exception('Reserved bit is not equal to 0: %d' % zero ) bitPosition, nal_ref_idc = readBits(buf, bitPosition,2) if nal_ref_idc != 3: - raise(Exception('NAL ref idc is not equal to 3: %d' % nal_ref_idc )) + raise Exception('NAL ref idc is not equal to 3: %d' % nal_ref_idc ) bitPosition, nal_unit_type = readBits(buf, bitPosition,5) if nal_unit_type != 8: - raise(Exception('NAL unit type is not a PPS: %d' % nal_unit_type )) + raise Exception('NAL unit type is not a PPS: %d' % nal_unit_type ) bitPosition, self.pic_parameter_set_id = readUnsignedExpGolomb(buf, bitPosition) bitPosition, self.seq_parameter_set_id = readUnsignedExpGolomb(buf, bitPosition) @@ -1245,7 +1245,7 @@ class PPS: for i in range(0, nbMatrices): matrix = self.pic_scaling_list[i] logger.info("Retrieved pic scaling matrix: %s %d" % (matrix, len(matrix))) - present = (len(matrix)!=0) + present = len(matrix)!=0 logger.info("Matrix is present: %s" % present) bitPosition = writeBoolean(buf, bitPosition, present) if present: @@ -1293,17 +1293,17 @@ class AVCDecoderConfiguration: bitPosition, self.AVCLevelIndication = readByte(buf, bitPosition) bitPosition, v = readBits(buf, bitPosition, 6) if v != 0b111111: - raise(Exception('Reserved bits are not equal to 0b111111: %x' % v )) + raise Exception('Reserved bits are not equal to 0b111111: %x' % v ) bitPosition, self.lengthSizeMinusOne = readBits(buf, bitPosition, 2) bitPosition, v = readBits(buf, bitPosition, 3) if v != 0b111: - raise(Exception('Reserved bits are not equal to 0b111: %x' % v)) + raise Exception('Reserved bits are not equal to 0b111: %x' % v) bitPosition, self.numOfSequenceParameterSets= readBits(buf, bitPosition, 5) logger.debug('Number of SPS: %d' % self.numOfSequenceParameterSets) for i in range(0,self.numOfSequenceParameterSets): bitPosition, length = readWord(buf, bitPosition) if bitPosition % 8 != 0: - raise(Exception('SPS is not located at a byte boundary: %d' % bitPosition )) + raise Exception('SPS is not located at a byte boundary: %d' % bitPosition ) sps = SPS() sodb = RBSP2SODB(buf[floor(bitPosition/8):]) @@ -1323,7 +1323,7 @@ class AVCDecoderConfiguration: for i in range(0,self.numOfPictureParameterSets): bitPosition, length = readWord(buf, bitPosition) if bitPosition % 8 != 0: - raise(Exception('PPS is not located at a byte boundary: %d' % bitPosition )) + raise Exception('PPS is not located at a byte boundary: %d' % bitPosition ) pps = PPS() sodb = RBSP2SODB(buf[floor(bitPosition/8):]) @@ -1342,15 +1342,15 @@ class AVCDecoderConfiguration: if self.AVCProfileIndication in [100, 110, 122, 144]: bitPosition, reserved = readBits(buf, bitPosition, 6) if reserved != 0b111111: - raise(Exception('Reserved bits are different from 111111: %x' % reserved)) + raise Exception('Reserved bits are different from 111111: %x' % reserved) bitPosition, self.chroma_format = readBits(buf, bitPosition, 2) bitPosition, reserved = readBits(buf, bitPosition, 5) if reserved != 0b11111: - raise(Exception('Reserved bits are different from 11111: %x' % reserved)) + raise Exception('Reserved bits are different from 11111: %x' % reserved) bitPosition, self.bit_depth_luma_minus8 = readBits(buf, bitPosition, 3) bitPosition, reserved = readBits(buf, bitPosition, 5) if reserved != 0b11111: - raise(Exception('Reserved bits are different from 11111: %x' % reserved)) + raise Exception('Reserved bits are different from 11111: %x' % reserved) bitPosition, self.bit_depth_chroma_minus8 = readBits(buf, bitPosition, 3) bitPosition, self.numOfSequenceParameterSetExt = readByte(buf, bitPosition) for i in range(0, self.numOfSequenceParameterSetExt): @@ -1422,28 +1422,28 @@ class AVCDecoderConfiguration: def merge(self, config): # Check config compatibility if self.configurationVersion != config.configurationVersion: - raise(Exception('Configuration versions are different: %d vs %s' % (self.configurationVersion, config.configurationVersion))) + raise Exception('Configuration versions are different: %d vs %s' % (self.configurationVersion, config.configurationVersion)) if self.AVCProfileIndication != config.AVCProfileIndication: - raise(Exception('AVC profiles are different: %d vs %s' % (self.AVCProfileIndication, config.AVCProfileIndication))) + raise Exception('AVC profiles are different: %d vs %s' % (self.AVCProfileIndication, config.AVCProfileIndication)) if self.profile_compatibility != config.profile_compatibility: - raise(Exception('Profile compatilities are different: %d vs %s' % (self.profile_compatibility, config.profile_compatibility))) + raise Exception('Profile compatilities are different: %d vs %s' % (self.profile_compatibility, config.profile_compatibility)) if self.AVCLevelIndication != config.AVCLevelIndication: - raise(Exception('Level indications are different: %d vs %s' % (self.AVCLevelIndication, config.AVCLevelIndication))) + raise Exception('Level indications are different: %d vs %s' % (self.AVCLevelIndication, config.AVCLevelIndication)) if self.lengthSizeMinusOne != config.lengthSizeMinusOne: - raise(Exception('Length units are different: %d vs %s' % (self.lengthSizeMinusOne, config.lengthSizeMinusOne))) + raise Exception('Length units are different: %d vs %s' % (self.lengthSizeMinusOne, config.lengthSizeMinusOne)) if self.chroma_format != config.chroma_format: - raise(Exception('Colour format are different: %d vs %s' % (self.chroma_format, config.chroma_format))) + raise Exception('Colour format are different: %d vs %s' % (self.chroma_format, config.chroma_format)) if self.bit_depth_luma_minus8 != config.bit_depth_luma_minus8: - raise(Exception('Depth of luminance are different: %d vs %s' % (self.bit_depth_luma_minus8, config.bit_depth_luma_minus8))) + raise Exception('Depth of luminance are different: %d vs %s' % (self.bit_depth_luma_minus8, config.bit_depth_luma_minus8)) if self.bit_depth_chroma_minus8 != config.bit_depth_chroma_minus8: - raise(Exception('Depth of chromaticity are different: %d vs %s' % (self.bit_depth_chroma_minus8, config.bit_depth_luma_minus8))) + raise Exception('Depth of chromaticity are different: %d vs %s' % (self.bit_depth_chroma_minus8, config.bit_depth_luma_minus8)) for spsid in config.sps: sps = config.sps[spsid] if spsid in self.sps: localsps = self.sps[spsid] if sps!=localsps: - raise(Exception('Profile are not compatible. They contain two different SPS with the same identifier (%d): %s\n%s\n' % (spsid, localsps, sps))) + raise Exception('Profile are not compatible. They contain two different SPS with the same identifier (%d): %s\n%s\n' % (spsid, localsps, sps)) self.sps[spsid] = sps self.numOfSequenceParameterSets = len(self.sps) @@ -1453,7 +1453,7 @@ class AVCDecoderConfiguration: if ppsid in self.pps: localpps = self.pps[ppsid] if pps!=localpps: - raise(Exception('Profile are not compatible. They contain two different PPS with the same identifier (%d): %s\n%s\n' % (ppsid, localpps, pps))) + raise Exception('Profile are not compatible. They contain two different PPS with the same identifier (%d): %s\n%s\n' % (ppsid, localpps, pps)) self.pps[ppsid] = pps self.numOfPictureParameterSets = len(self.pps) @@ -1462,12 +1462,12 @@ class AVCDecoderConfiguration: def parseCodecPrivate(codecPrivateData): if codecPrivateData[0] != 0x63: - raise(Exception('Matroska header is wrong: %x' % codecPrivateData[0])) + raise Exception('Matroska header is wrong: %x' % codecPrivateData[0]) if codecPrivateData[1] != 0xA2: - raise(Exception('Matroska header is wrong: %x' % codecPrivateData[1])) + raise Exception('Matroska header is wrong: %x' % codecPrivateData[1]) length = codecPrivateData[2] if length == 0: - raise(Exception('Matroska length cannot start with zero byte.')) + raise Exception('Matroska length cannot start with zero byte.') for nbZeroes in range(0,8): b = readBit(codecPrivateData[2:], nbZeroes) if b != 0: @@ -1493,14 +1493,14 @@ def getAvcConfigFromH264(inputFile): bitPosition = 0 bitPosition, startCode = readLong(sodb, bitPosition) if startCode != 1: - raise(Exception('Starting code not detected: %x' % startCode)) + raise Exception('Starting code not detected: %x' % startCode) sps = SPS() bitLength = sps.fromBytes(sodb[4:]) bitPosition+=bitLength bitPosition, startCode = readLong(sodb, bitPosition) if startCode != 1: - raise(Exception('Starting code not detected: %x' % startCode)) + raise Exception('Starting code not detected: %x' % startCode) pps = PPS() bitLength = pps.fromBytes(sodb[floor(bitPosition/8):], sps.chroma_format_idc) logger.debug(pps) @@ -1553,7 +1553,7 @@ def parseMKVTree(mkvinfo, inputFile): else: position = int(m.group('position')) size = int(m.group('size')) - root = (m.group('root')!=None) + root = m.group('root')!=None if root: depth = 0 else: @@ -2337,7 +2337,7 @@ def extractSound(ffmpeg, inputFile, begin, outputFileName, packetDuration, subCh lseek(outfd, 0, SEEK_SET) sound = read(outfd, length) - if (len(sound) != length): + if len(sound) != length: logger.info("Received %d bytes but %d were expected (channels=%d, freq=%d, packets=%d, duration=%d ms)." % (len(sound), length, nbChannels, sampleRate, nbPackets, packetDuration)) return None, None @@ -2467,7 +2467,7 @@ def extractAllStreams(ffmpeg, ffprobe, inputFile, begin, end, streams, filesPref packets = getFramesInStream(ffprobe, inputFile=inputFile, begin=begin, end=end, streamKind='a', subStreamId=audioID) nbPackets = len(packets) logger.debug("Found %d packets to be extracted from audio track.", nbPackets) - if(nbPackets > 0): + if nbPackets > 0: packetDuration = getPacketDuration(packets[0]) if packetDuration is None: return None