Python Implements---"Easy" online music player

Source: Internet
Author: User

Recently these days, learning a bit of Python, for the crawler is more interested in doing a simple crawler project, using Python library Tkinsert made an interface, feel that the library is very convenient to use, music data from the NetEase Cloud music interface, Through the requests module, GET request to obtain data, using JSON module for data parsing, and finally use the Python Mp3play library for music online playback, the following is the program's source code.

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #@Date: 2016-12-28 21:03:214 #@Author: Donoy ([email protected])5 #@Link: http://www.cnblogs.com/Donoy/6 #@Version: $Id $7 8  fromTkinterImport*9 ImportTkmessageboxTen ImportRequests One ImportJSON A ImportUrllib - ImportMp3play - ImportThreading the Import Time -  -  - defCreatewnd (): +     GlobalRoot -     GlobalListBox +     Globaltext A      atRoot =Tk () -Root.title ('--Dmplayer--default search 100----from NetEase cloud Music---') -Root.geometry ('500x270+600+200') -  -Text = Entry (font='Song Body', width=36) - Text.pack () inButton (root,text='Search', width=18,command=searchm). Pack () -  toListBox = ListBox (Root, height=12,width=72) +Listbox.bind ('<Double-Button-1>', play) - Listbox.pack () the  * Root.mainloop () $ Panax Notoginseng defsearchm (): -     Globalm_list theItemCount = 100 +  A     if  nottext.get (): theTkmessagebox.showinfo ('Warm Tips','You can search \n1 by entering the following. Song name \n2. Singer name \n3. Part lyrics') +  -     #get the input song name and URL $URL ='http://s.music.163.com/search/get/?type=1&s=%s&limit=%s'%(Text.get (), ItemCount) $      -     #GET Request -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'} theHTML =requests.get (Url,header) -data =json.loads (Html.text)WuyiM_list = [] the  -     Try: Wu Listbox.delete (0,listbox.size ()) -          forMusicdatainchdata['result']['Songs']: AboutListbox.insert (end,musicdata['name'] +'------'+'('+musicdata['Artists'][0]['name'] +')') $M_list.append (musicdata['Audio']) -     exceptException as E: -         Print 'error occurred during query, please try again' -      A      + defPlay (args): the     Try: -         Globalmp3 $SY =listbox.curselection () [0] theMP3 =mp3play.load (M_list[int (SY))) the Mp3.play () the         #Time.sleep (+) the     exceptException as E: -         Pass in  the      the defMain (): About Createwnd () the  the  the if __name__=='__main__': +Main ()

Program run results such as:

 

Python Implements---"Easy" online music player

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.