Python音乐播放器?

无聊的时候整了个python带歌词的播放器=-=

Buggggg特别多/特别多

  • 1.需要VSC打开并且用调试模式(不然代码无限循环)
  • 2.歌词时快时慢=-=

配合NeteaseCloudMusicApi实现的 代码写的特别…..

下面放出代码:

import multiprocessing
import requests
import json
import time
import os
import re
import threading
from playsound import playsound

idd = "41645488" #网易云音乐id
apii = "http://127.0.0.1:4000" #NeteaseCloudMusicApi的地址

urlmu = apii+"/song/url?id="+idd
mu = requests.get(urlmu)     
music = json.loads(mu.text)            
musicurl = music["data"]
musicurl11 = json.dumps(musicurl[0])
music = json.loads(musicurl11) 
alll_music = music["url"]



dmu = alll_music
#mudd = requests.get(dmu)
#with open ("music.mp3", "wb") as code:
#        code.write(mudd.content)


#---------------------歌词获取------------------------------
url = apii+"/lyric?id="+idd
r = requests.get(url)     
json = json.loads(r.text)            
lrc = json["lrc"]["lyric"]
s=json["lrc"]["lyric"]
with open ("lyric.lrc", "w") as code:
        code.write(lrc)
#print(lrc)           
for f in os.listdir('.'):
       if 'lyric.lrc' in f:
               lines = open(f).readlines()
               open(f, 'w').writelines(lines[1:])

with open("lyric.lrc", "r") as f:  # 打开文件
    oklrc = f.read()  # 读取文件
#----------------------------------------------------------

第二段:

time.sleep(3)
def task1(): #没用的线程qwq
    time.sleep(99999)
  

def task2():
    #-----------------------歌词解析----------------------------
    musicLrc = oklrc
    LrcDict = {}
    musicLrcList = musicLrc.splitlines()

    for musicLrcLine in musicLrcList:
        musicLrcTime = musicLrcLine.split(']')
        musicLrc = musicLrcTime.pop()

        for LrcTime in musicLrcTime:
            LrcTimeList = LrcTime[1:]
            timeList = LrcTimeList.split(':')
            times = float(timeList[0]) * 60 + float(timeList[1])
            LrcDict[times] = musicLrc
    timeSort = list(LrcDict)
    timeSort.sort()
    time.sleep(timeSort[0])
    timeSleep = timeSort[0]

第三段:

    for i in timeSort:
        print(LrcDict[i])
        time.sleep(i - timeSleep)
        timeSleep = i
    #----------------------------------------------------------


if __name__ == '__main__':
    p1 = multiprocessing.Process(target=task1)  # multiprocessing.Process创建了子进程对象p1
    p2 = multiprocessing.Process(target=task2)  # multiprocessing.Process创建了子进程对象p2
    p1.start()  # 子进程p1启动
    p2.start()  # 子进程p2启动
    print("开始播放")  
    time.sleep(0.5)
    playsound(dmu)

别问我为什么分段 代码贴不上来啊

评论

  1. yimi
    yimi
    Windows Edge 84.0.522.52
    2月前
    2020-8-05 12:01:34

    牛逼!(破音)

  2. ltyec
    ltyec
    Macintosh Safari 13.1
    1月前
    2020-8-13 15:56:16

    强欸!

  3. 呵呵君
    呵呵君
    Android Chrome 71.0.3578.141
    1月前
    2020-8-20 12:36:41

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇