如何通过YouTube Data API匹配频道公开Videos标签页:排除存档直播并保留首映视频
Great question — this is a common pain point because the obvious API fields (liveBroadcastContent and liveStreamingDetails) don’t clearly differentiate between premiere videos that show up in the Videos tab and archived livestreams that don’t. Here’s what you need to know:
The Core Issue
As you saw, both premiere videos and archived livestreams can return none for liveBroadcastContent and have the liveStreamingDetails field present once they’ve aired. This is because premieres are technically scheduled live events that convert to regular videos after airing, while archived livestreams are recordings of past live broadcasts. YouTube’s frontend separates these in the Videos tab vs. Live tab, but the raw video metadata doesn’t flag this distinction directly.
The Reliable Solution: Use the Channel’s "Uploads" Playlist
The Videos tab on a YouTube channel is populated exclusively from the channel’s official "uploads" playlist. Archived livestreams live in a separate "live" playlist and won’t appear here. Here’s how to leverage this via the API:
Step 1: Get the Channel’s Uploads Playlist ID
First, fetch the channel’s metadata to retrieve the ID of its uploads playlist:
import requests YT_API_KEY = "YOUR_API_KEY" CHANNEL_URL = "https://www.googleapis.com/youtube/v3/channels" # Get channel details using username (or use id parameter if you have the channel ID) resp = requests.get( CHANNEL_URL, params={ "part": "contentDetails", "forUsername": "LiquidZulu", "key": YT_API_KEY, }, timeout=30 ).json() uploads_playlist_id = resp["items"][0]["contentDetails"]["relatedPlaylists"]["uploads"] print(f"Uploads Playlist ID: {uploads_playlist_id}")
Step 2: Fetch Videos from the Uploads Playlist
Next, use the playlist ID to pull all videos that appear in the channel’s Videos tab. This will include premieres (once they’ve aired) and regular uploaded videos, but exclude archived livestreams:
PLAYLIST_ITEMS_URL = "https://www.googleapis.com/youtube/v3/playlistItems" # Fetch playlist items (you may need to handle pagination with pageToken for large playlists) resp = requests.get( PLAYLIST_ITEMS_URL, params={ "part": "snippet,contentDetails", "playlistId": uploads_playlist_id, "maxResults": 50, "key": YT_API_KEY, }, timeout=30 ).json() # Check if your test videos are in the uploads playlist for item in resp["items"]: video_id = item["contentDetails"]["videoId"] print(f"Video in Videos tab: {video_id}")
Bonus: Identify Premiere Videos Within the Uploads Playlist
If you need to specifically flag premieres among the uploads, you can check for the liveStreamingDetails.scheduledStartTime field in the video’s metadata. Premieres will have this field set (indicating they were scheduled in advance), while regular uploaded videos won’t.
Why This Works
YouTube’s frontend uses the uploads playlist as the source for the Videos tab, and archived livestreams are never added to this playlist — they’re only in the live playlist. This is the most accurate way to replicate the channel’s Videos tab content via the API, since there’s no single metadata field that directly marks this distinction.
内容的提问来源于stack exchange,提问作者FluidMechanics Potential Flows




