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="/todi/rectory"
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")
來自 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=ecK3EnyGD8o 持續時間:486 秒---標題:管理GitHub 組織工具、提示和最佳實踐 - Mark MatyasURL:https://youtube.com/watch?v=1T4HAPBFbb0Duration:1525 秒---標題:你知道管理GitHub Issues 的最佳方法嗎? /youtube.com/watch?v=OccRyzAS4VcDuration : 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=LbtrnCjopwkhttps://youtube.com/watch ?v=pfl2ga6AS3chttps://youtube.com/watch?v=TzNk2ygEU4chttps://youtube.com/watch?v=yQfXVRKvA70https:/ /youtube.com/watch?v=G5tQX990XU0https://youtube.com/watch?v =4LQzYMhtXV8https://youtube.com/watch?v=BOLGwdjCSAohttps://youtube.com/watch?v=CgSH3Ww3MHshttps://youtube .com/watch?v=_43tx98VEWchttps://youtube.com/watch?v=wLDRGZaBEoQhttps ://youtube.com/watch?v=3qaHb2t3Lkwhttps://youtube.com/watch?v=56deLmbicLghttps://youtube.com /watch?v=pQk2TzmwnS0https://youtube.com/watch?v=NJ3sOlg8KGohttps:/ /youtube.com/watch?v=kfDSHjlk4Pghttps://youtube.com/watch?v=8KHak4ZNO3k>>>