def extract_title(source, path):
 if (u'<!-- title:' in source):
  title = re.findall(u'<!-- title:([^>]*) -->', source)[0].strip()
 elif (u'<h1>' in source):
  match = re.findall(u'<h1>([^<]*)', source)
  title = match[0].strip()[:300]
 else:
  title = os.path.basename(path).replace(u'_', u' ').replace(u'-', u' ').title()
 return title

def extract_title ( source , path ) : if ( u'<!-- title:' in source ) : title = re . findall ( u'<!-- title:([^>]*) -->' , source ) [ 0 ] . strip ( ) elif ( u'<h1>' in source ) : match = re . findall ( u'<h1>([^<]*)' , source ) title = match [ 0 ] . strip ( ) [ : 300 ] else : title = os . path . basename ( path ) . replace ( u'_' , u' ' ) . replace ( u'-' , u' ' ) . title ( ) return title
returns title from &lt;!-- title --&gt; or &lt;h1&gt; or path .