Skip to content

Instantly share code, notes, and snippets.

@XueshiQiao
Last active August 21, 2018 00:34
Show Gist options
  • Save XueshiQiao/5992949 to your computer and use it in GitHub Desktop.
Save XueshiQiao/5992949 to your computer and use it in GitHub Desktop.
combine WWDC subtitle files (fileSequence*.webvtt) to a srt file.
#!/usr/bin/ruby
docPath = "wwdc_srts"
#exclude . and .. folder
folders = Dir.entries(docPath).select{|folder| folder.to_i > 0}
folders.each{ |folder|
print folder
print "\n"
sequenceFilePath = docPath + "/" + folder
sequenceFiles = Dir.entries(sequenceFilePath).select{|file| file.length > 12}
fileCount = sequenceFiles.count
f = File.new(docPath + "/" + folder + ".srt", "w")
#combine sequence files to xxx.srt, xxx is video num, such as 210.srt.
for i in 0..fileCount-1
out = File.open(sequenceFilePath + "/" + "fileSequence" + i.to_s + ".webvtt", "r");
f.write(out.read);
out.close;
end
f.close
}
@XueshiQiao
Copy link
Author

@lexrus Cooool 受教

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment