Reputation: 47
I can judge whether this video is live by judging whether there is liveStreamingDetails in the collected data.
if 'liveStreamingDetails' in video_data:
video_type = 'live'
But doing so will treat the premiere video as a live broadcast.
How to avoid this?
Upvotes: 0
Views: 1268
Reputation: 47
I managed to find a way to distinguish whether a video is live or premiered.
I refer to the answer from Use beautifulsoup to get a youtube video‘s information.
from requests_html import HTMLSession
from bs4 import BeautifulSoup
video_url = "YouTube Url"
session = HTMLSession()
response = session.get(video_url)
response.html.render(sleep=3)
soup = BeautifulSoup(response.html.html, "lxml")
if soup.select_one('#info-strings').text[:8] == 'Streamed':
video_type = 'live'
else:
video_type = 'video'
Upvotes: 1
Reputation: 5612
As far as I tested, the liveStreamingDetails:concurrentViewers entry is missing for premiere videos being broadcasted. So you can check, using for instance Videos: list, if this entry is part of the response to know whether or not the video is a livestream being broadcasted or a premiere being broadcasted.
Upvotes: 0