Extract YouTube Shorts from specific channel using YouTube Data API v3

I’m trying to figure out how to fetch YouTube Shorts content from a particular channel using the YouTube Data API v3. I’ve been searching for a solution but haven’t found any clear documentation or examples.

What I’ve tried so far

I can successfully retrieve the playlist ID containing all videos from a channel using:

response = youtube_service.channels().list(
    part="contentDetails",
    channelId=channel_id
)

I also experimented with additional parameters to see if it would help:

response = youtube_service.channels().list(
    part="snippet,contentDetails,statistics,brandingSettings",
    channelId=channel_id
)

My question

Is there a specific method or parameter in the YouTube Data API v3 that allows filtering for Shorts content only? If not, are there any alternative approaches or third-party solutions that can help me achieve this goal?

no direct way exists, but I’ve found video descriptions help. most shorts include #shorts hashtag or mention “shorts” in the description. pair that with duration filtering (under 60 seconds) for better results. shorts typically use 9:16 aspect ratio too, so you can filter by that in video details if you need to.

YouTube’s API doesn’t filter Shorts directly, but you can catch them by duration. Grab the playlist items from the channel’s uploads, then hit the videos endpoint with those IDs to get durations. Shorts are usually 60 seconds or under, so filter for duration <= PT1M (ISO 8601 format). I’ve done this on multiple projects - works great. Just watch your API quota since you’ll need two calls: one for playlist items, another for video details. Some devs check if it’s uploaded from mobile, but I find duration filtering way more reliable.

The Problem:

You’re trying to retrieve only YouTube Shorts content from a specific channel using the YouTube Data API v3, but the API doesn’t offer direct filtering for Shorts. Existing methods like filtering by duration (duration <= PT1M) may miss some Shorts or include non-Shorts videos. You need a more robust and accurate method to identify and retrieve Shorts content.

:thinking: Understanding the “Why” (The Root Cause):

The YouTube Data API v3 doesn’t have a dedicated field to directly identify Shorts. This is because the definition of a “Short” isn’t solely based on video length or aspect ratio; YouTube uses internal metadata and other signals to classify content. Relying solely on duration (duration <= PT1M) or aspect ratio is unreliable because:

  • Duration: Some Shorts might be longer than 60 seconds, and some regular videos might be shorter.
  • Aspect Ratio: While many Shorts use a vertical aspect ratio (9:16), not all do. Conversely, some regular videos might also use this ratio.

Therefore, a more comprehensive approach is needed, combining multiple signals to increase accuracy.

:gear: Step-by-Step Guide:

Step 1: Combine Multiple Signals for Accurate Detection:

Instead of relying on a single filter, use a combination of criteria to improve the accuracy of identifying YouTube Shorts. This approach leverages several characteristics commonly associated with Shorts:

  1. Duration: Use the duration field (within the contentDetails part) to filter videos shorter than or equal to a certain duration (e.g., PT1M for 1 minute).
  2. Upload Date: Filter by recent uploads, as Shorts are more commonly recent content. You can do this by sorting the results by published date.
  3. Video Statistics: Analyze video statistics (part statistics) like view counts, like counts, and comment counts. Shorts often exhibit different engagement patterns compared to regular videos. This can be a helpful additional filter.
  4. Snippet Analysis (Advanced): Look within the snippet part for potential metadata keywords or tags associated with Shorts, although this is less reliable and may change over time.

Step 2: Implement the Combined Filtering in Your Code:

You’ll need to make multiple API calls. First, get a list of videos from the channel’s upload playlist. Then, use the video IDs obtained from that step to fetch detailed video information, including duration and statistics. This will require careful pagination and error handling to efficiently process large numbers of videos. Here’s a conceptual Python example, not including error handling or pagination:

from googleapiclient.discovery import build

youtube = build('youtube', 'v3', developerKey='YOUR_API_KEY')

#Get the uploads playlistId
response = youtube.channels().list(part="contentDetails", channelId=channel_id).execute()
playlist_id = response['items'][0]['contentDetails']['relatedPlaylists']['uploads']

#Get playlist items (videos)
request = youtube.playlistItems().list(
    part="snippet",
    playlistId=playlist_id,
    maxResults=50
)
response = request.execute()
video_ids = [item['snippet']['resourceId']['videoId'] for item in response['items']]

#Get video details with duration and statistics
video_details = []
for i in range(0, len(video_ids), 50):  # Process in batches of 50 to avoid exceeding quotas
    batch = video_ids[i:i + 50]
    request = youtube.videos().list(
        part="snippet,contentDetails,statistics",
        id=",".join(batch)
    )
    response = request.execute()
    video_details.extend(response['items'])

#Filter for Shorts based on multiple criteria (adjust thresholds as needed)
shorts = [video for video in video_details if 
          (video['contentDetails']['duration'] <= 'PT1M' and #Duration
           video['snippet']['publishedAt'] > '2023-01-01T00:00:00Z') and #Recent upload (adjust date range)
           int(video['statistics'].get('viewCount', 0)) > 100 #Example engagement check
         ]


print(f"Found {len(shorts)} Shorts.")
for short in shorts:
    print(short['snippet']['title'])

Step 3: Handle API Quotas and Rate Limits:

Be mindful of the YouTube Data API v3 usage quotas. Implement error handling, retry mechanisms, and batch processing to manage potential rate limits and efficiently handle large datasets. Consider exponential backoff strategies for retrying failed API requests.

:mag: Common Pitfalls & What to Check Next:

  • API Key: Ensure you have a valid API key and are not exceeding daily quota limits.
  • Date Range: Adjust the publishedAt filter’s date range to capture Shorts uploaded within a relevant period.
  • Engagement Thresholds: Experiment with different thresholds for view counts, like counts, and other video statistics to optimize the accuracy of your filtering criteria.
  • False Positives/Negatives: Expect some inaccuracies. You’ll likely need to fine-tune the thresholds in your criteria to minimize false positives (regular videos misclassified as Shorts) and false negatives (Shorts that aren’t detected).
  • Advanced Techniques: Explore more sophisticated techniques, like machine learning models trained on YouTube Shorts data, for higher accuracy but with increased complexity.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

Manual filtering works but gets messy with multiple channels or real-time updates. Hit this exact issue last year building a content analysis system.

What I learned: duration checks + hashtag detection catch most Shorts, but you’ll miss edge cases. API quota burns fast with extra calls too.

Ended up automating everything instead. Built a workflow that pulls channel data, filters by duration/keywords, then sorts into buckets. Handles quota management and retries automatically.

You can build this without writing tons of Python. Just chain API calls and add filtering logic between them. Way cleaner than managing responses manually.

Best part? Runs on schedule so you get fresh Shorts data without babysitting.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.