pytubefix
Pytubefix 8.3.2 Released
pip install pytubefix
从 pytubefix 导入 YouTubefrom pytubefix.cli 导入 on_progress 网址=“网址” yt = YouTube(url, on_progress_callback = on_progress)print(yt.title) ys = yt.streams.get_highest_resolution()ys.download()
从 pytubefix 导入 YouTubefrom pytubefix.cli 导入 on_progress 网址=“网址” yt = YouTube(url, on_progress_callback = on_progress)print(yt.title) ys = yt.streams.get_audio_only()ys.download(mp3=True)
从 pytubefix 导入播放列表从 pytubefix.cli 导入 on_progress url = "url"pl = pl.videos 中视频的播放列表(url):ys = video.streams.get_audio_only()ys.download(mp3=True)
从 pytubefix 导入 YouTubefrom pytubefix.cli 导入 on_progress url =“url”yt = YouTube(url,use_oauth = True,allow_oauth_cache = True,on_progress_callback = on_progress) ys = yt.streams.get_highest_resolution()ys.download() # 下载后才会收到验证请求
从 pytubefix 导入 YouTubefrom pytubefix.cli 导入 on_progressurl = "url"yt = YouTube(url, on_progress_callback = on_progress)ys = yt.streams.get_highest_resolution()ys.download(output_path="path/to/directory")
from pytubefix import YouTubeyt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')subtitles = yt.captionsprint(字幕)
从 pytubefix 导入 YouTube yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')caption = yt.captions['a.en']print(caption.generate_srt_captions())
从 pytubefix 导入 YouTube yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')caption = yt.captions['a.en']caption.save_captions("captions.txt")
from pytubefix import Channelc = Channel("https://www.youtube.com/@ProgrammingKnowledge/featured")print(f'频道名称: {c.channel_name}')
from pytubefix import Channelc = Channel("https://www.youtube.com/@ProgrammingKnowledge")print(f'通过以下方式下载视频:{c.channel_name}')对于 c.videos 中的视频:download = video.streams. get_highest_resolution().download()
>>> from pytubefix import Search>>> >>> results = Search('Github Issue Best Practices')>>> >>> results.videos 中的视频: ... print(f'标题: {video.title}') ... print(f'URL: {video.watch_url}') ... print(f'持续时间:{video.length} 秒') ... 打印(' - -') ... 标题:GitHub 问题的良好实践URL:https://youtube.com/watch?v=v1AeHaopAYED 持续时间:406 秒---标题:GitHub 问题提示和指南URL:https://youtube.com/watch?v=kezinXSoV5AD 持续时间:852秒---标题:13 种高级(但有用)Git 技术和快捷方式URL: https://youtube.com/watch?v=ecK3EnyGD8oDuration:486 秒---标题:管理 GitHub 组织工具、提示和最佳实践 - Mark MatyasURL:https://youtube.com/watch?v=1T4HAPBFbb0Duration: 1525 秒---标题:你知道管理 GitHub Issues 的最佳方法吗?网址: https://youtube.com/watch?v=OccRyzAS4Vc持续时间:534秒--->>>
>>> from pytubefix.contrib.search import 搜索、过滤>>> >>> >>> f = { ... 'upload_data': Filter.get_upload_data('今天'), ... '类型': Filter.get_type("视频"), ... 'duration': Filter.get_duration("4 分钟以下"), ...'功能':[Filter.get_features(“4K”),Filter.get_features(“知识共享”)], ... 'sort_by': Filter.get_sort_by("上传日期") ... }>>> >>> s = Search('music',filters=f)>>> for c in s.videos: ... 打印(c.watch_url) ... https://youtube.com/watch?v=_Rq8MzYz0YU https://youtube.com/watch?v=YHPGM8nBk3U https://youtube.com/watch?v=m98WShs7MLE https://youtube.com/watch?v=-vBqfC3Nir0 https://youtube.com/watch?v=m98WShs7MLE https://youtube.com/watch?v=-vBqfC3Nir0https ://youtube.com/watch?v=LbtrnCjopwk https://youtube.com/watch?v=pfl2ga6AS3c https://youtube.com/watch?v=TzNk2ygEU4c https://youtube.com/watch?v=yQfXVRKvA70 https://youtube.com/watch?v=G5tQX990XU0 https: //youtube.com/watch?v=4LQzYMhtXV8h ttps://youtube.com/watch?v=BOLGwdjCSAo https://youtube.com/watch?v=CgSH3Ww3MHs https://youtube.com/watch?v=_43tx98VEWc https://youtube.com/watch?v=wLDRGZaBEoQ https: //youtube.com/watch?v=3qaHb2t3Lkwht tps://youtube.com/watch?v=56deLmbicLg https://youtube.com/watch?v=pQk2TzmwnS0 https://youtube.com/watch?v=NJ3sOlg8KGo https://youtube.com/watch?v=kfDSHjlk4Pg https: //youtube.com/watch?v=8KHak4ZNO3k>>>