Last active
November 25, 2015 15:42
-
-
Save andyhuzhill/51f29c821c471de804c2 to your computer and use it in GitHub Desktop.
PyDoubanFm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# *-* encoding: utf-8 *-* | |
# | |
# ============================================= | |
# Author : Andy Scout | |
# Homepage : http://andyhuzhill.github.com | |
# E-mail : [email protected] | |
# | |
# Description : This program play the online | |
# music on douban.fm | |
# Revision : 1.0 | |
# | |
# ============================================= | |
import urllib2 | |
import json | |
import os | |
url = "http://douban.fm/j/mine/playlist?type=n&channel=0" | |
try: | |
urls = urllib2.urlopen(url) | |
except urllib2.HTTPError: | |
import sys | |
print 'something wrong with your Internet connection!' | |
sys.exit(-1) | |
except urllib2.URLError: | |
import sys | |
print 'something wrong with your Internet connection!' | |
sys.exit(-1) | |
# read the json data from douban.com | |
jsondat = urls.read() | |
# parser the json data | |
strs = json.loads(jsondat) | |
# create a list to contain the songs | |
songlist = [] | |
for song in strs['song']: | |
songlist.append(song) | |
# use mpg123 to play the song, you can change it | |
# to your favorite music player | |
for song in songlist: | |
print 'Now is playing <%s> from [%s]' % (song['title'],song['artist']) | |
cmd = 'mpg123 -C ' + song['url'] | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment