{"id":1599,"date":"2021-08-25T17:02:56","date_gmt":"2021-08-25T09:02:56","guid":{"rendered":"https:\/\/swf.com.tw\/?p=1599"},"modified":"2021-10-20T07:24:15","modified_gmt":"2021-10-19T23:24:15","slug":"youtube%e5%bd%b1%e7%89%87%e4%b8%8b%e8%bc%89%ef%bc%88%e4%b8%83%ef%bc%89%ef%bc%9a%e4%b8%8b%e8%bc%89%e6%92%ad%e6%94%be%e6%b8%85%e5%96%ae%e4%b8%ad%e7%9a%84%e5%85%a8%e9%83%a8%e5%bd%b1%e7%89%87","status":"publish","type":"post","link":"https:\/\/swf.com.tw\/?p=1599","title":{"rendered":"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e0b\u8f09YouTube\u5f71\u7247\u7684Pytube\u7a0b\u5f0f\u5eab\u6709\u500b\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684<strong>Playlist\u985e\u5225<\/strong>\uff0c\u672c\u6587\u5c07\u4fee\u6539\u4e4b\u524d\u7684YouTube\u5f71\u97f3\u4e0b\u8f09\u7a0b\u5f0f\u78bc\uff0c\u8b93\u5b83\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53d6\u5f97YouTube\u64ad\u653e\u6e05\u55ae\u7db2\u5740<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5<a href=\"https:\/\/www.youtube.com\/channel\/UCePDFpCr78_qmVtpoB1Axaw\" target=\"_blank\" rel=\"noreferrer noopener\">Great Art Explained\u983b\u9053<\/a>\u70ba\u4f8b\uff0c\u9ede\u64ca\u5176\u4e2d\u4e00\u500b\u64ad\u653e\u6e05\u55ae\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/playlist_0.png\" alt=\"YouTube\u983b\u9053\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u700f\u89bd\u5668\u5c07\u900f\u904e\u9019\u500b\u7db2\u5740\u64ad\u653e\u5f71\u7247\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.youtube.com\/watch?v=T15Kv6dtYO0&amp;list=PLjBkTEtM_Tw_cQi2PXrD9zSdFFsr4NQ5U\">https:\/\/www.youtube.com\/watch?v=T15Kv6dtYO0&amp;list=PLjBkTEtM_Tw_cQi2PXrD9zSdFFsr4NQ5U<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u9ede\u64ca\u53f3\u5074\u64ad\u653e\u6e05\u55ae\u88e1\u7684\u4efb\u4e00\u5f71\u7247\uff0c\u4e0a\u9762\u7684\u7db2\u5740\u5f8c\u9762\u6703\u52a0\u4e0a\u4e00\u500b\u4ee3\u8868\u7d22\u5f15\u7de8\u865f\u7684index\u53c3\u6578\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/playlist_1.png\" alt=\"YouTube\u64ad\u653e\u6e05\u55ae\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\uff0c\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684\u7db2\u5740\u683c\u5f0f\u5982\u4e0b\uff0c\u900f\u904e\u7a0b\u5f0f\u4e0b\u8f09\u5f71\u7247\u6642\uff0cindex\u53c3\u6578\u53ef\u4ee5\u7701\u7565\uff0c\u56e0\u70ba\u7121\u8ad6\u662f\u5426\u6dfb\u52a0index\u53c3\u6578\uff0c\u90fd\u80fd\u53d6\u5f97\u6e05\u55ae\u88e1\u7684\u6240\u6709\u5f71\u7247\u7684\u7db2\u5740\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/playlist_2.png\" alt=\"YouTube\u64ad\u653e\u6e05\u55ae\u7db2\u5740\u683c\u5f0f\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u900f\u904eYouTube\u4f3a\u670d\u5668\u7684playlist\u7a0b\u5f0f\uff0c\u4e5f\u80fd\u53d6\u5f97\u6307\u5b9a\u7684\u64ad\u653e\u6e05\u55ae\u7684\u5f71\u7247\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/playlist_3.png\" alt=\"YouTube\u64ad\u653e\u6e05\u55ae\u7db2\u5740\u683c\u5f0f\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u628a\u4e0a\u9762\u7db2\u5740\u88e1\u7684list\u53c3\u6578\uff0c\u526a\u8cbc\u5230playlist\u7db2\u5740\u5f8c\u9762\uff0c\u5c07\u80fd\u6aa2\u8996\u6e05\u55ae\u4e2d\u7684\u6240\u6709\u5f71\u7247\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.youtube.com\/playlist?list=PLjBkTEtM_Tw_cQi2PXrD9zSdFFsr4NQ5U\">https:\/\/www.youtube.com\/playlist?list=PLjBkTEtM_Tw_cQi2PXrD9zSdFFsr4NQ5U<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u900f\u904ePytube\u7684Playlist\u985e\u5225\u53d6\u5f97\u300c\u64ad\u653e\u6e05\u55ae\u300d\u7684\u6240\u6709\u5f71\u7247\u7db2\u5740<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pytube\u7a0b\u5f0f\u5eab\u7684<strong>Playlist\u985e\u5225<\/strong>\u63a5\u6536\u4e00\u500b\u300c\u64ad\u653e\u6e05\u55ae\u300d\u7db2\u5740\uff1b\u5e95\u4e0b\u6558\u8ff0\u5c07\u5efa\u7acb\u4e00\u500b\u540d\u53eb\u2018pl\u2019\u7684Playlist\u7269\u4ef6\uff0c\u900f\u904epl\u7269\u4ef6\u7684<strong>video_urls\u5c6c\u6027<\/strong>\uff0c\u6216\u76f4\u63a5\u5b58\u53d6pl\u7269\u4ef6\uff0c\u90fd\u80fd\u50b3\u56de\u5217\u8868\uff08list\uff09\u683c\u5f0f\u7684\u5f71\u7247\u7db2\u5740\u6e05\u55ae\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/playlist_4.png\" alt=\"\u57f7\u884cPytube\u5f97Playlist\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Playlist\u985e\u5225\u7269\u4ef6\uff08\u5373pl\u7269\u4ef6\uff09\u5305\u542bYouTube\u7269\u4ef6\uff0c\u56e0\u6b64\u5e95\u4e0b\u6558\u8ff0\u53ef\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u7684\u5168\u90e8\u5f71\u7247\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for video in p.videos:\n   video.streams.first().download()\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7684\u7a0b\u5f0f\u50c5\u5229\u7528Playlist\u53d6\u5f97\u5f71\u7247\u6e05\u55ae\u7684\u5168\u90e8\u7db2\u5740\uff0c\u57f7\u884c\u4e0b\u8f09\u548c\u5408\u4f75\u5f71\u97f3\u7684\u7a0b\u5f0f\uff0c\u6cbf\u7528\u4e4b\u524d\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b46\u8005\u5c07\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Python\u7a0b\u5f0f\u6a94\u547d\u540d\u6210tube_list.py\uff0c\u5b83\u652f\u63f4\u4e4b\u524d\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c3\u6578\uff0c\u5982\uff1a-a\uff08\u50c5\u4e0b\u8f09\u8072\u97f3\uff09\u548c-fhd\uff08\u9ad8\u756b\u8cea\u683c\u5f0f\uff09\uff0c\u4e26\u65b0\u589e\u4e00\u500b\u6307\u5b9a\u4e0b\u8f09\u5f71\u7247\u6578\u91cf\u7684-end\u53c3\u6578\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u5728\u7d42\u7aef\u6a5f\u6216\u547d\u4ee4\u63d0\u793a\u5b57\u5143\u4e2d\u57f7\u884ctube_list.py\uff0c\u5b83\u5c07\u4e0b\u8f09\u6307\u5b9a\u64ad\u653e\u6e05\u55ae\u7576\u4e2d\u7684\u524d\u4e09\u500b\u9ad8\u756b\u8cea\u5f71\u7247\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>python tube_list.py \u64ad\u653e\u6e05\u55ae\u7db2\u5740 -fhd -end 3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tube_list.py\u7a0b\u5f0f\u6a94\u4fee\u6539\u81ea\u4e4b\u524d\u7684tube.py\u6a94\uff0cmain()\u51fd\u5f0f\u7684\u6539\u52d5\u5167\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/modded_main_code.png\" alt=\"\u4fee\u6539main()\u51fd\u5f0f\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">check_urls()\u51fd\u5f0f\u8ca0\u8cac\u5f9e\u64ad\u653e\u6e05\u55ae\u4e2d\u53d6\u51fa\u4e00\u500b\u7db2\u5740\uff0c\u4ea4\u7d66download_media()\u51fd\u5f0f\u9032\u884c\u4e0b\u8f09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def check_urls():\n    global args\n    global file_index   # \u4e0b\u8f09\u6a94\u7684\u5217\u8868\u7d22\u5f15\n    global download_count\n\n    download_count = 1\n\n    if file_index < len(videos):\n        vars(args)['url'] = videos[file_index]  # \u628a\u5f71\u7247\u7db2\u5740\u50b3\u7d66url\u53c3\u6578\n        file_index = file_index + 1\n        print(\"\u4e0b\u8f09\u5f71\u7247\uff1a\", vars(args)['url'])\n        download_media(args)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">download_media()\u51fd\u5f0f\u5c07\u5f9eargs\u7269\u4ef6\u53d6\u5f97\u5305\u542burl\uff08\u5f71\u7247\u4e0b\u8f09\u7db2\u5740\uff09\u5728\u5167\u7684\u53c3\u6578\uff0c\u6240\u4ee5\u4e0a\u9762\u7684\u7a0b\u5f0f\u628a\u4e0b\u8f09\u5f71\u7247\u7684\u7db2\u5740\u5beb\u5165args\u7269\u4ef6\u7684url\u53c3\u6578\uff0c\u9019\u90e8\u4efd\u7684\u76f8\u95dc\u8aaa\u660e\u8acb\u53c3\u95b1\u300c<a href=\"\/?p=1357\" target=\"_blank\" rel=\"noreferrer noopener\">YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e00\uff09\uff1a\u5408\u4f75\u8996\u8a0a\u548c\u97f3\u8ecc\u7684Python\u7a0b\u5f0f<\/a>\u300d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684\u5b8c\u6574Python\u7a0b\u5f0f\u78bc<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">tube_list.py\u7684\u5b8c\u6574\u7a0b\u5f0f\u78bc\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding: utf-8 -*-\nimport argparse\nimport os\nimport platform\nfrom pytube import YouTube\nfrom pytube import Playlist\nimport subprocess\n\nargs = {}\nfileobj = {}\ndownload_count = 1\nfile_index = 0\n\ndef pyTube_folder():\n    sys = platform.system()\n    home = os.path.expanduser('~')\n\n    if sys == 'Windows':\n        folder = os.path.join(home, 'Videos', 'PyTube')\n    elif sys == 'Darwin':\n        folder = os.path.join(home, 'Movies', 'PyTube')\n\n    if not os.path.isdir(folder):  # \u82e5'PyTube'\u8cc7\u6599\u593e\u4e0d\u5b58\u5728\u2026\n        os.mkdir(folder)        # \u5247\u65b0\u589e\u8cc7\u6599\u593e\n\n    return folder\n\n\ndef onProgress(stream, chunk, remains):\n    total = stream.filesize\n    percent = (total-remains) \/ total * 100\n    print('\u4e0b\u8f09\u4e2d\u2026 {:05.2f}%'.format(percent), end='\\r')\n\ndef video_res(yt):\n    res_set = set()\n    video_list = yt.streams.filter(type=\"video\")\n    for v in video_list:\n        res_set.add(v.resolution)\n\n    # \u50b3\u56de\u89e3\u6790\u5ea6\u8868\u5217\uff0c\u4f8b\u5982\uff1a['720p', '480p', '360p', '240p', '144p']\n    return sorted(res_set, reverse=True, key=lambda s: int(s[:-1]))\n\n\ndef download_media(args):\n    try:\n        yt = YouTube(args.url, on_progress_callback=onProgress,\n                     on_complete_callback=onComplete)\n    except:\n        print('\u4e0b\u8f09\u5f71\u7247\u6642\u767c\u751f\u932f\u8aa4\uff0c\u8acb\u78ba\u8a8d\u7db2\u8def\u9023\u7dda\u548cYouTube\u7db2\u5740\u7121\u8aa4\u3002')\n        return\n\n    filter = yt.streams.filter\n\n    if args.a:  # \u53ea\u4e0b\u8f09\u8072\u97f3\n        target = filter(type=\"audio\").first()\n    elif args.fhd:\n        target = filter(type=\"video\", resolution=\"1080p\").first()\n    elif args.hd:\n        target = filter(type=\"video\", resolution=\"720p\").first()\n    elif args.sd:\n        target = filter(type=\"video\", resolution=\"480p\").first()\n    else:\n        target = filter(type=\"video\").first()\n\n    if target is None:\n        print('\u6c92\u6709\u60a8\u6307\u5b9a\u7684\u89e3\u6790\u5ea6\uff0c\u53ef\u7528\u7684\u89e3\u6790\u5ea6\u5982\u4e0b\uff1a')\n        res_list = video_res(yt)\n\n        for i, res in enumerate(res_list):\n            print('{}) {}'.format(i+1, res))\n\n        val = input('\u8acb\u9078\u64c7\uff08\u9810\u8a2d{}\uff09\uff1a'.format(res_list[0]))\n\n        try:\n            res = res_list[int(val)-1]\n        except:\n            res = res_list[0]\n\n        print('\u60a8\u9078\u64c7\u7684\u662f {} \u3002'.format(res))\n        target = filter(type=\"video\", resolution=res).first()\n\n    # \u958b\u59cb\u4e0b\u8f09\n    target.download(output_path=pyTube_folder())\n\n\ndef check_media(filename):\n    out = subprocess.run([\"ffprobe\", filename],\n                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n    if (out.stdout.decode('utf-8').rfind('Audio') == -1):\n        return -1  # \u6c92\u6709\u8072\u97f3\n    else:\n        return 1\n\n\ndef merge_media():\n    vars(args)['a'] = False # \u6e05\u7a7aa\u53c3\u6578\n    temp_video = os.path.join(fileobj['dir'], 'temp_video.mp4')\n    temp_audio = os.path.join(fileobj['dir'], 'temp_audio.mp4')\n    temp_output = os.path.join(fileobj['dir'], 'output.mp4')\n\n    cmd = f'ffmpeg -i {temp_video} -i {temp_audio} \\\n        -map 0:v -map 1:a -c copy -y {temp_output}'\n    try:\n        subprocess.run(cmd, shell=True)\n        # \u8996\u8a0a\u6a94\u91cd\u65b0\u547d\u540d\n        os.rename(temp_output, os.path.join(fileobj['dir'], fileobj['name']))\n        os.remove(temp_audio)\n        os.remove(temp_video)\n        print('\u8996\u8a0a\u548c\u8072\u97f3\u5408\u4f75\u5b8c\u6210')\n        check_urls()\n    except:\n        print('\u8996\u8a0a\u548c\u8072\u97f3\u5408\u4f75\u5931\u6557')\n\n\ndef onComplete(stream, file_path):\n    global download_count, fileobj\n    fileobj['name'] = os.path.basename(file_path)\n    fileobj['dir'] = os.path.dirname(file_path)\n    print('\\r')\n\n    if download_count == 1:\n        if check_media(file_path) == -1:\n            print('\u6b64\u5f71\u7247\u6c92\u6709\u8072\u97f3')\n            download_count += 1\n            try:\n                # \u8996\u8a0a\u6a94\u91cd\u65b0\u547d\u540d\n                os.rename(file_path, os.path.join(\n                    fileobj['dir'], 'temp_video.mp4'))\n            except:\n                print('\u8996\u8a0a\u6a94\u91cd\u65b0\u547d\u540d\u5931\u6557')\n                return\n\n            print('\u6e96\u5099\u4e0b\u8f09\u8072\u97f3\u6a94')\n            vars(args)['a'] = True  # \u8a2d\u5b9a\u6210a\u53c3\u6578\n            download_media(args)    # \u4e0b\u8f09\u8072\u97f3\n        else:\n            print('\u6b64\u5f71\u7247\u6709\u8072\u97f3\uff0c\u4e0b\u8f09\u5b8c\u7562\uff01')\n            check_urls()\n    else:\n        try:\n            # \u8072\u97f3\u6a94\u91cd\u65b0\u547d\u540d\n            os.rename(file_path, os.path.join(\n                fileobj['dir'], 'temp_audio.mp4'))\n        except:\n            print(\"\u8072\u97f3\u6a94\u91cd\u65b0\u547d\u540d\u5931\u6557\")\n        # \u5408\u4f75\u8072\u97f3\u6a94\n        merge_media()\n\ndef check_urls():\n    global args\n    global file_index\n    global download_count\n    download_count = 1\n\n    if file_index < len(videos):\n        vars(args)['url'] = videos[file_index]  # \u8a2d\u5b9a\u6210url\u53c3\u6578\n        file_index = file_index + 1\n        print(\"\u4e0b\u8f09\u5f71\u7247\uff1a\", vars(args)['url'])\n        download_media(args)\n\ndef main():\n    global videos\n    global args\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"url\", help=\"\u6307\u5b9aYouTube\u8996\u8a0a\u7db2\u5740\")\n    parser.add_argument(\"-sd\", action=\"store_true\", help=\"\u9078\u64c7\u666e\u901a\uff08480P\uff09\u756b\u8cea\")\n    parser.add_argument(\"-hd\", action=\"store_true\", help=\"\u9078\u64c7HD\uff08720P\uff09\u756b\u8cea\")\n    parser.add_argument(\"-fhd\", action=\"store_true\", help=\"\u9078\u64c7Full HD\uff081080P\uff09\u756b\u8cea\")\n    parser.add_argument(\"-a\", action=\"store_true\", help=\"\u50c5\u4e0b\u8f09\u8072\u97f3\")\n    parser.add_argument(\"-end\", action=\"store\", help=\"\u5f71\u97f3\u6e05\u55ae\u6578\u91cf\u4e0a\u9650\")\n\n    args = parser.parse_args()\n\n    try:\n        pl = Playlist(args.url)\n\n        if args.end:\n            videos = pl.video_urls[:int(args.end)]\n        else:\n            videos = pl.video_urls\n    except:\n        print('\u4e0b\u8f09\u5f71\u7247\u6642\u767c\u751f\u932f\u8aa4\uff0c\u8acb\u78ba\u8a8d\u7db2\u8def\u9023\u7dda\u548cYouTube\u7db2\u5740\u7121\u8aa4\u3002')\n        return\n\n    # print('\u5f71\u7247\u5217\u8868: ', videos)\n    check_urls()\n\nif __name__ == '__main__':\n    main()\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u57f7\u884c\u9019\u500b\u7a0b\u5f0f\u6a94\u6642\u8981\u7559\u610f\uff0cWindows\u7684CLI\u4ecb\u9762\uff0c\u5982PowerShell\uff0c\u4e0d\u5141\u8a31\u547d\u4ee4\u53c3\u6578\u5305\u542b'&amp;'\u5b57\u5143\uff1b\u82e5YouTube\u5f71\u7247\u7db2\u5740\u5305\u542b'&amp;'\u5b57\u5143\uff0c\u57f7\u884c\u6642\u5c07\u6703\u51fa\u73fe\u5982\u4e0b\u7684\u932f\u8aa4\u8a0a\u606f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/cli_ampersand_error.png\" alt=\"Windows\u7684CLI\u8996\u7a97\u7684\u932f\u8aa4\u8a0a\u606f\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8acb\u628a'&amp;'\u5b57\u5143\u7528\u5f15\u865f\u522e\u4f4f\uff0c\u6216\u6539\u7528\u4e0a\u6587\u63d0\u5230\u7684playlist\u7db2\u5740\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"\/images\/books\/python\/PyTube\/playlist_5.png\" alt=\"\u7528\u5f15\u597d\u522e\u4f4f\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5ef6\u4f38\u95b1\u8b80<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"\/?p=1205\" target=\"_blank\" rel=\"noreferrer noopener\">\u8d85\u5716\u89e3Python\u7a0b\u5f0f\u8a2d\u8a08\u5165\u9580<\/a><\/li><li><a href=\"\/?p=1434\" target=\"_blank\" rel=\"noreferrer noopener\">YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u516d\uff09\uff1a\u6539\u7528PyTube\u7a0b\u5f0f\u5eab\u89e3\u6c7a\u57f7\u884c\u932f\u8aa4<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u8f09YouTube\u5f71\u7247\u7684Pytube\u7a0b\u5f0f\u5eab\u6709\u500b\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Playlist\u985e\u5225\uff0c\u672c\u6587\u5c07\u4fee\u6539\u4e4b\u524d\u7684YouTube\u5f71\u97f3\u4e0b\u8f09\u7a0b\u5f0f\u78bc\uff0c\u8b93\u5b83\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\u3002\u7b46\u8005\u5c07\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Python\u7a0b\u5f0f\u6a94\u547d\u540d\u6210tube_list.py\uff0c\u5b83\u652f\u63f4\u4e4b\u524d\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c3\u6578\uff0c\u5982\uff1a-a\uff08\u50c5\u4e0b\u8f09\u8072\u97f3\uff09\u548c-fhd\uff08\u9ad8\u756b\u8cea\u683c\u5f0f\uff09\uff0c\u4e26\u65b0\u589e\u4e00\u500b\u6307\u5b9a\u4e0b\u8f09\u5f71\u7247\u6578\u91cf\u7684-end\u53c3\u6578\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/images\/books\/python\/PyTube\/modded_main_code.png\" width=\"708\" height=\"607\" alt=\"\u4fee\u6539main()\u51fd\u5f0f\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[3],"tags":[49],"class_list":["post-1599","post","type-post","status-publish","format-standard","hentry","category-3","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247 - \u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8<\/title>\n<meta name=\"description\" content=\"\u4e0b\u8f09YouTube\u5f71\u7247\u7684Pytube\u7a0b\u5f0f\u5eab\u6709\u500b\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Playlist\u985e\u5225\uff0c\u672c\u6587\u5c07\u4fee\u6539\u4e4b\u524d\u7684YouTube\u5f71\u97f3\u4e0b\u8f09\u7a0b\u5f0f\u78bc\uff0c\u8b93\u5b83\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\u3002\u9019\u500bPython\u7a0b\u5f0f\u6a94\u547d\u540d\u6210tube_list.py\uff0c\u5b83\u652f\u63f4\u4e4b\u524d\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c3\u6578\u4e26\u65b0\u589e\u6307\u5b9a\u4e0b\u8f09\u5f71\u7247\u6578\u91cf\u7684-end\u53c3\u6578\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swf.com.tw\/?p=1599\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005:\" \/>\n\t<meta name=\"twitter:data1\" content=\"cubie\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u4f30\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599\"},\"author\":{\"name\":\"cubie\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#\\\/schema\\\/person\\\/24480fda9184aa137df8f05d79bc2f57\"},\"headline\":\"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\",\"datePublished\":\"2021-08-25T09:02:56+00:00\",\"dateModified\":\"2021-10-19T23:24:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599\"},\"wordCount\":117,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#organization\"},\"keywords\":[\"Python\"],\"articleSection\":[\"\u6559\u5b78\u6587\u4ef6\"],\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/swf.com.tw\\\/?p=1599#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599\",\"url\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599\",\"name\":\"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247 - \u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#website\"},\"datePublished\":\"2021-08-25T09:02:56+00:00\",\"dateModified\":\"2021-10-19T23:24:15+00:00\",\"description\":\"\u4e0b\u8f09YouTube\u5f71\u7247\u7684Pytube\u7a0b\u5f0f\u5eab\u6709\u500b\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Playlist\u985e\u5225\uff0c\u672c\u6587\u5c07\u4fee\u6539\u4e4b\u524d\u7684YouTube\u5f71\u97f3\u4e0b\u8f09\u7a0b\u5f0f\u78bc\uff0c\u8b93\u5b83\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\u3002\u9019\u500bPython\u7a0b\u5f0f\u6a94\u547d\u540d\u6210tube_list.py\uff0c\u5b83\u652f\u63f4\u4e4b\u524d\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c3\u6578\u4e26\u65b0\u589e\u6307\u5b9a\u4e0b\u8f09\u5f71\u7247\u6578\u91cf\u7684-end\u53c3\u6578\u3002\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swf.com.tw\\\/?p=1599\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/?p=1599#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swf.com.tw\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#website\",\"url\":\"https:\\\/\\\/swf.com.tw\\\/\",\"name\":\"\u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8\",\"description\":\"Arduino+Python+JavaScript+\u7a0b\u5f0f\u8a2d\u8a08+\u786c\u9ad4DIY\",\"publisher\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swf.com.tw\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#organization\",\"name\":\"\u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8\",\"url\":\"https:\\\/\\\/swf.com.tw\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swf.com.tw\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/logo_bat.png\",\"contentUrl\":\"https:\\\/\\\/swf.com.tw\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/logo_bat.png\",\"width\":71,\"height\":65,\"caption\":\"\u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8\"},\"image\":{\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swf.com.tw\\\/#\\\/schema\\\/person\\\/24480fda9184aa137df8f05d79bc2f57\",\"name\":\"cubie\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c77b6f4d3b4ccdcdc343aeee53301c212f54787c43bd2ebf6648bf74ff59b474?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c77b6f4d3b4ccdcdc343aeee53301c212f54787c43bd2ebf6648bf74ff59b474?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c77b6f4d3b4ccdcdc343aeee53301c212f54787c43bd2ebf6648bf74ff59b474?s=96&d=retro&r=g\",\"caption\":\"cubie\"},\"sameAs\":[\"https:\\\/\\\/swf.com.tw\"],\"url\":\"https:\\\/\\\/swf.com.tw\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247 - \u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8","description":"\u4e0b\u8f09YouTube\u5f71\u7247\u7684Pytube\u7a0b\u5f0f\u5eab\u6709\u500b\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Playlist\u985e\u5225\uff0c\u672c\u6587\u5c07\u4fee\u6539\u4e4b\u524d\u7684YouTube\u5f71\u97f3\u4e0b\u8f09\u7a0b\u5f0f\u78bc\uff0c\u8b93\u5b83\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\u3002\u9019\u500bPython\u7a0b\u5f0f\u6a94\u547d\u540d\u6210tube_list.py\uff0c\u5b83\u652f\u63f4\u4e4b\u524d\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c3\u6578\u4e26\u65b0\u589e\u6307\u5b9a\u4e0b\u8f09\u5f71\u7247\u6578\u91cf\u7684-end\u53c3\u6578\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swf.com.tw\/?p=1599","twitter_misc":{"\u4f5c\u8005:":"cubie","\u9810\u4f30\u95b1\u8b80\u6642\u9593":"4 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swf.com.tw\/?p=1599#article","isPartOf":{"@id":"https:\/\/swf.com.tw\/?p=1599"},"author":{"name":"cubie","@id":"https:\/\/swf.com.tw\/#\/schema\/person\/24480fda9184aa137df8f05d79bc2f57"},"headline":"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247","datePublished":"2021-08-25T09:02:56+00:00","dateModified":"2021-10-19T23:24:15+00:00","mainEntityOfPage":{"@id":"https:\/\/swf.com.tw\/?p=1599"},"wordCount":117,"commentCount":0,"publisher":{"@id":"https:\/\/swf.com.tw\/#organization"},"keywords":["Python"],"articleSection":["\u6559\u5b78\u6587\u4ef6"],"inLanguage":"zh-TW","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/swf.com.tw\/?p=1599#respond"]}]},{"@type":"WebPage","@id":"https:\/\/swf.com.tw\/?p=1599","url":"https:\/\/swf.com.tw\/?p=1599","name":"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247 - \u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8","isPartOf":{"@id":"https:\/\/swf.com.tw\/#website"},"datePublished":"2021-08-25T09:02:56+00:00","dateModified":"2021-10-19T23:24:15+00:00","description":"\u4e0b\u8f09YouTube\u5f71\u7247\u7684Pytube\u7a0b\u5f0f\u5eab\u6709\u500b\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u5f71\u7247\u7684Playlist\u985e\u5225\uff0c\u672c\u6587\u5c07\u4fee\u6539\u4e4b\u524d\u7684YouTube\u5f71\u97f3\u4e0b\u8f09\u7a0b\u5f0f\u78bc\uff0c\u8b93\u5b83\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247\u3002\u9019\u500bPython\u7a0b\u5f0f\u6a94\u547d\u540d\u6210tube_list.py\uff0c\u5b83\u652f\u63f4\u4e4b\u524d\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c3\u6578\u4e26\u65b0\u589e\u6307\u5b9a\u4e0b\u8f09\u5f71\u7247\u6578\u91cf\u7684-end\u53c3\u6578\u3002","breadcrumb":{"@id":"https:\/\/swf.com.tw\/?p=1599#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swf.com.tw\/?p=1599"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/swf.com.tw\/?p=1599#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swf.com.tw\/"},{"@type":"ListItem","position":2,"name":"YouTube\u5f71\u7247\u4e0b\u8f09\uff08\u4e03\uff09\uff1a\u4e0b\u8f09\u64ad\u653e\u6e05\u55ae\u4e2d\u7684\u5168\u90e8\u5f71\u7247"}]},{"@type":"WebSite","@id":"https:\/\/swf.com.tw\/#website","url":"https:\/\/swf.com.tw\/","name":"\u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8","description":"Arduino+Python+JavaScript+\u7a0b\u5f0f\u8a2d\u8a08+\u786c\u9ad4DIY","publisher":{"@id":"https:\/\/swf.com.tw\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swf.com.tw\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-TW"},{"@type":"Organization","@id":"https:\/\/swf.com.tw\/#organization","name":"\u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8","url":"https:\/\/swf.com.tw\/","logo":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/swf.com.tw\/#\/schema\/logo\/image\/","url":"https:\/\/swf.com.tw\/wp-content\/uploads\/2019\/10\/logo_bat.png","contentUrl":"https:\/\/swf.com.tw\/wp-content\/uploads\/2019\/10\/logo_bat.png","width":71,"height":65,"caption":"\u8d85\u5716\u89e3\u7cfb\u5217\u5716\u66f8"},"image":{"@id":"https:\/\/swf.com.tw\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/swf.com.tw\/#\/schema\/person\/24480fda9184aa137df8f05d79bc2f57","name":"cubie","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/secure.gravatar.com\/avatar\/c77b6f4d3b4ccdcdc343aeee53301c212f54787c43bd2ebf6648bf74ff59b474?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c77b6f4d3b4ccdcdc343aeee53301c212f54787c43bd2ebf6648bf74ff59b474?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c77b6f4d3b4ccdcdc343aeee53301c212f54787c43bd2ebf6648bf74ff59b474?s=96&d=retro&r=g","caption":"cubie"},"sameAs":["https:\/\/swf.com.tw"],"url":"https:\/\/swf.com.tw\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/swf.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/1599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swf.com.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swf.com.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swf.com.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swf.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1599"}],"version-history":[{"count":0,"href":"https:\/\/swf.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/1599\/revisions"}],"wp:attachment":[{"href":"https:\/\/swf.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swf.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swf.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}