Skip to content

Instantly share code, notes, and snippets.

@louisroyer
Created July 28, 2025 08:21
Show Gist options
  • Select an option

  • Save louisroyer/bf4ba6d72f3cd1f1d992373c2aa706bb to your computer and use it in GitHub Desktop.

Select an option

Save louisroyer/bf4ba6d72f3cd1f1d992373c2aa706bb to your computer and use it in GitHub Desktop.
Check for synched off-vocal versions
#!/usr/bin/env python3
'''Check for synched off-vocal versions'''
import os
import sys
import hashlib
import json
BUF_SIZE = 65535
OFF_VOCAL_TAG = 'c0cc87b9-55b9-40f0-878a-fbb9e34c151e'
def find_off_vocal(directory):
'''Returns list of .ass for off vocal karaokes'''
file_list = []
karajson_directory = os.path.join(directory, 'karaokes')
for filename in os.listdir(karajson_directory):
if not filename.endswith('.kara.json'):
continue
with open(os.path.join(karajson_directory, filename), 'r', encoding='utf-8') as file:
karajson = json.load(file)
if not 'versions' in karajson['data']['tags']:
continue
if OFF_VOCAL_TAG in karajson['data']['tags']['versions']:
file_list.append(karajson['medias'][0]['lyrics'][0]['filename'])
print(f'Found {len(file_list)} off-vocal files.')
return file_list
def compute_hashes(directory):
'''Computes hashes of all .ass'''
out = {}
ass_directory = os.path.join(directory, 'lyrics')
for filename in os.listdir(ass_directory):
with open(os.path.join(ass_directory, filename), 'rb') as file:
sha512 = hashlib.sha512()
while True:
data = file.read(BUF_SIZE)
if not data:
break
sha512.update(data)
out[filename] = sha512.hexdigest()
return out
def main(directory):
'''Main function'''
off_vocals = find_off_vocal(directory)
hashes = compute_hashes(directory)
total_count = 0
sync = 0
out_sync = 0
trio = 0
for off_vocal_kara in off_vocals:
off_vocal_hash = hashes[off_vocal_kara]
found = False
total_count += 1
for file, file_hash in hashes.items():
if file_hash == off_vocal_hash and off_vocal_kara != file:
print(f'Found synchronized lyrics for {off_vocal_kara}: {file_hash}')
if found:
trio += 1
else:
found = True
sync += 1
if not found:
out_sync += 1
print(f'No Synchronized lyric for {off_vocal_kara}')
print(f'Total: {total_count}, sync: {sync}, out of sync: {out_sync}, trio: {trio}')
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.exit(1)
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment