This Python script automates the process of extracting, downloading, and cleaning subtitles from VK video pages. It was created to simplify working with subtitles by removing unnecessary timestamps and blank lines for a compact and readable format.
- Automatically fetches subtitle URLs from VK video pages.
- Generates unique filenames for downloaded subtitles to prevent overwriting existing files.
- Cleans subtitles by removing timestamps and empty lines, leaving only meaningful text.
I developed this tool to help me with the Samsung innovation campus because i wanted to summraize the videos, save time when working with VK subtitles, making them more concise and easier to use. This is especially useful for language learning or content analysis, where cluttered subtitles can be distracting.
- Fetch the Subtitle URL: The script uses Selenium to open the VK video page and find the subtitle URL.
- Download and Clean: Subtitles are downloaded from the URL and cleaned of timestamps and unnecessary lines.
- Save Output: Cleaned subtitles are saved in a uniquely named file (e.g.,
subtitles.vtt1,subtitles.vtt2, etc.).
- Install the dependencies:
pip install selenium webdriver-manager requests
- Run the script: python script.py
- Enter the VK video URL when prompted.
- Find the cleaned subtitle file in the script's directory.
To keep timestamps in the output:
Remove the following block in the clean_subtitles function:
if not timestamp_pattern.match(line) and not line.startswith("<c>"):
To allow blank lines:
Remove or modify this section:
stripped_line = line.strip()
if stripped_line:
cleaned_lines.append(stripped_line)
To keep subtitles unaltered:
Skip the clean_subtitles function in download_subtitles:
cleaned_content = clean_subtitles(response.content)
Replace with:
cleaned_content = response.content
This project is open-source. Feel free to modify and use it.
- To keep timestamps, the
ifcondition inclean_subtitlesthat filters out timestamp lines should be removed. - To allow blank lines, the
stripped_linelogic can be bypassed. - To keep subtitles unaltered, skip the
clean_subtitlesstep entirely. This involves changing howresponse.contentis handled indownload_subtitles.
