Python Douban FM
Python Douban FM
参考:
http://www.shumeipai.net/thread-18061-1-1.html?_dsign=9284ceb4
https://github.com/zonyitoo/doubanfm-qt/wiki/%E8%B1%86%E7%93%A3FM-API
http://douban.fm/j/mine/playlist?type=p&sid=707632&pt=0.0&channel=-10&pb=128&from=mainsite&r=d485449161
-10豆瓣精选
我使用python3.5,修改如下
#!/usr/bin/python3 # -*- coding: utf-8 -*- import urllib.request import json import os import sys import subprocess import time #reload(sys) #sys.setdefaultencoding('utf-8') num=0 while num<10 : # 获取播放列表 #httpConnection = httplib.HTTPConnection('douban.fm') #httpConnection.request('GET', '/j/mine/playlist?type=n&channel=4') #http://www.douban.fm/j/mine/playlist?type=n&channel=4 #channel list : https://www.douban.com/j/app/radio/channels res = urllib.request.urlopen('https://www.douban.com/j/app/radio/people?version=100&app_name=radio_android&channel=1&type=n') song = json.loads(res.read().decode('utf-8'))['song'] picture = 'images/' + song[0]['picture'].split('/')[4] # 播放 player = subprocess.Popen(['D:/qv/mpg123.exe', song[0]['url']]) time.sleep(song[0]['length']) player.kill() num += 1
修改
#!/usr/bin/python3 # -*- coding: utf-8 -*- import urllib.request import json import os import sys import subprocess import time import threading PLAYER='' def play(): global PLAYER while 1: if PLAYER=='' or PLAYER.poll() is not None: # 获取播放列表 res = urllib.request.urlopen('http://www.douban.fm/j/mine/playlist?type=n&channel=4') song = json.loads(res.read().decode('utf-8'))['song'] # 播放 PLAYER = subprocess.Popen(['D:/qv/mpg123.exe', song[0]['url']]) #print(player.poll()) #time.sleep(song[0]['length']) #player.kill() else: time.sleep(1) def next(): global PLAYER PLAYER.kill() while True: con = input("please input control ,p :play, n:next ,e: end\n>") if con =='p': p = threading.Thread(target= play) p.setDaemon(1) p.start(); elif con =='n': if PLAYER=='': print('current don\'t play...') else: next() elif con =='e': if PLAYER!='': PLAYER.kill() exit(1) else: print('can\'t find command...')
我本地D:/qv/目录下有一个mpg123文件
运行如下代码就可以播放了(win8.1 测试正常)
python douban.py
v附录:
1>channel list
{ channels: [{ name_en: "Personal Radio", seq_id: 0, abbr_en: "My", name: "私人兆赫", channel_id: 0 }, { name: "华语", seq_id: 0, abbr_en: "", channel_id: "1", name_en: "" }, { name: "欧美", seq_id: 1, abbr_en: "", channel_id: "2", name_en: "" }, { name: "七零", seq_id: 2, abbr_en: "", channel_id: "3", name_en: "" }, { name: "八零", seq_id: 3, abbr_en: "", channel_id: "4", name_en: "" }, { name: "九零", seq_id: 4, abbr_en: "", channel_id: "5", name_en: "" }, { name: "粤语", seq_id: 5, abbr_en: "", channel_id: "6", name_en: "" }, { name: "摇滚", seq_id: 6, abbr_en: "", channel_id: "7", name_en: "" }, { name: "民谣", seq_id: 7, abbr_en: "", channel_id: "8", name_en: "" }, { name: "轻音乐", seq_id: 8, abbr_en: "", channel_id: "9", name_en: "" }, { name: "原声", seq_id: 9, abbr_en: "", channel_id: "10", name_en: "" }, { name: "爵士", seq_id: 10, abbr_en: "", channel_id: "13", name_en: "" }, { name: "电子", seq_id: 11, abbr_en: "", channel_id: "14", name_en: "" }, { name: "说唱", seq_id: 12, abbr_en: "", channel_id: "15", name_en: "" }, { name: "R&B ", seq_id: 13, abbr_en: "", channel_id: "16", name_en: "" }, { name: "日语", seq_id: 14, abbr_en: "", channel_id: "17", name_en: "" }, { name: "韩语", seq_id: 15, abbr_en: "", channel_id: "18", name_en: "" }, { name: "女声", seq_id: 16, abbr_en: "", channel_id: "20", name_en: "" }, { name: "法语", seq_id: 17, abbr_en: "", channel_id: "22", name_en: "" }, { name: "古典", seq_id: 18, abbr_en: "", channel_id: "27", name_en: "" }, { name: "动漫", seq_id: 19, abbr_en: "", channel_id: "28", name_en: "" }, { name: "咖啡馆", seq_id: 20, abbr_en: "", channel_id: "32", name_en: "" }, { name: "圣诞", seq_id: 21, abbr_en: "", channel_id: "170", name_en: "" }, { name: "豆瓣好歌曲", seq_id: 22, abbr_en: "", channel_id: "179", name_en: "" }, { name: "世界音乐", seq_id: 23, abbr_en: "", channel_id: "187", name_en: "" }, { name: "布鲁斯", seq_id: 24, abbr_en: "", channel_id: "188", name_en: "" }, { name: "新歌", seq_id: 25, abbr_en: "", channel_id: "61", name_en: "" }, { name: "雷鬼", seq_id: 26, abbr_en: "", channel_id: "190", name_en: "" }, { name: "世界杯", seq_id: 27, abbr_en: "", channel_id: "201", name_en: "" }, { name: "小清新", seq_id: 28, abbr_en: "", channel_id: "76", name_en: "" }, { name: "Easy ", seq_id: 29, abbr_en: "", channel_id: "77", name_en: "" }, { name: "91.1 ", seq_id: 30, abbr_en: "", channel_id: "78", name_en: "" }, { name: "“砖”属音乐", seq_id: 31, abbr_en: "", channel_id: "145", name_en: "" }, { name: "Pop", seq_id: 32, abbr_en: "", channel_id: "194", name_en: "" }, { name: "拉丁", seq_id: 33, abbr_en: "", channel_id: "189", name_en: "" }, { name: "来电嘉旅,唤醒耳朵", seq_id: 34, abbr_en: "", channel_id: "253", name_en: "" }, { name: "雷克萨斯大匠之夜", seq_id: 35, abbr_en: "", channel_id: "254", name_en: "" }] }
2> Music
{
r: 0,
version_max: 638,
is_show_quick_start: 0,
song: [{
album: "/subject/3876207/",
status: 0,
picture: "https://img1.doubanio.com/lpic/s3920313.jpg",
ssid: "ee4c",
artist: "许飞",
url: "http://mr7.doubanio.com/3c5ec43447931f6cb30f617f1a3ac263/0/fm/song/p1467655_128k.mp4",
title: "我要的飞翔",
length: 244,
like: 0,
subtype: "",
public_time: "2009",
sid: "1467655",
singers: [{
related_site_id: 105387,
is_site_artist: false,
id: "15935",
name: "许飞"
}],
aid: "3876207",
file_ext: "mp4",
sha256: "4eee7f9295a9f3bd52615844ef5fb7e0b8c16be3e595ef185af4ec6b3224257a",
kbps: "128",
albumtitle: "一起来看流星雨 原声音乐辑",
alert_msg: ""
}]
}