I'm trying to get a link to a video, but I'm getting an error. I don't know how to fix this. I spent a lot of time looking for a way to fix it, but I don’t have the strength anymore. Help :) My code:
from pytube import YouTube
link = "https://www.youtube.com/watch?v=9pmsuKWKf90"
yt = YouTube(link)
print(yt.streams)
itag = 137
url = YouTube(link).streams.get_by_itag(itag).url
print(url)
Traceback
File "D:\Python\ffmpeg\link_video.py", line 5, in <module>
print(yt.streams)
File "D:\Python\ffmpeg\venv\lib\site-packages\pytube\__main__.py", line 295, in streams
self.check_availability()
File "D:\Python\ffmpeg\venv\lib\site-packages\pytube\__main__.py", line 233, in check_availability
raise exceptions.LiveStreamError(video_id=self.video_id)
pytube.exceptions.LiveStreamError: 9pmsuKWKf90 is streaming live and cannot be loaded
Let me clarify: need to get a link to download the stream. The question is relevant
You cannot print it because it is a livestream, and that functionality is not supported.
EDIT: You can access data of a livestreamed video using the following code (m39SPyU3abg is the video id of a currently livestreaming video; it may not be live streaming when you use this code). I kept it in Python, but did not use Pytube, since Pytube is not designed for live streaming.
SECOND EDIT: The url is constructed from the video_id. You do have the video_id, correct? If you also have the channel_id, you would not need to make an API call and could construct the url yourself. But if you do not have it, this code determines the channel_id and creates the url: