mtu-webcams

0.1.1 • Public • Published

mtu-webcams

📷 🚨 an easy-to-use API for downloading and streaming from public Michigan Tech webcams

Installation

npm i mtu-webcams

Usage

The below example assumes you have FFMPEG installed and it is in your $PATH.

If you don't have FFMPEG installed or don't want to install it, check out ffmpeg-static.

const fs = require('fs');
const Webcams = require('mtu-webcams');
 
const cams = new Webcams();
 
(async () => {
  // Get all webcams and save in instance
  await cams.init();
 
  // Log discovered webcams
  console.log(cams.getAll()); // => [ ... ]
 
  // Download yesterday's timelapse to 'recording.mp4'
  const yesterday = new Date(new Date().getTime() - (86400 * 1000));
 
  cams.byName('Campus Aerial').streamRecording(yesterday).pipe(fs.createWriteStream('recording.mp4'));
 
  // Get a current snapshot and save to 'snapshot.jpg'
  cams.byName('Campus Aerial').streamImage().pipe(fs.createWriteStream('snapshot.jpg'));
 
  // Stream ~5 seconds of video and save to 'stream.flv'
  const stream = cams.byName('Campus Aerial').streamVideo();
  stream.pipe(fs.createWriteStream('stream.mp4'));
 
  setTimeout(() => {
    stream.destroy();
  }, 5000);
})();

📖 Docs

Table of Contents

Webcams

Main cameras class.

Parameters

  • options Object (optional, default {})
    • options.ffmpegPath String? path to local FFMPEG binary

init

Scrape Michigan Tech's website to retrieve all published webcams.

Returns Array<Camera> discovered cameras

getAll

Get all cameras saved in instance.

Returns Array<Camera>

byId

Gets camera by ID.

Parameters

Returns Camera

byName

Gets camera by name.

Parameters

Returns Camera

Camera

Main camera class.

Parameters

  • $0 Object (optional, default {})
    • $0.imageURL
    • $0.name
    • $0.description
    • $0.ffmpegPath

getImageURL

Returns the URL to a static snapshot.

Returns String

streamImage

Returns a stream of the latest static snapshot.

Returns stream.Readable

getVideoURL

Returns the URL to a live m3u8 playlist.

Returns String

streamVideo

Returns a live video stream from the webcam.

Parameters
  • options Object (optional, default {})
    • options.format String format specifier passed to FFMPEG (optional, default 'flv')

Returns stream.Readable

getRecordingURL

Returns the URL for a MP4 recording.

Parameters
  • date Date of recording

Returns String

streamRecording

Returns a recording as a stream.

Parameters
  • date Date of recording to retrieve

Returns stream.Readable

Package Sidebar

Install

npm i mtu-webcams

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

10.8 kB

Total Files

5

Last publish

Collaborators

  • codetheweb