This Python application reads two VTT (WebVTT) files, combines their entries based on specific logic, and writes the combined entries to an Excel file. The application uses the openpyxl
library to create and manipulate the Excel file.
- Parses VTT files to extract timestamps and values.
- Combines entries from two VTT files based on their timestamps.
- Writes the combined entries to an Excel file with columns for source and translated timestamps and values.
- Adds additional "Reviewer 1 Suggestion" and "Reviewer 2 Suggestion" columns in the Excel file.
- Python 3.x
openpyxl
library
-
Clone the repository or download the script:
git clone https://github.com/yourusername/vtt-to-excel.git cd vtt-to-excel
-
Install the required library:
pip install openpyxl
Or, if using
pip3
for Python 3:pip3 install openpyxl
-
Prepare your VTT files:
- Ensure you have two VTT files:
source.vtt
andtranslated.vtt
.
- Ensure you have two VTT files:
-
Run the Python script:
python convertionvtt.py
Or, if using Python 3:
python3 convertionvtt.py
-
Check the output:
- The script will generate an Excel file named
TheOutput.xlsx
in the same directory.
- The script will generate an Excel file named
This function reads a VTT file and parses the entries to extract timestamps and values.
This function combines the source and translated entries based on the following logic:
- When
Source Timestamp
equalsTranslated Timestamp
, they are placed on the same row. - When
Source Timestamp
is greater thanTranslated Timestamp
, the translated timestamp values are kept, and the source timestamp and source value are left empty/blank for that row. - When
Source Timestamp
is less thanTranslated Timestamp
, the source timestamp values are kept, and the translated timestamp and translated value are left empty/blank for that row.
This function writes the combined entries to an Excel file using the openpyxl
library. It creates a new Excel file with columns for source and translated timestamps and values, and additional "Reviewer 1 Suggestion" and "Reviewer 2 Suggestion" columns.
This function orchestrates the process by calling the above functions and printing a success message.
-
Sample
source.vtt
:00:00:01.000 --> 00:00:05.000 Hello, world! 00:00:06.000 --> 00:00:10.000 This is a test.
-
Sample
translated.vtt
:00:00:01.000 --> 00:00:05.000 Hola, mundo! 00:00:07.000 --> 00:00:11.000 Esto es una prueba.
-
Generated
TheOutput.xlsx
:Source Timestamp Source Value Translated Timestamp Translated Value Reviewer 1 Suggestion Reviewer 2 Suggestion 00:00:01.000 Hello, world! 00:00:01.000 Hola, mundo! 00:00:06.000 This is a test. 00:00:07.000 Esto es una prueba.
This Python application reads a VTT (WebVTT) file called translated.vtt
, adds 00:00:03
to every timestamp, and writes the modified content to a new VTT file called translatedPlusDisclaimer.vtt
. Any other value which is not a timestamp remains unchanged.
- Parses VTT files to extract timestamps.
- Adds a specified number of seconds (
00:00:03
) to each timestamp. - Writes the modified timestamps and other unchanged content to a new VTT file.
- Python 3.x
-
Prepare your VTT file:
- Ensure you have a VTT file named
translated.vtt
in the same directory as the script.
- Ensure you have a VTT file named
-
Run the Python script:
- Open a terminal and navigate to the directory where the script is saved.
- Run the script using Python:
Or, if using Python 3:
python AddDisclaimer.py
python3 AddDisclaimer.py
-
Check the output:
- The script will generate a new VTT file named
translatedPlusDisclaimer.vtt
in the same directory.
- The script will generate a new VTT file named
This function parses a VTT timestamp string into hours, minutes, and seconds, adds the specified number of seconds, and returns the new timestamp string in the same format.
This function reads the input VTT file line by line. For lines containing timestamps (-->
), it parses the start and end times, adds the specified number of seconds, and writes the modified timestamps to the output file. For other lines, it writes them unchanged to the output file.
This function orchestrates the process by defining the input and output file names and the number of seconds to add. It calls the add_disclaimer_to_vtt
function to process the VTT file and prints a success message.
-
Sample
translated.vtt
:WEBVTT 00:00:01.000 --> 00:00:05.000 Hello, world! 00:00:06.000 --> 00:00:10.000 This is a test.
-
Generated
translatedPlusDisclaimer.vtt
:WEBVTT 00:00:04.000 --> 00:00:08.000 Hello, world! 00:00:09.000 --> 00:00:13.000 This is a test.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
For any questions or suggestions, please contact @fatenhealy [email protected].