Created
July 30, 2022 14:41
-
-
Save premist/7386d353209675c3a245d3af7af00ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts full name font specification on .ass subtitle to | |
# PostScript name to be used with ffmpeg+coretext on macOS | |
# coretext can't locate "맑은 고딕" (display name / full name) specified on ass file, | |
# however it can locate when "MalgunGothicRegular" (postscript name) is specified. | |
ASS_PATH = ARGV[0] | |
NEWASS_PATH = ARGV[1] | |
FONTS_DIR = ARGV[2] | |
unless ASS_PATH && NEWASS_PATH && FONTS_DIR | |
puts "Usage: assfontmatch.rb subtitle.ass newsubtitle.ass ./fonts" | |
exit 0 | |
end | |
FC_SCAN_PATH = "/opt/homebrew/Cellar/fontconfig/2.14.0/bin/fc-scan" | |
FC_SCAN_CMD = "#{FC_SCAN_PATH} --format=\"%{fullname}\n%{postscriptname}\"" | |
ass = File.read(ASS_PATH) | |
Dir["#{FONTS_DIR}/*"].each do |font| | |
full_names, postscript_name = `#{FC_SCAN_CMD} #{font}`.split("\n") | |
full_names.split(",").each do |full_name| | |
# Match "양재난초체M" even when "양재난초체m" is specified on ass file | |
regexp = Regexp.new(Regexp.escape(full_name), Regexp::IGNORECASE) | |
ass.gsub!(regexp, postscript_name) | |
end | |
end | |
File.write(NEWASS_PATH, ass) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment