一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python實現在線音樂播放器

Python實現在線音樂播放器

2020-09-22 09:36Donoy Python

這篇文章主要為大家詳細介紹了Python實現在線音樂播放器的相關資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近這幾天,學習了一下python,對于爬蟲比較感興趣,就做了一個簡單的爬蟲項目,使用Python的庫Tkinsert做了一個界面,感覺這個庫使用起來還是挺方便的,音樂的數據來自網易云音樂的一個接口,通過requests模塊,get請求將數據獲得,使用Json模塊進行數據的解析,最終使用python的mp3play庫進行對音樂的在線播放,以下是該程序的源碼。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2016-12-28 21:03:21
# @Author : Donoy ([email protected])
# @Link : http://www.cnblogs.com/Donoy/
# @Version : $Id$
 
from Tkinter import *
import tkMessageBox
import requests
import json
import urllib
import mp3play
import threading
import time
 
def center_window(root, width, height):
 screenwidth = root.winfo_screenwidth()
 screenheight = root.winfo_screenheight()
 size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
 root.geometry(size)
 
def createWnd():
 global root
 global listBox
 global text
 
 root = Tk()
 root.title('-----DMPlayer------來自網易云音樂-----')
 
 center_window(root, 440, 250)
 
 root['background'] = '#C7EDCC'
 
 text = Entry(font='宋體',width=36)
 text.pack()
 button = Button(root,text='搜索',width=18,fg='red',background='#CDCDC1',command=searchM).pack()
 
 listBox = Listbox(root, height=12,width=72,background='#C7EDCC')
 listBox.bind('<Double-Button-1>',play)
 listBox.pack()
 
 root.mainloop()
 
def searchM():
 global m_List
 itemCount = 50
 
 if not text.get():
 tkMessageBox.showinfo('溫馨提示','您可以輸入以下內容進行搜索\n1.歌曲名\n2.歌手名\n3.部分歌詞')
 return
 
 #獲得輸入的歌名
 url = 'http://s.music.163.com/search/get/?type=1&s=%s&limit=%s'%(text.get(),itemCount)
 
 #get請求
 header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'}
 html = requests.get(url,header)
 data = json.loads(html.text)
 m_List = []
 
 try:
 listBox.delete(0,listBox.size())
 for MusicData in data['result']['songs']:
  listBox.insert(END,MusicData['name'] +'------'+'(' +MusicData['artists'][0]['name'] + ')')
  m_List.append(MusicData['audio'])
 except Exception as e:
 tkMessageBox.showinfo('溫馨提示','查詢過程出現錯誤,請重試')
 #print '查詢過程出現錯誤,請重試'
 
 
def play(args):
 try:
 global mp3
 sy = listBox.curselection()[0]
 mp3 = mp3play.load(m_List[int(sy)])
 mp3.play()
 #time.sleep(1000)
 except Exception as e:
 pass
 
 
def main():
 createWnd()
 
 
if __name__ == '__main__':
 main()

程序運行結果:

Python實現在線音樂播放器

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产精品久线观看视频 | futa百合高肉全h | 亚洲高清中文字幕精品不卡 | 91精品综合久久久久久五月天 | 91久久99热青草国产 | 免费一看一级毛片人 | 日本老妇和子乱视频 | 色多多视频网站 | lilisha李丽莎喷水大胆在线 | 久久久久久免费高清电影 | 国产高清路线一路线二2022 | 国产精品刺激好大好爽视频 | 羞羞视频污 | 男人肌肌捅女人肌肌 | 白丝尤物的下面被疯狂蹂躏 | 女仆掀起蕾丝裙被打屁股作文 | 久久久无码精品无码国产人妻丝瓜 | 精品久久久久久无码人妻国产馆 | 国产91青青成人a在线 | 日本午夜大片免费观看视频 | 18性夜影院午夜寂寞影院免费 | 成人国产精品视频频 | 韩国三级年轻小的胰子完整 | 乌克兰一级片 | 欧美男男gaysgays | 国产精品1 | 精品99一区二区三区麻豆 | 美女禁区视频免费观看精选 | 精品综合久久久久久8888 | 欧美日韩精品一区二区三区视频播放 | 亚洲国产综合网 | 女人张开腿 让男人桶个爽 免费观看 | 精品一区二区三区五区六区七区 | 亚洲香蕉伊在人在线观看9 亚洲系列国产系列 | 国产欧美日韩一区二区三区在线 | 欧美一区高清 | 爽好大快深点一视频 | 91精品国产麻豆国产自产在线 | 精品国产自在在线在线观看 | 欧美一区二区三区精品国产 | bl双性小说 |