npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tubby

v0.3.3

Published

youtube channel instant search

Downloads

246

Readme

tubby — youtube playlist search

using the <tubby-youtube-explorer> component on your webpage

  1. first, you need access to the youtube api, and have your api key ready

    • login with the google developer console, and get yourself a youtube api key
    • you have to whitelist your domains with that api key
    • you can have an api key that allows 'localhost' for testing
  2. install tubby on your page

    • include the following snippet on your page

      <script type="importmap-shim">
        {
          "imports": {
            "lit-html/": "https://unpkg.com/[email protected]/",
            "lit-html": "https://unpkg.com/[email protected]/lit-html.js",
            "lit-element/": "https://unpkg.com/[email protected]/",
            "lit-element": "https://unpkg.com/[email protected]/lit-element.js",
            "tubby/": "https://unpkg.com/[email protected]/",
            "tubby": "https://unpkg.com/[email protected]/dist/index.js"
          }
        }
      </script>
      <script type="module-shim">
        import "tubby/dist/register-all.js"
      </script>
      <script src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>

      here's what's going on in this snippet

      • import maps
        • we provide an import map which locates tubby and its dependencies
        • of course, for the import map, we're using guy bedford's awesome polyfill: es-module-shims
        • if you're from the future, you won't need the -shim's
      • register the web components
        • we run import "tubby/dist/register-all.js" to register the <tubby-youtube-explorer> component
  3. place the explorer html on your page

    <tubby-youtube-explorer
      search
      max-description-length="360"
      api-key="AIzaSyDeHpB9W14feQs8myoWgFAZOCrDeKMLRwE"
      playlist-id="UUL_f53ZEJxp8TtlOkHwMV9Q"
      canned="dist-demo/canned-videos.json"
      >
    </tubby-youtube-explorer>

    the youtube explorer fetches the specified youtube playlist, and displays video thumbnails in a grid formation, and optionally has a searchbar for filtering the video selection

    youtube's api limits us to 50 videos at a time, so tubby does the hard work and requests every video sequentially, using back-to-back calls until it finds every video in the playlist

    tubby has a simple dev-time caching mechanism i call "canning videos"

  4. know how to configure the explorer for your use-case

    all of tubby's configurable properties are optional, but you probably want to use a combination that loads some videos

    • ⚓ string attributes [api-key] and [playlist-id]
      tubby will fetch all the videos in that playlist

    • ⚓ string attributes [api-key] and [channel-id]
      tubby will make an extra round trip to find the playlist called "uploads".
      it is faster to provide the [playlist-id] attribute instead

    • ⚓ string attribute [canned] url
      tubby will fetch these cached videos.
      if a playlist is also being fetched, the canned videos will provide a headstart that can prevent many round-trips and greatly improve the loading time.
      more on canning videos later in the readme

    • ⚓ boolean attribute [search]
      tubby will display a search bar that the user can use to narrow the video listing

    • ⚓ number attribute [max-description-length]
      character number limit for video descriptions

    optional javascript stuff

    
    // we can create the explorer programmatically
    const explorer = document.createElement("tubby-youtube-explorer")
    document.body.appendChild(explorer)
    
    // we can set the attributes as properties
    explorer["search"] = true
    explorer["max-description-length"] = 360
    explorer["api-key"] = "AIzaSyDeHpB9W14feQs8myoWgFAZOCrDeKMLRwE" 
    explorer["playlist-id"] = "UUL_f53ZEJxp8TtlOkHwMV9Q"
    explorer["canned"] = "dist-demo/canned-videos.json"
    
    // the explorer supports these callbacks
    explorer.onReady = () => console.log(`tubby loaded ${explorer.videos.length} videos`)
    explorer.onError = error => console.warn(error)
    
    // in addition to the two callbacks, there are matching custom events
    explorer.addEventListener("ready", () => console.info("ready"))
    explorer.addEventListener("error", () => console.info("error"))
  5. know how to style the explorer

    <style>
      tubby-video-explorer {
        --focus-outline: 2px solid #0ef;
        --tubby-search-focus-outline-offset: -4px;
        --tubby-pending-bg: rgba(0,0,0, 0.2);
        --tubby-error-bg: rgba(128,0,0, 0.2);
        --tubby-pending-color: white;
        --tubby-error-color: yellow;
        --tubby-search-icon-color: rgba(0,0,0, 0.5);
        --tubby-results-blink-color: rgba(255,255,255, 0.5);
        --tubby-grid-bg: rgba(0,0,0, 0.2);
        --tubby-video-color: white;
        --tubby-video-bg: linear-gradient(to bottom right,
          rgba(25,25,25, 0.95) 32%,
          rgba(25,25,25, 0.6)
        );
      }
    </style>
  6. canning videos with tubby's tubby-download commandline tool

    you can give tubby a headstart (greatly reducing load times for large playlists), by using the tubby-download cli to generate a cache of "canned" videos in a json file, here's how

    • npm install tubby
      install tubby into your npm package

    • tubby-download --api-key=AIzaSyDeHpB9W14feQs8myoWgFAZOCrDeKMLRwE --playlist-id=UUL_f53ZEJxp8TtlOkHwMV9Q > dist/canned-videos.json
      call the tubby binary in a package.json script, supply the api-key and playlist-id, and specify where tubby should write the canned videos json file

    • then you just provide the [canned] attribute like so: <tubby-youtube-explorer canned="dist/canned-videos.json">

tubby is open source and contributions are welcome!

please consider opening an issue or contributing pull requests :)