Created
December 30, 2019 04:02
-
-
Save nicholastay/47738e98c691dda55de6af38c6443094 to your computer and use it in GitHub Desktop.
Quick tool to put together timed lyr file and a translation of the song given same lines
This file contains hidden or 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
import sys | |
import re | |
lyrReg = re.compile('^\\[\\d+:\\d+\\.\\d+\\]\\s+?$', re.MULTILINE) | |
def readInFile(filename, isTiming=True): | |
out = [] | |
with open(filename, 'r', encoding='UTF-8') as f: | |
for line in f: | |
line = line.strip() | |
if not line: | |
continue | |
if isTiming and lyrReg.match(line): | |
continue | |
out.append(line) | |
return out | |
def addTranslate(krtext, entext): | |
kr = readInFile(krtext, True) | |
en = readInFile(entext, False) | |
if len(kr) != len(en): | |
raise Exception('Lyric lines mismatch! Difference: ' + str(len(kr)-len(en))) | |
for i in range(len(kr)): | |
if en[i] == '%skip%': | |
continue | |
kr[i] += '\n' + en[i] | |
return(kr) | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print('Usage: translate.py lyricsWithTiming.txt langToAdd.txt') | |
tr = addTranslate(sys.argv[1], sys.argv[2]) | |
print('\n'.join(tr)) | |
#print(readInFile('kr.lrc')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment