{"id":1731,"date":"2023-07-26T17:18:25","date_gmt":"2023-07-26T09:18:25","guid":{"rendered":"http:\/\/blog.xtaa.cn\/?p=1731"},"modified":"2023-08-23T08:59:05","modified_gmt":"2023-08-23T00:59:05","slug":"flask%e4%b9%8bredisdplayer%e6%b6%88%e6%81%af%e9%98%9f%e5%88%97%e5%ae%9e%e7%8e%b0%e7%94%b5%e5%bd%b1%e5%bc%b9%e5%b9%95","status":"publish","type":"post","link":"http:\/\/blog.xtaa.cn\/index.php\/2023\/07\/26\/flask%e4%b9%8bredisdplayer%e6%b6%88%e6%81%af%e9%98%9f%e5%88%97%e5%ae%9e%e7%8e%b0%e7%94%b5%e5%bd%b1%e5%bc%b9%e5%b9%95\/","title":{"rendered":"flask\u4e4bREDIS+Dplayer\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u7535\u5f71\u5f39\u5e55"},"content":{"rendered":"\n<p><strong>\u4e00\u3001\u5b89\u88c5Redis<\/strong><\/p>\n\n\n\n<p>\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/redis.io\/download\">https:\/\/redis.io\/download<\/a><\/p>\n\n\n\n<p>Redis&nbsp; centos\u5b89\u88c5\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum -y install gcc gcc-c++\nwget http:\/\/download.redis.io\/releases\/redis-4.0.10.tar.gz\ntar -zxvf redis-4.0.10.tar.gz\ncd redis-4.0.10\nmake &amp;&amp; make install\n.\/utils\/install_server.sh\n#\u6d4b\u8bd5redis\u662f\u5426\u8fd0\u884c\nredis-cli\n&gt; ping #\u8fd4\u56depong\u8868\u793a\u6210\u529f<\/pre>\n\n\n\n<p>\u5b89\u88c5<a href=\"https:\/\/so.csdn.net\/so\/search?q=flask&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">flask<\/a>-redis<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#\u6e05\u534e\u6e90\npip3 install -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple flask-redis<\/pre>\n\n\n\n<p><strong>\u4e8c\u3001\u5b89\u88c5\u5f00\u6e90\u63d2\u4ef6Dplayer<\/strong><\/p>\n\n\n\n<p>Dplayer\u5b98\u7f51\u5730\u5740\uff1a<a href=\"http:\/\/dplayer.js.org\/#\/\">http:\/\/dplayer.js.org\/#\/<\/a>&nbsp; &nbsp; (\u6709\u65f6\u5019\u4f1a\u6253\u4e0d\u5f00\u54e6)<\/p>\n\n\n\n<p>Dplayer github\u5730\u5740:<a href=\"https:\/\/github.com\/MoePlayer\/DPlayer\">https:\/\/github.com\/MoePlayer\/DPlayer<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#html\u5f15\u5165css\/js\n&lt;link rel=\"stylesheet\" href=\"{{ url_for('static',filename='dplayer\/dist\/Dplayer.min.css') }}\" >\n&lt;script src=\"{{ url_for('static',filename='dplayer\/dist\/DPlayer.min.js') }}\">&lt;\/script>\n#\u5f15\u7528\u5230\u9875\u9762\n&lt;div id=\"dplayer\" style=\"height: 500px;width: 774px\">&lt;\/div>\n#\u5f39\u5e55\u548c\u89c6\u9891\u63a5\u53e3\n &lt;script>\n        var dp1 = new DPlayer({\n            container: document.getElementById('dplayer'),\n            video: {\n                url: \"{{ url_for('static',filename='uploads\/'+movie.url) }}\"\n            },\n            danmaku: {\n                id: '{{ movie.id }}',\n                api: \"\/tm\/\"\n            }\n        });\n &lt;\/script>\n \n#Python\u8fd4\u56de\u5f39\u5e55\u7684\u5904\u7406\u65b9\u6cd5\n@home.route(\"\/tm\/v3\/\",methods=&#91;\"GET\",\"POST\"])\ndef tm():\n    import json\n    if request.method==\"GET\":\n        #\u83b7\u53d6\u5f39\u5e55\u6d88\u606f\u961f\u5217\n        mid = request.args.get(\"id\")\n        key=\"movie\"+str(mid)\n        if rd.llen(key):\n            msgs=rd.lrange(key,0,2999)\n            res={\n                \"code\":0,\n                \"data\":&#91;json.loads(v) for v in msgs]\n            }\n        else:\n            res={\n                \"code\":1,\n                \"danmaku\":&#91;]\n            }\n        resp=json.dumps(res)\n    if request.method==\"POST\":\n        #\u6dfb\u52a0\u5f39\u5e55\n        data=json.loads(request.get_data())\n        msg= {\n        \"__v\": 0,\n        \"_id\": datetime.datetime.now().strftime(\"%Y%m%d%H%M%S\") + uuid.uuid4().hex,\n        \"author\": data&#91;\"author\"],\n        \"time\": data&#91;\"time\"],\n        \"text\": data&#91;\"text\"],\n        \"color\": data&#91;\"color\"],\n        \"type\": data&#91;\"type\"],\n        \"ip\": request.remote_addr,\n        \"player\": data&#91;\"id\"]\n        }\n        res = {\n            \"code\": 0,\n            \"danmaku\":msg\n        }\n        resp=json.dumps(res)\n        msg=&#91;data&#91;\"time\"],data&#91;\"type\"],data&#91;\"color\"],data&#91;\"author\"],data&#91;\"text\"]]\n        rd.lpush(\"movie\"+str(data&#91;\"id\"]),json.dumps(msg))\n    return Response(resp,mimetype=\"application\/json\")<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5b89\u88c5Redis \u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/redis.io\/download Redis&nbsp;  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1731","post","type-post","status-publish","format-standard","hentry","category-10"],"_links":{"self":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts\/1731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1731"}],"version-history":[{"count":1,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts\/1731\/revisions"}],"predecessor-version":[{"id":1764,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts\/1731\/revisions\/1764"}],"wp:attachment":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1731"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}