Created
June 20, 2020 14:05
-
-
Save south1907/dae4d547d46391d0ebc60659d18a3b83 to your computer and use it in GitHub Desktop.
Read file lyric of zingmp3
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
#!usr/bin/python3 | |
# created by namph | |
# link lyric file: https://zingmp3.vn/api/song/get-lyric?id=ZWAFE897&ctime=1592657865&sig=a79a3de95632ac37d116c01755f216e965784f2cf2ce13dac1ced62a3f08430438691484848bf685903c363a367eec12d1379c13f6d25288488b59b2fac1b091&api_key=38e8643fb0dc04e8d65b99994d3dafff | |
import json | |
import time | |
import os | |
with open('banhmikhong.json', 'r') as f: | |
song = json.loads(f.read()) | |
my_string = '' | |
current_time = 0 | |
# cần thêm thời gian delay vì xử lý mất một vài mili giây (ms) | |
delay_time = 4 | |
end_time_word = 0 | |
for line in song['data']: | |
words = line['words'] | |
for w in words: | |
start_time_word = w['startTime'] | |
if end_time_word != 0: | |
sleep_word = start_time_word - end_time_word | |
time.sleep(sleep_word/1000) | |
end_time_word = w['endTime'] | |
word = w['data'] | |
# tách và in theo từng ký tự để hiển thị mượt hơn, không thì chỉ hiển thị theo từng từ | |
# ở phần gửi qua Messenger sẽ gửi theo từng từ vì thời gian xử lý khá lâu | |
split_word = [char for char in word] | |
time_sleep = end_time_word - start_time_word | |
# cần sleep ít hơn, 1 lượng bằng thời gian delay (nhân với số lần in ra màn hình) | |
time_sleep -= delay_time * len(split_word) | |
time_sleep = time_sleep/1000 | |
if time_sleep < 0: | |
time_sleep = 0 | |
for c in split_word: | |
os.system('clear') | |
my_string += c | |
print(my_string) | |
time.sleep(time_sleep/len(split_word)) | |
my_string += " " | |
my_string += "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment