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

@fow/puppeteer-source-metadata

v1.0.0

Published

Downloads

5

Readme

SourceMetadata

使用

const puppeteer = require('puppeteer');
const SourceMetadata = require('source-metadata');

(async () => {
  let meta = new SourceMetadata();
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  
  // 尽早的设置page
  meta.setPage(page);

  // 读取到一个资源的meta内容
  meta.on('takeattr', metadata=>{
    console.log(metadata.info.streams);
  })

  // 每隔一段时间, 查看下当前已经解析的资源的列表
  meta.watch(list=>{
    console.log(list);
  })

  page.goto('http://127.0.0.1:8080/index.html');
  

})();

方法

watch(callback, interval=3000)

  • callback 接收的参数:

    • sourceList : array<metadata>
  • interval: 间隔的毫秒数

meta.watch(sourceList=>{
  console.log(sourceList);
})

sourceList 的具体格式参照下面 metadata 格式章节.

事件

takeattr

成功解析出一个资源的metadata信息后, 会触发此时间

callback 接收一个 metadata 对象作为参数

// 读取到一个资源的meta内容
meta.on('takeattr', metadata=>{
  console.log(metadata.info.streams);
})

pageresponse

页面收到一次资源响应后触发, 无论成功或者失败的响应, 都会触发.

metadata 对象尚未包含资源metadata信息

callback 接收一个 metadata 对象作为参数


meta.on('pageresponse', metadata=>{
  console.log(metadata);
})

matadata 对象

一个完整的metadata对象目前有如下格式:

{
  url: 资源的路径,
  requestHeaders: 浏览器资源请求的header,
  responseHeaders: 浏览器资源响应的header,
  err: Error|null,  响应是否有错误,
  info: Object, 资源的metadata的信息,
}

metadata.info 的格式

{
  format: {},
  streams: []
}

视频的 metadata.info 信息:

{
  "streams": [
    {
      "index": 0,
      "codec_name": "h264",
      "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
      "profile": "Constrained Baseline",
      "codec_type": "video",
      "codec_time_base": "1/48",
      "codec_tag_string": "avc1",
      "codec_tag": "0x31637661",
      "width": 320,
      "height": 180,
      "has_b_frames": 0,
      "sample_aspect_ratio": "1:1",
      "display_aspect_ratio": "16:9",
      "pix_fmt": "yuv420p",
      "level": 13,
      "r_frame_rate": "24/1",
      "avg_frame_rate": "24/1",
      "time_base": "1/24",
      "start_pts": 0,
      "start_time": "0.000000",
      "duration_ts": 14315,
      "duration": "596.458333",
      "bit_rate": "702655",
      "nb_frames": "14315",
      "disposition": {
        "default": 0,
        "dub": 0,
        "original": 0,
        "comment": 0,
        "lyrics": 0,
        "karaoke": 0,
        "forced": 0,
        "hearing_impaired": 0,
        "visual_impaired": 0,
        "clean_effects": 0,
        "attached_pic": 0
      },
      "tags": {
        "creation_time": "1970-01-01 00:00:00",
        "language": "und",
        "handler_name": "\fVideoHandler"
      }
    },
    {
      "index": 1,
      "codec_name": "aac",
      "codec_long_name": "AAC (Advanced Audio Coding)",
      "codec_type": "audio",
      "codec_time_base": "1/48000",
      "codec_tag_string": "mp4a",
      "codec_tag": "0x6134706d",
      "sample_fmt": "fltp",
      "sample_rate": "48000",
      "channels": 2,
      "bits_per_sample": 0,
      "r_frame_rate": "0/0",
      "avg_frame_rate": "0/0",
      "time_base": "1/48000",
      "start_pts": 0,
      "start_time": "0.000000",
      "duration_ts": 28619776,
      "duration": "596.245333",
      "bit_rate": "159997",
      "nb_frames": "27949",
      "disposition": {
        "default": 0,
        "dub": 0,
        "original": 0,
        "comment": 0,
        "lyrics": 0,
        "karaoke": 0,
        "forced": 0,
        "hearing_impaired": 0,
        "visual_impaired": 0,
        "clean_effects": 0,
        "attached_pic": 0
      },
      "tags": {
        "creation_time": "1970-01-01 00:00:00",
        "language": "und",
        "handler_name": "\fSoundHandler"
      }
    }
  ],
  "format": {
    "filename": "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4",
    "nb_streams": 2,
    "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
    "format_long_name": "QuickTime / MOV",
    "start_time": "0.000000",
    "duration": "596.459000",
    "size": "64657027",
    "bit_rate": "867211",
    "tags": {
      "major_brand": "isom",
      "minor_version": "512",
      "compatible_brands": "mp41",
      "creation_time": "1970-01-01 00:00:00",
      "title": "Big Buck Bunny",
      "artist": "Blender Foundation",
      "composer": "Blender Foundation",
      "date": "2008",
      "encoder": "Lavf52.14.0"
    }
  }
}

音频的 metadata.info 的格式

{
  streams: [
    {
      index: 0,
      codec_name: 'mp3',
      codec_long_name: 'MP3 (MPEG audio layer 3)',
      profile: 'unknown',
      codec_type: 'audio',
      codec_time_base: '1/44100',
      codec_tag_string: '[0][0][0][0]',
      codec_tag: '0x0000',
      sample_fmt: 'fltp',
      sample_rate: 44100,
      channels: 2,
      channel_layout: 'stereo',
      bits_per_sample: 0,
      id: 'N/A',
      r_frame_rate: '0/0',
      avg_frame_rate: '0/0',
      time_base: '1/14112000',
      start_pts: 353600,
      start_time: 0.025057,
      duration_ts: 'N/A',
      duration: 'N/A',
      bit_rate: 128000,
      max_bit_rate: 'N/A',
      bits_per_raw_sample: 'N/A',
      nb_frames: 'N/A',
      nb_read_frames: 'N/A',
      nb_read_packets: 'N/A',
      tags: [Object],
      disposition: [Object]
    },
    {
      index: 1,
      codec_name: 'mjpeg',
      codec_long_name: 'Motion JPEG',
      profile: 'Baseline',
      codec_type: 'video',
      codec_time_base: '0/1',
      codec_tag_string: '[0][0][0][0]',
      codec_tag: '0x0000',
      width: 640,
      height: 640,
      coded_width: 640,
      coded_height: 640,
      closed_captions: 0,
      has_b_frames: 0,
      sample_aspect_ratio: '1:1',
      display_aspect_ratio: '1:1',
      pix_fmt: 'yuvj420p',
      level: '-99',
      color_range: 'pc',
      color_space: 'bt470bg',
      color_transfer: 'unknown',
      color_primaries: 'unknown',
      chroma_location: 'center',
      field_order: 'unknown',
      timecode: 'N/A',
      refs: 1,
      id: 'N/A',
      r_frame_rate: '90000/1',
      avg_frame_rate: '0/0',
      time_base: '1/90000',
      start_pts: 'N/A',
      start_time: 'N/A',
      duration_ts: 'N/A',
      duration: 'N/A',
      bit_rate: 'N/A',
      max_bit_rate: 'N/A',
      bits_per_raw_sample: 8,
      nb_frames: 'N/A',
      nb_read_frames: 'N/A',
      nb_read_packets: 'N/A',
      tags: [Object],
      disposition: [Object]
    }
  ],
  format: {
    filename: 'pipe:0',
    nb_streams: 2,
    nb_programs: 0,
    format_name: 'mp3',
    format_long_name: 'MP2/3 (MPEG audio layer 2/3)',
    start_time: 0.025057,
    duration: 'N/A',
    size: 'N/A',
    bit_rate: 128000,
    probe_score: 51,
    tags: {
      encoder: 'Lavf57.71.100',
      disc: '01',
      track: '1',
      artist: '程书林',
      comment: "163 key(Don't modify):L64FU3W4YxX3ZFTmbZ+8/d0ujcBjK+/33J9EbZrPbfv1UuacG3mgDgdaKbhfu1p+5Oa1DsZq2n/kpC/IQEFrvkEfsL924EocORhB9HbF2dtSYSad0YSgedrHU9s2yTTKQFerteZpOTD9m4YIK3hzOiZyZ/tars9wJNO8ZYIpin0Pf4MXsX6ZHY3TAcfFkHscf62DED2hy4PDAFgIzXM/2AgKP/elxQidTzNUZoYz3K8aKiddgxK7OqUS+1SiyU0VybHNq1NLLaqLximAyHgEo9/2uhk1AlTrY3L5BJxwgeaNSSNstsdejSFcH3cWod4NviPLUW3MiHawOb3Ndoqj9gukMdtmOR9fcLBqmUgsp/PF8cjJmkk4VjhfPzhSsD+j3nagSJ3qTEuJf+DuLrMg62ugvIqNZ0HAFOgJGJF3qCIjYtCguPK/Xe5HKS7oIvcZqU9Jf8VtB+IQZJ9f2/ceEou+T9CnR5OoFL/XKTM15sHl3rVVk7OcHXwtCr2O2O9PsaY5uHSrK6Hp1JI7a5slIMt3CYgmsaGXs0lsB0+/j7bHUtM4Q9k+tby0BcJgbTtR6YURAByiRHQ6CI5tvtxzQg==",
      title: '程书林 - 烤面筋(古风重编曲)(程书林 remix)',
      album: '烤面筋'
    }
  },
  chapters: []
}

图片的 metadata.info 信息:

{
  streams: [
    {
      index: 0,
      codec_name: 'png',
      codec_long_name: 'PNG (Portable Network Graphics) image',
      profile: 'unknown',
      codec_type: 'video',
      codec_time_base: '0/1',
      codec_tag_string: '[0][0][0][0]',
      codec_tag: '0x0000',
      width: 1225,
      height: 924,
      coded_width: 1225,
      coded_height: 924,
      closed_captions: 0,
      has_b_frames: 0,
      sample_aspect_ratio: 'N/A',
      display_aspect_ratio: 'N/A',
      pix_fmt: 'rgba',
      level: '-99',
      color_range: 'pc',
      color_space: 'unknown',
      color_transfer: 'unknown',
      color_primaries: 'unknown',
      chroma_location: 'unspecified',
      field_order: 'unknown',
      timecode: 'N/A',
      refs: 1,
      id: 'N/A',
      r_frame_rate: '25/1',
      avg_frame_rate: '0/0',
      time_base: '1/25',
      start_pts: 'N/A',
      start_time: 'N/A',
      duration_ts: 'N/A',
      duration: 'N/A',
      bit_rate: 'N/A',
      max_bit_rate: 'N/A',
      bits_per_raw_sample: 'N/A',
      nb_frames: 'N/A',
      nb_read_frames: 'N/A',
      nb_read_packets: 'N/A',
      disposition: [Object]
    }
  ],
  format: {
    filename: 'pipe:0',
    nb_streams: 1,
    nb_programs: 0,
    format_name: 'png_pipe',
    format_long_name: 'piped png sequence',
    start_time: 'N/A',
    duration: 'N/A',
    size: 'N/A',
    bit_rate: 'N/A',
    probe_score: 99
  },
  chapters: []
}