Skip to content

Xeukxz/get-twitter-media

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

About

Get media from twitter posts quick and easy with option to get as buffer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published