1. 程式人生 > >歌詞遍歷案例 lrc檔案

歌詞遍歷案例 lrc檔案

程式碼

//A code block import time

musicLrc=""" [00:00.64]背後女人 - 楊千嬅/周柏豪 [00:03.17]詞:Tim Lui [00:03.95]曲:周柏豪 [00:05.30]編曲:周錫漢/黃兆銘 [00:05.63]監製:周錫漢 [00:06.49]OP:Click Music Limited [00:06.65]SP: Music Nation Publishing Company Limited (50%) [00:07.42]OP:Shoot The Lyricist admin by Universal Music Publishing Limited (50%) [00:09.51] [00:15.40]男: [00:16.18]身與心去為明日賓士 [00:20.89]女: [00:22.31]同樣為家栽出暖意 [00:25.98] [00:26.56]誰人在等一雙臂靠倚 [00:30.48]男: [00:31.41]可記起誰日和夜堅持 [00:35.97] [00:36.68]女: [00:37.91]長期用心打點細緻 [00:41.40]原期望枕邊一個 [00:43.95]合: [00:44.47]快樂愜意 [00:47.38]男: [00:49.88]這背影每天沿路照應 [00:54.19]女: [00:55.28]不需得到掌聲 [00:57.90]男: [00:58.73]當天答應 [01:00.45]女: [01:00.81]想兌現著 [01:02.39]男: [01:02.85]一生的笑聲 [01:03.76]女: [01:03.99]一生所愛保證 [01:05.44]男: [01:05.81]偏錯失了 未陪伴細聽 [01:09.27]合: [01:10.19]那些內心的感性 [01:12.61]女: [01:13.98]請不忘重拾步履 [01:16.42]合: [01:17.19]行過最幸福小徑 [01:20.37] [01:34.32]男: [01:34.98]心裡的那小孩亂呼救 [01:39.30]女: [01:41.67]同時在安撫小怪獸 [01:44.54] [01:45.34]如何受壓都不會放手 [01:49.26]男: [01:50.12]懂那心理 脆弱時營救 [01:54.94]合: [01:56.43]這些時間裡 歲月看透 [02:01.02]在背後那份愛 珍惜可會未夠 [02:06.34] [02:07.90]男: [02:08.87]這背影每天沿路照應 [02:12.81]女: [02:14.09]不需得到掌聲 [02:16.65]男: [02:17.75]當天答應 [02:19.11]女: [02:19.58]想兌現著 [02:21.11]男: [02:21.60]一生的笑聲 [02:22.55]女: [02:22.85]一生快樂笑聲 [02:24.08]男: [02:24.49]偏錯失了 未陪伴細聽 [02:27.73]合: [02:28.88]那些內心的感性 [02:31.77]女: [02:32.71]請不忘重拾步履 [02:35.35]合: [02:35.93]行過最幸福小徑 [02:39.37] [02:52.26]女: [02:54.08]所有一切來自愛吧 [02:57.04]男: [02:58.09]不歇息每天 [02:59.39]合: [02:59.94]期待開花 [03:02.07] [03:07.31]男: [03:08.73]這背影每天沿路照應 [03:12.54]女: [03:13.27] [03:13.99]不需得到掌聲 [03:16.40]男: [03:17.51]當天答應 [03:19.18]女: [03:19.54]想兌現著 [03:20.77]男: [03:21.26]每日的笑聲 [03:23.01]女: [03:23.24]每日歡樂笑聲 [03:24.24]男: [03:24.43]不要等到 沒能力細聽 [03:27.96]合: [03:28.84]讓愛未得到呼應 [03:31.34]女: [03:32.56]請堅持重拾步履 [03:35.65]合: [03:36.20]行過最幸福小徑 [03:39.11] [03:42.15]男: [03:46.38]可記起那天門外一吻 [03:50.26]女: [03:52.85]點點的愛可刻骨銘心 [03:55.92]男: [03:56.70]延續著這種相愛 [03:59.35]合: [03:59.87]到白鬢""" print("*"*50) musicLrcList=musicLrc.splitlines() #按行處理 lrcDict={} #runCount=lrcLine.count(’:’) for lrcLine in musicLrcList: lrcLineList=lrcLine.split(’]’) for index in range(len(lrcLineList)-1): timeStr=lrcLineList[index][1:] timeList=timeStr.split(’:’) time1=float(timeList[0])*60+float(timeList[1]) lrcDict[time1]=lrcLineList[-1] print(lrcDict)

allTimeList=[] for t in lrcDict: allTimeList.append(t) allTimeList.sort() print(allTimeList)

“”“while 1: getTime=float(input(“請輸入一個時間”)) for n in range(len(allTimeList)): tempTime=allTimeList[n] if getTime<tempTime: break if n==0: print(“時間太小”) else: print(lrcDict[allTimeList[n-1]]) “”” getTime=0 while 1:

for n in range(len(allTimeList)):
    tempTime = allTimeList[n]
    if getTime < tempTime:
        break
lrc=lrcDict.get(allTimeList[n-1])
if lrc==None:
    pass
else:

    print(lrc)
time.sleep(1)
getTime+=2

"""
if n == 0:
    #print("時間太小")
    pass
else:
    print(lrcDict[allTimeList[n - 1]])
"""