Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. β We all watch YouTube - almost daily. Only a few however know how to control it with Python. Today we will use pytubefix - a Python library that provides access to YouTube. Know video stats (# views, upload date) or download them, all in a line of code β οΈ Note: Respect YouTubeβs terms and download only content you own or have permission for. β π¦ Install pytubefix
In:
pip install pytubefix
Out:
β π‘ Basic housekeeping - Check version
In:
import pytubefix print(pytubefix.__version__)
Out:
'9.5.0'
β π‘ Basic housekeeping - Import "YouTube" class directly Pandas Daily readers know why this works better than importing all of pytubefix (above snippet)
In:
from pytubefix import YouTube
Out:
β π¬ Create YouTube object (yt) - Swifties will love it β£οΈ
In:
url = "https://www.youtube.com/watch?v=nn_0zPAfyo8" yt = YouTube(url)
Out:
β π Video Title π
In:
yt.title
Out:
'Taylor Swift β august (Official Lyric Video)'
β π·οΈ Know important stats right away
In:
print(yt.length) print(yt.author) print(yt.publish_date) print(yt.views)
Out:
264 TaylorSwiftVEVO 2020-07-23 21:00:15-07:00 126155556 β π₯ Download and save on your machine
In:
stream = yt.streams.get_highest_resolution() stream.download()
Out:
'/user/home/directory/path/Taylor Swift β august (Official Lyric Video).mp4'
β π‘ Want to know how to save video somewhere else? Or download in a different resolution? Tune in tomorrow!! βπ£ That's it for today! If you liked it, please share it with anyone who will find it useful and share your feedback below πΌ
β |
Beginner to Expert in Python in just 5 minutes
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. I am sure when you print C:\new_folder your code breaks due to \. Or you wonder how to print single (It's) or double ("Hello") quotes. Enter Escape Sequences, tiny backslash commands in Python that fix all of this. π Most common uses: Format using new lines Print tabs Single or double quotes in text Write file paths safely Print symbols like Ο orβ€οΈ Let's Begin... π \n Print in next line - the one we all...
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Think about the time you waste right-clicking and saving course lectures on YouTube one-by-one. Inefficient process, can cause errors and you lose focus. pytubefix eliminates that bottleneck. Today is day 3 of mastering YouTube with Python. You already know how to get stats of a single video; or download them in various formats. Now time to level up with playlists. Pytubefix has a Playlist object that...
Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Yesterday we introduced pytubefix - a powerful module to access YouTube. We downloaded a video as well. Cool, but basic. What if you want 1080p instead of 480p. Or prefer WebM over MP4. To answer all this - let's cover downloads in depth today. π€« I am 100% sure you can charm recruiters or your colleagues as they won't know this! π₯ Code Recap: How to download YouTube video In: # Import library from...