JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 60
  • Score
    100M100P100Q66656F
  • License MIT

Get media from tweets quick and easy.

Package Exports

  • get-twitter-media
  • get-twitter-media/dist/getTwitterMedia.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (get-twitter-media) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Installation:

> npm i get-twitter-media

Usage:

Params:

  • url - | type: string | MediaOptionsWithUrl | - A URL or an object with a URL property, and optionally a buffer and/or text property
  • options - | type: MediaOptions | - An object with a buffer and/or text property
const getTwitterMedia = require('get-twitter-media');
getTwitterMedia(url, options)

Examples:

Example with buffer:

const getTwitterMedia = require('get-twitter-media');
let media = await getTwitterMedia("https://twitter.com/CursedVideos/status/1687071264848879616?s=20", {
                    buffer: true
                  });
console.log(media);

Output with buffer:

{
  found: true,
  type: 'Video',
  media: {
    url: 'https://video.twimg.com/amplify_video/1687071206959177728/vid/854x480/SlOcOcqfwdfNhtdk.mp4?tag=14',
    buffer: <Buffer 00 00 00 1c 66 74 79 70 6d 70  ... 3522918 more bytes> 
  }
}

Example with text:

const getTwitterMedia = require('get-twitter-media');
let media = await getTwitterMedia("https://twitter.com/TurnkeyPet/status/1523047586998865920", {
                    text: true,
            });
console.log(media);

Output with text:

{
  found: true,
  type: 'image',
  media: {
    url: 'https://pbs.twimg.com/media/FSLztSMVcAA84nP.jpg'
  },
  text: "My little rescue dog..Iris who is blind now due to cruel treatment, we have had her a year now had one eye taken out and lots of other things done and she's now a little monkey!! https://t.co/BKqd0ruHzc"
}

Types (d.ts reference):

export interface MediaOptions {
    buffer?: boolean
    text?: boolean
}

export interface MediaOptionsWithUrl extends MediaOptions {
    url: string
}

export interface Output {
    found: true
    type: "video" | "image" | "gif"
    media: {
        url: string
        buffer?: Buffer
    }
    text?: string
}
export interface ErrorOutput {
    found: false
    error: string
}

export function getTwitterMedia(url: string | MediaOptionsWithUrl, options?: MediaOptions): Promise<Output>