激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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 (172829352@qq.com)
# @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實現在線音樂播放器

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 中文字幕视频在线播放 | 日本aⅴ在线 | 欧美成年人在线视频 | 黄色片网站在线免费观看 | 一夜新娘第三季免费观看 | a黄毛片 | 久久av喷吹av高潮av懂色 | 欧洲成人精品 | 97超级碰碰人国产在线观看 | 亚洲国产一区二区三区 | 国产影视| 进去了(高h) | 在线播放免费播放av片 | 深夜福利视频免费观看 | 美国一级黄色毛片 | 成人免费淫片视频软件 | 欧美综合在线观看 | japanese hot milf free av| 午夜视频在线看 | 黄色大片在线免费看 | 日本网站在线播放 | 国产一级在线观看视频 | 13一14毛片免费看 | xxxx18韩国护士hd老师 | 看国产毛片| 国产一区二区二 | 欧美国产一区二区三区激情无套 | 操网 | 九九热九九热 | 少妇淫片免费一级毛片 | 天堂在线中文资源 | 国产精品久久久久久久模特 | 精品无吗乱吗av国产爱色 | 欧美日韩国产成人在线 | videos真实高潮xxxx | 国产精品一区99 | 国产99一区二区 | 精品国产一区二 | 精品国产高清一区二区三区 | 久久精品一二三区 | 国产精彩视频在线 |