Skip to content

Instantly share code, notes, and snippets.

@Sen
Created November 7, 2022 09:30
Show Gist options
  • Save Sen/a47dab5f9929dd374f41354c8ad57c24 to your computer and use it in GitHub Desktop.
Save Sen/a47dab5f9929dd374f41354c8ad57c24 to your computer and use it in GitHub Desktop.
fix subtitle
#!/usr/bin/env ruby
# sync subtitle with https://github.com/smacke/ffsubsync
video_ext = %w(mp4 mkv avi)
subtitle_ext = %w(srt ssa ass)
work_hash = []
files = Dir[Dir.pwd + '/*']
video_files = files.select do |file_name|
video_ext.include?(file_name.split('.')[-1])
end
video_files.each do |filename|
if /s\d+?e(\d+)/ =~ filename.downcase
number = $1
subtitle_filename = files.select do |name|
subtitle_ext.include?(name.split('.')[-1]) && name.include?(number) && !name.include?('fixed')
end[0]
ext = subtitle_filename.split('.')[-1]
system "ffs #{filename} -i #{subtitle_filename} -o #{Dir.pwd}/fixed_#{number}.#{ext}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment