前几天用Ruby写了一个斗鱼TV弹幕的小爬虫,因为接下来的大四下学期需要去上海找工作,于是赶紧拿出Python来复习复习,把Ruby版本的代码使用Python重写一遍.
怎么用?
在安装好python3版本之后使用
pip3 install danmu.fm
# 比如主播的直播间
danmu.fm http://www.douyutv.com/16789
#或者
danmu.fm 16789
使用效果如下
test.gif test1.gifPython版本代码
https://github.com/twocucao/danmu.fm
原理
http://www.jianshu.com/p/ef0225b6bb0e
最新更新时间
- **Update 20160609 : ** 更新Python客户端,修复由于斗鱼网页版面修改带来的小问题,直接开启海量弹幕模式(请大家不要问我为什么端午节这一天为什么闲着没事更新代码,这个真的和情人节是同一个原因).
- **Update 20160220 : **更新Python客户端,增加直播视频的Live获取,以及Mac平台下面的Mplayer的视频播放.代码均放在Github上面. GitHub - twocucao/danmu.fm: douyutv danmu 斗鱼TV 弹幕助手**
- **Update 20160214 : 更新Python和Ruby客户端(请大家不要问我为什么情人节这一天为什么闲着没事更新代码)
如果你喜欢,点下喜欢吧
网友评论
[15:04:20] INFO::danmu - 正在检查环境
[15:04:20] INFO::danmu - 程序正在启动,检查环境配置
[15:04:20] INFO::danmu - 开始配置环境
[15:04:20] INFO::danmu - 环境检查完毕,正在开启斗鱼客户端(请等待15s~30s)
Traceback (most recent call last):
File "/usr/local/bin/danmu.fm", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/danmufm/danmu.py", line 117, in main
parse_command()
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/danmufm/danmu.py", line 107, in parse_command
start_douyu_client()
File "/usr/local/lib/python3.6/site-packages/danmufm/danmu.py", line 112, in start_douyu_client
DouyuClient(url).start()
File "/usr/local/lib/python3.6/site-packages/danmufm/client/douyu_client.py", line 66, in start
self.fetch_danmu(auth_server_ip, auth_server_port)
File "/usr/local/lib/python3.6/site-packages/danmufm/client/douyu_client.py", line 162, in fetch_danmu
client.start()
File "/usr/local/lib/python3.6/site-packages/danmufm/client/douyu_danmu_manager.py", line 36, in start
self.do_login()
File "/usr/local/lib/python3.6/site-packages/danmufm/client/douyu_danmu_manager.py", line 71, in do_login
self.danmu_socket.connect(self.DANMU_ADDR)
TimeoutError: [Errno 60] Operation timed out
1. python3 环境
2. 安装对应依赖库
3. windows里可以考虑在pycharm的终端里执行命令.
File "f:\python\lib\runpy.py", line 195, in _run_module_as_main
"__main__", mod_spec)
File "f:\python\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "F:\Python\Scripts\danmu.fm.exe\__main__.py", line 5, in <module>
File "f:\python\lib\site-packages\danmufm\danmu.py", line 18, in <module>
from .settings import ROOT_PROJECT_DIR
File "f:\python\lib\site-packages\danmufm\settings.py", line 49, in <module>
code = compile(f.read(), CONFIG_FILE, 'exec')
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 16: illegal m
ultibyte sequence
怎么回事,亲
[23:17:23] INFO::danmu - 正在检查环境
[23:17:23] INFO::danmu - 程序正在启动,检查环境配置
[23:17:23] INFO::danmu - 开始配置环境
[23:17:23] INFO::danmu - 环境检查完毕,正在开启斗鱼客户端(请等待15s~30s)
Traceback (most recent call last):
File "/usr/local/bin/danmu.fm", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/danmufm/danmu.py", line 117, in main
parse_command()
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/danmufm/danmu.py", line 107, in parse_command
start_douyu_client()
File "/usr/local/lib/python3.6/site-packages/danmufm/danmu.py", line 112, in start_douyu_client
DouyuClient(url).start()
File "/usr/local/lib/python3.6/site-packages/danmufm/client/douyu_client.py", line 51, in start
auth_server_ip, auth_server_port = self.fetch_room_info(self.url)
File "/usr/local/lib/python3.6/site-packages/danmufm/client/douyu_client.py", line 75, in fetch_room_info
room["gg_show"] = js["room_gg"]["show"]
KeyError: 'room_gg'
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/danmufm/client/douyu_danmu_manager.py", line 63, in keeplive
self.send_auth_keeplive_msg()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/danmufm/client/douyu_danmu_manager.py", line 178, in send_auth_keeplive_msg
self.danmu_auth_socket.sendall(msg)
BrokenPipeError: [Errno 32] Broken pipe
root@cz-virtual-machine:/home/cz# danmu.fm 426088
Traceback (most recent call last):
File "/usr/local/bin/danmu.fm", line 7, in <module>
from danmufm.danmu import main
File "/usr/local/lib/python3.5/dist-packages/danmufm/danmu.py", line 73, in <module>
import click
ImportError: No module named 'click'
什么原因?
结果里面的相互引用的文件地址就乱了
还有一个我发现接受的消息有些是带好几条弹幕的,会有好几个'type@='关键字,这个不知道博主处理了没?