def matroska_bps_to_bitrate(bps):
 m = re.search(u'([\\d.]+)\\s*(\\D.*)', bps)
 if m:
  (bps, suffix) = m.groups()
  if (u'kbit' in suffix):
   return (float(bps) * 1024)
  elif (u'kbyte' in suffix):
   return ((float(bps) * 1024) * 8)
  elif (u'byte' in suffix):
   return (float(bps) * 8)
  elif ((u'bps' in suffix) or (u'bit' in suffix)):
   return float(bps)
 if bps.replace(u'.', u'').isdigit():
  if (float(bps) < 30000):
   return (float(bps) * 1024)
  return float(bps)

def matroska_bps_to_bitrate ( bps ) : m = re . search ( u'([\\d.]+)\\s*(\\D.*)' , bps ) if m : ( bps , suffix ) = m . groups ( ) if ( u'kbit' in suffix ) : return ( float ( bps ) * 1024 ) elif ( u'kbyte' in suffix ) : return ( ( float ( bps ) * 1024 ) * 8 ) elif ( u'byte' in suffix ) : return ( float ( bps ) * 8 ) elif ( ( u'bps' in suffix ) or ( u'bit' in suffix ) ) : return float ( bps ) if bps . replace ( u'.' , u'' ) . isdigit ( ) : if ( float ( bps ) < 30000 ) : return ( float ( bps ) * 1024 ) return float ( bps )
tries to convert a free-form bps string into a bitrate .