def read_torrent_name(torrent_file, default_name=None):
 try:
  with open(torrent_file, 'rb') as fp:
   torrent_info = bdecode(fp.read())
 except IOError as e:
  logger.error('Unable to open torrent file: %s', torrent_file)
  return
 if torrent_info:
  try:
   return torrent_info['info']['name']
  except KeyError:
   if default_name:
    logger.warning("Couldn't get name from torrent file: %s. Defaulting to '%s'", e, default_name)
   else:
    logger.warning("Couldn't get name from torrent file: %s. No default given", e)
 return default_name

def read_torrent_name ( torrent_file , default_name = None ) : try : with open ( torrent_file , 'rb' ) as fp : torrent_info = bdecode ( fp . read ( ) ) except IOError as e : logger . error ( 'Unable to open torrent file: %s' , torrent_file ) return if torrent_info : try : return torrent_info [ 'info' ] [ 'name' ] except KeyError : if default_name : logger . warning ( "Couldn't get name from torrent file: %s. Defaulting to '%s'" , e , default_name ) else : logger . warning ( "Couldn't get name from torrent file: %s. No default given" , e ) return default_name
read the torrent file and return the torrent name .