Popyt

website·Indexed 29 days ago

https://popyt.brandonsbench.net

A library for interacting with YouTube, featuring a YouTube class for searching channels and getting channel sections, as well as OAuth support via classes like OAuthChannels, OAuthVideos, OAuthComments, and OAuthPlaylists.

Tokens
19.3K
Snippets
163
Records
208
Agent score
49%

What's inside Popyt

  1. Overview of Popyt for YouTube Data API

    Popyt is a tool designed for quick installation and intuitive downloading from and uploading to the YouTube Data API. It handles the background work of parsing YouTube API data into a well-documented, easy-to-use format, allowing developers to focus on data retrieval.
  2. Channel class properties reference

    Basic Information

    • id (string): The unique ID of the channel.
    • name (string): The name of the channel.
    • about (string): The channel description.
    • url (string): The channel URL.
    • customUrl (string): The custom URL, if available.
    • country (string): The country where the channel is based.
    • language (string): The default upload language.
    • dateCreated (Date): The date the channel was created.
    • keywords (string[]): The channel's keywords.
    • subCount (number): Number of subscribers. Returns -1 if the count is hidden.

    Media and Visuals

    • banner (string): URL to the channel banner image.
    • profilePictures (object): Contains various thumbnail sizes (default, high, maxres, medium, standard).

    Status and Metadata

    • full (boolean): Indicates if this is a full channel object.
    • data (any): The raw data of the channel.
    • liveStatus (false | "live" | "upcoming"): Only set if the channel is a search result. Indicates if there is an ongoing or upcoming livestream.
    • kids (object): Contains madeForKids and selfDeclaredMadeForKids booleans.
    • localizations (object): A map of language codes to Schema$ChannelLocalization objects.

    Lazy-Loaded Properties

    These properties are only defined after their respective fetch methods are called:

    • playlists: A PaginatedResponse of Playlist objects (populated via fetchPlaylists()).
    • subscriptions: A PaginatedResponse of Subscription objects (populated via fetchSubscriptions()).
    • sections: An array of ChannelSection objects (populated via fetchSections()).
    • featuredChannels (string[]): URLs of featured channels (Note: this property may be broken for some channels).
  3. Video class properties reference

    The Video class provides extensive metadata about a YouTube video. Key properties include:

    • Identification & Links: id (string), shortUrl (string, e.g., https://youtu.be/id).
    • Content Details: description (string), tags (string[]), category (string), license ("creativeCommon" | "youtube").
    • Timing: datePublished (Date), dateRecorded (Date), minutes (number), seconds (number).
    • Engagement: likes (number), dislikes (number), commentCount (number).
    • Status: liveStatus (false | "live" | "upcoming"), private (boolean - indicates if the video could be private).
    • Channel Info: channel object containing id and name.
    • Kids Content: kids object containing madeForKids and selfDeclaredMadeForKids (booleans).
    • Localization: localizations object mapping language strings to localized data.
    • Raw Data: data (any) contains the raw video data.
    • Full Object Status: full (boolean) indicates if this is a full video object.
  4. Fetch videos from a playlist

    Because Popyt does not fetch child objects automatically to save quota, you must explicitly call fetchVideos() on a playlist object to retrieve its videos. Once fetched, videos are available both as the return value of the method and via the playlist.videos array.
    const videos = await playlist.fetchVideos()
    
    console.log(`First video: ${playlist.videos[0].title}`)
    console.log(`Last video: ${videos[videos.length - 1].title}`)
  5. Access captions and comments for a Video

    Captions and comments are not available by default upon instantiation. They must be explicitly fetched using the class methods:

    • Captions: Accessible via the captions property (Caption[]) only after calling Video.fetchCaptions().
    • Comments: Accessible via the comments property (PaginatedResponse<Comment>) only after calling Video.fetchComments().
  6. Initialize the YouTube client

    The YouTube class is the primary entry point for interacting with the YouTube API. It can be configured with an API key for general data access or an OAuth access token for authenticated methods.
    const yt = new YouTube(
      'YOUR_API_KEY',
      'YOUR_ACCESS_TOKEN',
      { /* caching options */ },
      'en_US',
      'US'
    );
  7. Fetch full video details from a playlist item

    Videos retrieved from playlists (playlist items) contain limited information. To access full metadata (such as commentCount), you must call the .fetch() method on the individual video object. The video.full property indicates whether the full data has been loaded.
    const video = playlist.videos[0]
    
    console.log(video.full) // false
    console.log(video.commentCount) // undefined
    
    await video.fetch()
    
    console.log(video.full) // true
    console.log(video.commentCount) // the number of comments on the video
  8. Install Popyt

    Popyt is a Node.js YouTube API wrapper that provides typings, promises, and caching for the YouTube Data v3 API. It can be installed using npm, Yarn, pnpm, or Bun.
    npm install popyt