{"id":23521985,"url":"https://github.com/yuanji-dev/shirokumacafe","last_synced_at":"2025-10-16T06:14:53.421Z","repository":{"id":68646332,"uuid":"132872914","full_name":"yuanji-dev/shirokumacafe","owner":"yuanji-dev","description":"白熊咖啡馆的豆瓣广播","archived":false,"fork":false,"pushed_at":"2022-12-08T06:34:11.000Z","size":1988,"stargazers_count":22,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T20:56:58.806Z","etag":null,"topics":["bot","douban"],"latest_commit_sha":null,"homepage":"https://cafe.douban.love","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuanji-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-10T08:41:51.000Z","updated_at":"2023-02-02T09:07:04.000Z","dependencies_parsed_at":"2023-03-08T07:15:32.093Z","dependency_job_id":null,"html_url":"https://github.com/yuanji-dev/shirokumacafe","commit_stats":null,"previous_names":["yuanji-dev/shirokumacafe"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yuanji-dev/shirokumacafe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanji-dev%2Fshirokumacafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanji-dev%2Fshirokumacafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanji-dev%2Fshirokumacafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanji-dev%2Fshirokumacafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuanji-dev","download_url":"https://codeload.github.com/yuanji-dev/shirokumacafe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanji-dev%2Fshirokumacafe/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265434516,"owners_count":23764529,"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":["bot","douban"],"created_at":"2024-12-25T17:14:06.573Z","updated_at":"2025-10-16T06:14:48.382Z","avatar_url":"https://github.com/yuanji-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 在白熊咖啡馆打工的两天\n\n店长白熊桑 @qinhuai 说想在豆瓣开个白熊咖啡馆，我说反正我闲着也是闲着要不就交给我吧（大意），于是有了这个项目，就是定时把白熊咖啡馆的截图发到豆瓣广播上。\n\n## Day 1\n\n要完成这个工作，无非就是分三步：\n\n1. 准备好截图\n1. 准备好发广播\n1. 设置定时程序\n\n要先拿到截图就必须要有素材，素材当然就是白熊咖啡馆的片源啦，马上下载了 50 集，当然人工一张一张截图虽然也是个办法，果然还是太麻烦了，而且容易出错，规格也很难保证，于是就想着用程序去完成，就请来了 ffmpeg 桑，让他每隔 20 秒就去截一张图。\n\n`ffmpeg -i shirokumacafe_01.mkv  -f image2 -vf fps=fps=1/20 %d.jpg`\n\n写个遍历文件的简单代码，就可以坐等把所有截图都获取啦，50 集一共获取了 3698 张图片。然后打包传到服务器上（当然本地用也行，只要能保证一直开机运行就行）\n\n`rsync -av --progress -e \"ssh -p $ssh_port\" ./images.zip $remote_dst`\n\n然后就是研究怎么发广播，就跟平时刷广播一样，无非就是用浏览器，或者用 App。只要模拟这个过程就可能像他们一样发出广播了。这里选择了模拟 App 请求的方式，简单，方便而且有效期长。就是拿着账号密码去换 access_token，有了这个凭证就可以用它来发广播或者干其他什么事了。于是写了 `shirokumacafe.py` 这个程序，从 50 集的截图里随机挑选一张，然后发到豆瓣广播上。\n\n最后为了让这个程序定时跑起来，只要用 `crontab -e` 设置一下就可以啦。\n\n`0 * * * * cd /root/app/shirokumacafe \u0026\u0026 pipenv run python shirokumacafe.py`\n\n\n## Day 2\n\n上面的程序运行了一天之后，发现了一些问题，比如 OP 和 ED 的截图存在感较高，还有一些意味不明的图片，也没有办法嘛，毕竟每 20 秒截一张图的办法谁也不知道都拿到了什么样的照片。另外一个就是感觉就光秃秃一张图片未免有些单调。于是为了解决这些问题，打工第二天开始了。\n\n为了改善机械的截图方式，想到了用台词去截图，也就是用字幕。这样一来至少是有对白的画面，质量多少会高一点儿，另外台词顺便可以当发广播的文字，一举两得，不对顺便还能当学日语的例句，一举三得了。首先就是提取字幕，用 `mkvmerge -i` 查看字幕信息，然后用 `mkvextract` 导出就行。之后就是处理这些字幕文件，提取出我们需要的截图时刻（这里简单地使用了字幕起止时间的中间作为截图点），然后合并一下中日两种文字的台词。总的来说就是 `coffee.py` 的作用了。有了这些信息，就写了 `bamboo.py` 让他去按照台词的时刻截图了，最后截了近两万张图，辛苦了 ffmpeg 桑。\n\nOP 和 ED 出现概率高的原因是因为他们每集都有嘛，简单得改了下随机策略就解决了，先把 OP 和 ED 的截图摘出来选出一张，然后把他加到正片的截图池里再随机选一张就差不多了。\n\n以上就是打工两天的内容啦。\n\n![すげぇだろう？](./webarebears.jpg)\n\n## 追记\n\n- 2018/05/13: 发完广播后自动回复截图出处\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanji-dev%2Fshirokumacafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanji-dev%2Fshirokumacafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanji-dev%2Fshirokumacafe/lists"}