{"id":11,"date":"2021-10-17T22:10:37","date_gmt":"2021-10-17T14:10:37","guid":{"rendered":"https:\/\/linguopeng.top\/?p=11"},"modified":"2021-10-19T10:20:53","modified_gmt":"2021-10-19T02:20:53","slug":"%e7%88%ac%e5%8f%96b%e7%ab%99%e8%a7%86%e9%a2%91","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=11","title":{"rendered":"\u722c\u53d6b\u7ad9\u89c6\u9891"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>##\u6211\u7684\u7f51\u76d8\/\u535a\u5ba2\u7d20\u6750\/\u722c\u53d6b\u7ad9\u89c6\u9891\nimport requests\nimport re\nimport json\nimport subprocess\ndef get_response(html_url):\n    headers = {\n        'Referer': 'https:\/\/www.bilibili.com\/video\/BV1A44y1t7xt',\n        'User-Agent': 'Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/87.0.4280.88 Safari\/537.36'}\n    response = requests.get(url=html_url,headers=headers)\n    return response\ndef get_video_info(html_url):\n    response = get_response(html_url)\n    title = re.findall('&lt;\/script&gt; &lt;title data-vue-meta=\"true\"&gt;(.*?)_\u54d4\u54e9\u54d4\u54e9_bilibili&lt;\/title&gt; ',response.text)&#91;0].replace(' ','')\n    html_data = re.findall('&lt;script&gt;window\\.__playinfo__=(.*?)&lt;\/script&gt;',response.text)&#91;0]\n    #\u6b63\u5219\u51fa\u6765\u7684\u6570\u636e\u662f\u5217\u8868\uff0c&#91;0]\u7d22\u5f15\u53d6\u5b57\u7b26\u4e32\n    #\u5b57\u7b26\u4e32\u8f6cjson\u5b57\u5178\n    json_data = json.loads(html_data)\n    #pprint.pprint(json_data)\n    audio_url = json_data&#91;'data']&#91;'dash']&#91;'audio']&#91;0]&#91;'baseUrl']\n    video_url = json_data&#91;'data']&#91;'dash']&#91;'video']&#91;0]&#91;'baseUrl']\n    video_info =&#91;title,audio_url,video_url]\n    return video_info\n    # print(title)\n    # print(audio_url)\n    # print(video_url)\ndef save(title,audio_url,video_url):\n    audio_content = get_response(audio_url).content\n    video_content = get_response(video_url).content\n    with open(title + '.mp3',mode='wb') as f:\n        f.write(audio_content)\n    with open(title +'.mp4',mode='wb') as f:\n        f.write(video_content)\n    print('\u89c6\u9891\u5185\u5bb9\u4fdd\u5b58\u5b8c\u6210~')\ndef merge_data(video_name):\n    print(\"\u89c6\u9891\u5408\u6210\u5f00\u59cb\", video_name)\n    #video_name = video_name_replace(' ','')\n    COMMAND = f'ffmpeg -i {video_name}.mp4 -i {video_name}.mp3 -c:v copy -c:a aac -strict experimental {video_name}output.mp4'\n    subprocess.Popen(COMMAND,shell =True)\n    print('\u89c6\u9891\u5408\u6210\u7ed3\u675f', video_name)\n\nurl = 'https:\/\/www.bilibili.com\/video\/BV1A44y1t7xt'\n#response = get_response(url)\n# print(response.text)\nvideo_info = get_video_info(url)\nsave(video_info&#91;0],video_info&#91;1],video_info&#91;2])\nmerge_data(video_info&#91;0])<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2021\/10\/1-5.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1805\" height=\"1185\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2021\/10\/1-5.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-70\"  sizes=\"auto, (max-width: 1805px) 100vw, 1805px\" \/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,4],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-2","tag-python","tag-4"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11"}],"version-history":[{"count":2,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions\/71"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}