Sharing a simple script for converting subtitles

2 replies [Last post]
GNUser
Offline
Joined: 07/17/2013

Hey guys,

Just thought this could be useful for other people out there.
When you download a youtube closed caption (subtitles) it usually comes in WebVTT format and encoded as UTF-8. That is a problem since many old media player boxes cannot play those subtitles.
So I found a python script on GitHub that converts VTT to SRT and I made a bash script that takes care of the encoding. I also made it so that lines larger than 50 characters are cut in two, since some videos that I watch were subbed without consideration for line length, which could also be a problem. If someone thinks 50 is a wrong number to use please share with us and adjust the script accordingly to your needs.
Simply run ./ytsubs.sh and all VTT files will be converted to SRT ones, with proper encoding and line length. Original files are not deleted.

As I have mentioned before, you are free to use my scripts for whatever you need them, but seeing as the original python script was not mine and is GPL-V3 licensed I will just consider that all is under the same conditions. Is it appropriate?

Hope this helps.

P.S.: I tried attaching the files as a ZIP file which was 5kB but Trisquel Forum refused it. I used TAR file which is 20kB. ZIP should be allowed since it's smaller.

AttachmentSize
ytsubs.tar20 KB
GNUser
Offline
Joined: 07/17/2013

Ups... sorry, I just noticed that it only works if the VTT file doens't have any spaces between letters. I am working on solving it now. Will upload new version when it's done.

GNUser
Offline
Joined: 07/17/2013

And here it is, now spaces are no problem at all!
Honestly I believe there might be cases where weird characters will make it malfunction, but as it is, it suits my needs and I don't plan on working on it anymore. Hope this serves someone's needs anyway.

GNUser

AttachmentSize
ytsubs2.tar 20 KB