def process_file(filepath):
    '\n    Rewrite links in `filepath` as follows: /some/path/index.html --> /some/path/\n    '
    if filepath.endswith('.html'):
        with open(filepath, 'r') as htmlfile:
            page = bs4.BeautifulSoup(htmlfile.read(), 'html.parser')
        links = page.find_all('a')
        for link in links:
            href = link['href']
            if href.endswith('index.html'):
                href = href.replace('index.html', '')
                link['href'] = href
        video = page.find('video')
        if video:
            source = video.find('source')
            main_file = source['src']
            tracks = video.find_all('track')
            if tracks:
                for track in tracks:
                    new_src = main_file.replace('.mp4', '.vtt')
                    track['src'] = new_src
        with open(filepath, 'w') as htmlfile:
            html = page.prettify()
            htmlfile.write(html)
Rewrite links in `filepath` as follows: /some/path/index.html --> /some/path/
def process_file(filepath):
    '\n    \n    '
    if filepath.endswith('.html'):
        with open(filepath, 'r') as htmlfile:
            page = bs4.BeautifulSoup(htmlfile.read(), 'html.parser')
        links = page.find_all('a')
        for link in links:
            href = link['href']
            if href.endswith('index.html'):
                href = href.replace('index.html', )
                link['href'] = href
        video = page.find('video')
        if video:
            source = video.find('source')
            main_file = source['src']
            tracks = video.find_all('track')
            if tracks:
                for track in tracks:
                    new_src = main_file.replace('.mp4', '.vtt')
                    track['src'] = new_src
        with open(filepath, 'w') as htmlfile:
            html = page.prettify()
            htmlfile.write(html)