def _find_id3v1(fileobj):
 extra_read = 'APETAGEX'.index('TAG')
 try:
  fileobj.seek(((-128) - extra_read), 2)
 except IOError as e:
  if (e.errno == errno.EINVAL):
   fileobj.seek(0, 0)
  else:
   raise
 data = fileobj.read((128 + extra_read))
 try:
  idx = data.index('TAG')
 except ValueError:
  return (None, 0)
 else:
  try:
   ape_idx = data.index('APETAGEX')
  except ValueError:
   pass
  else:
   if (idx == (ape_idx + extra_read)):
    return (None, 0)
  tag = ParseID3v1(data[idx:])
  if (tag is None):
   return (None, 0)
  offset = (idx - len(data))
  return (tag, offset)

def _find_id3v1 ( fileobj ) : extra_read = 'APETAGEX' . index ( 'TAG' ) try : fileobj . seek ( ( ( - 128 ) - extra_read ) , 2 ) except IOError as e : if ( e . errno == errno . EINVAL ) : fileobj . seek ( 0 , 0 ) else : raise data = fileobj . read ( ( 128 + extra_read ) ) try : idx = data . index ( 'TAG' ) except ValueError : return ( None , 0 ) else : try : ape_idx = data . index ( 'APETAGEX' ) except ValueError : pass else : if ( idx == ( ape_idx + extra_read ) ) : return ( None , 0 ) tag = ParseID3v1 ( data [ idx : ] ) if ( tag is None ) : return ( None , 0 ) offset = ( idx - len ( data ) ) return ( tag , offset )
returns a tuple of or offset mainly because we used to write too short tags in some cases and we need the offset to delete them .