https://github.com/codetheweb/mtu-webcams
📷 🚨 an easy-to-use API for downloading and streaming from public Michigan Tech webcams
https://github.com/codetheweb/mtu-webcams
Last synced: 4 months ago
JSON representation
📷 🚨 an easy-to-use API for downloading and streaming from public Michigan Tech webcams
- Host: GitHub
- URL: https://github.com/codetheweb/mtu-webcams
- Owner: codetheweb
- License: mit
- Created: 2019-08-06T02:02:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-22T16:44:05.000Z (almost 3 years ago)
- Last Synced: 2024-12-24T23:15:55.761Z (4 months ago)
- Language: JavaScript
- Size: 948 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://www.npmjs.com/package/ffmpeg-static).
```javascript
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](#webcams)
- [Parameters](#parameters)
- [init](#init)
- [getAll](#getall)
- [byId](#byid)
- [Parameters](#parameters-1)
- [byName](#byname)
- [Parameters](#parameters-2)
- [Camera](#camera)
- [Parameters](#parameters-3)
- [getImageURL](#getimageurl)
- [streamImage](#streamimage)
- [getVideoURL](#getvideourl)
- [streamVideo](#streamvideo)
- [Parameters](#parameters-4)
- [getRecordingURL](#getrecordingurl)
- [Parameters](#parameters-5)
- [streamRecording](#streamrecording)
- [Parameters](#parameters-6)### Webcams
Main cameras class.
#### Parameters
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`)
- `options.ffmpegPath` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path to local FFMPEG binary#### init
Scrape Michigan Tech's website to
retrieve all published webcams.Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Camera](#camera)>** discovered cameras
#### getAll
Get all cameras saved in instance.
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Camera](#camera)>**
#### byId
Gets camera by ID.
##### Parameters
- `id` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** of camera
Returns **[Camera](#camera)**
#### byName
Gets camera by name.
##### Parameters
- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of camera
Returns **[Camera](#camera)**
### Camera
Main camera class.
#### Parameters
- `$0` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`)
- `$0.imageURL`
- `$0.name`
- `$0.description`
- `$0.ffmpegPath`#### getImageURL
Returns the URL to a static snapshot.
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
#### streamImage
Returns a stream of the latest static snapshot.
Returns **[stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable)**
#### getVideoURL
Returns the URL to a live `m3u8` playlist.
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
#### streamVideo
Returns a live video stream from the webcam.
##### Parameters
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`)
- `options.format` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** format specifier passed to FFMPEG (optional, default `'flv'`)Returns **[stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable)**
#### getRecordingURL
Returns the URL for a MP4 recording.
##### Parameters
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)** of recording
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
#### streamRecording
Returns a recording as a stream.
##### Parameters
- `date` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)** of recording to retrieve
Returns **[stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable)**