{"id":13488342,"url":"https://github.com/littlecodersh/danmu","last_synced_at":"2025-04-12T20:45:44.582Z","repository":{"id":47789447,"uuid":"64667141","full_name":"littlecodersh/danmu","owner":"littlecodersh","description":"Python 弹幕包 A live danmu package for python","archived":false,"fork":false,"pushed_at":"2018-02-11T17:55:53.000Z","size":34,"stargazers_count":724,"open_issues_count":25,"forks_count":148,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-04T00:20:01.675Z","etag":null,"topics":["bilibili","danmu","douyu","panda"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/littlecodersh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-01T12:59:26.000Z","updated_at":"2025-03-19T08:42:03.000Z","dependencies_parsed_at":"2022-09-03T10:20:21.044Z","dependency_job_id":null,"html_url":"https://github.com/littlecodersh/danmu","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/littlecodersh%2Fdanmu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/littlecodersh%2Fdanmu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/littlecodersh%2Fdanmu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/littlecodersh%2Fdanmu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/littlecodersh","download_url":"https://codeload.github.com/littlecodersh/danmu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631692,"owners_count":21136559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bilibili","danmu","douyu","panda"],"created_at":"2024-07-31T18:01:14.079Z","updated_at":"2025-04-12T20:45:44.560Z","avatar_url":"https://github.com/littlecodersh.png","language":"Python","readme":"# danmu\r\n\r\n![py2][py2] ![py3][py3] [English Version][english_version]\r\n\r\ndanmu 是一个开源的直播平台弹幕接口，使用他没什么基础的你也可以轻松的操作各平台弹幕。\r\n\r\n使用不到三十行代码，你就可以使用Python基于弹幕进一步开发。\r\n\r\n支持斗鱼、熊猫、战旗、全民、Bilibili多平台弹幕。\r\n\r\n支持各版本Python，无平台依赖，方便各类开发者、爱好者使用。\r\n\r\n一次开启，主播上线自动连接，下线后上线自动重连。\r\n\r\n经过深度优化，几乎不漏过任何一条弹幕；使用抽象构架，方便修改与开发。\r\n\r\n## Documents\r\n\r\n你可以在[这里][document]获取使用帮助。\r\n\r\n## Installation\r\n\r\n可以通过本命令安装 danmu：\r\n\r\n```bash\r\npip install danmu\r\n```\r\n\r\n## Simple uses\r\n\r\n通过如下代码，可以初步通过Python对弹幕进行处理。\r\n\r\n```python\r\nimport time, sys\r\n\r\nfrom danmu import DanMuClient\r\n\r\ndef pp(msg):\r\n    print(msg.encode(sys.stdin.encoding, 'ignore').\r\n        decode(sys.stdin.encoding))\r\n\r\ndmc = DanMuClient('http://www.douyu.com/lslalala')\r\nif not dmc.isValid(): print('Url not valid')\r\n\r\n@dmc.danmu\r\ndef danmu_fn(msg):\r\n    pp('[%s] %s' % (msg['NickName'], msg['Content']))\r\n\r\n@dmc.gift\r\ndef gift_fn(msg):\r\n    pp('[%s] sent a gift!' % msg['NickName'])\r\n\r\n@dmc.other\r\ndef other_fn(msg):\r\n    pp('Other message received')\r\n\r\ndmc.start(blockThread = True)\r\n```\r\n\r\n## Screenshot\r\n\r\n![screenshot][screenshot]\r\n\r\n## Advanced uses\r\n\r\n### 设置默认的消息处理方式\r\n\r\n消息被分为三种类型注册：danmu, gift, other\r\n\r\n分别对应：普通弹幕，礼物消息，其他消息\r\n\r\n如果某种类型没有注册过，将会使用默认方法，默认方法的注册方式如下：\r\n\r\n```python\r\nfrom danmu import DanMuClient\r\n\r\ndmc = DanMuClient('http://www.douyu.com/lslalala')\r\n\r\n@dmc.default\r\ndef default_fn(msg):\r\n    pp('[%s] %s' % (msg['NickName'], msg['Content']))\r\n```\r\n\r\n### 取消已经注册过的方法\r\n\r\n通过以下方式可以取消某一种类型的注册。\r\n\r\n```python\r\nfrom danmu import DanMuClient\r\n\r\ndmc = DanMuClient('http://www.douyu.com/lslalala')\r\ndmc.default(None)\r\ndmc.gift(None)\r\n```\r\n\r\n## FAQ\r\n\r\nQ: 获取的消息格式都是什么？\r\n\r\nA: 消息为一个字典，必有三个键：NickName、Content、MsgType，对应用户名、消息内容、消息类型。\r\n\r\n## Comments\r\n\r\n如果有什么问题或者建议都可以在这个[Issue][issue#2]和我讨论\r\n\r\n或者也可以在gitter上交流：[![gitter][gitter_picture]][gitter]\r\n\r\n[py2]: https://img.shields.io/badge/python-2.7-ff69b4.svg \"python2\"\r\n[py3]: https://img.shields.io/badge/python-3.5-red.svg \"python3\"\r\n[english_version]: https://github.com/littlecodersh/danmu/blob/master/README_EN.md\r\n[document]: http://danmu.readthedocs.io/zh_CN/latest/\r\n[screenshot]: http://7xrip4.com1.z0.glb.clouddn.com/danmu/demo.png?imageView/2/w/400/ \"screenshot\"\r\n[issue#2]: https://github.com/littlecodersh/danmu/issues/2\r\n[gitter_picture]: https://badges.gitter.im/littlecodersh/danmu.svg \"gitter\"\r\n[gitter]: https://gitter.im/littlecodersh/danmu?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\r\n","funding_links":[],"categories":["Python","Uncategorized","Misc"],"sub_categories":["Uncategorized","Misc / Desktop"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittlecodersh%2Fdanmu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flittlecodersh%2Fdanmu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittlecodersh%2Fdanmu/lists"}