The short answer is the following: you'll have to filter out manually the videos that are live streams from each result set obtained from the Search.list
API endpoint.
The longer answer follows below:
A given video is a live stream if and only if that video has attached the property liveStreamingDetails
.
I'd warmly recommend to go through a very recent answer of mine that details a Python solution to precisely this issue, the function get_non_livestream_videos
:
def get_non_livestream_videos(youtube, video_ids):
assert len(video_ids) <= 50
if not video_ids: return []
response = youtube.videos().list(
fields = 'items(id,liveStreamingDetails)',
part = 'id,liveStreamingDetails',
maxResults = len(video_ids),
id = ','.join(video_ids),
).execute()
items = response.get('items', [])
assert len(items) <= len(video_ids)
not_live = lambda video:
not video.get('liveStreamingDetails')
video_id = lambda video: video['id']
return map(video_id, filter(not_live, items))
If you have a list of video IDs video_ids
then this function calls the Videos.list
API endpoint for to determine the existence of the property liveStreamingDetails
for each of the respective videos. Any video that has such a property gets filtered out from the resulting list of video IDs.
Note that above I used the fields
request parameter for to get from the APIs only the info that's actually needed.
Also note that a precondition of using get_non_livestream_videos
is that its list argument video_ids
to be of at most 50 elements.
This is not an actual restriction when using this function, because it's supposed to be used on a list of video IDs that's obtained from a paged API result set. (Search.list
returns paginated result sets of at most 50 items.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…