Created
October 29, 2010 07:10
-
-
Save ozten/653067 to your computer and use it in GitHub Desktop.
change_lrc_offset.py 5 heal_the_world.lrc will update the karaoke lyrics adding a 5 second delay
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
| #!/usr/bin/python | |
| import re | |
| import sys | |
| def offset(line, add_seconds): | |
| m = re.match("^\[(\d\d):(\d\d)(?:\.\d\d)?\](.*)$", line) | |
| if m: | |
| (r_min, r_sec, lyrics) = m.groups() | |
| minutes = int(r_min) | |
| seconds = int(r_sec) | |
| seconds += add_seconds | |
| minutes += seconds / 60 | |
| seconds = seconds % 60 | |
| return "[%02d:%02d] %s" % (minutes, seconds, lyrics) | |
| else: | |
| return line | |
| def main(argv): | |
| seconds = int(argv[1]) | |
| output = "%s_%d.lrc" % (argv[2][0:-4], seconds) | |
| print("Adjusting %s by %d seconds and placing output in %s" % (argv[2], seconds, output)) | |
| lrc = open(argv[2], 'r') | |
| new_lrc = open(output, 'w') | |
| line = lrc.readline() | |
| while line: | |
| new_lrc.write("%s\n" % offset(line, seconds)) | |
| line = lrc.readline() | |
| lrc.close() | |
| new_lrc.close() | |
| if __name__ == '__main__': | |
| if len(sys.argv) == 3: | |
| main(sys.argv) | |
| else: | |
| print("USAGE: %s 3 some_song.lrc\n\tWill change the offset by 3 Seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment