Skip to content

Latest commit

 

History

History
112 lines (73 loc) · 4.77 KB

README.md

File metadata and controls

112 lines (73 loc) · 4.77 KB

gdrive-file-info

build status install size npm package version github license js semistandard style

Fetch file information for publicly shared Google Drive items.

Instalation

$ npm install gdrive-file-info

API

Table of Contents

GDriveError

Extends Error

Custom error class used for wrapping HTTP errors

Properties

  • reason Error original HTTP error

FileInfo

Type: Object

Properties

Dimensions

Type: Object

Properties

fetchInfo

Fetch file info for given item id

Parameters

  • input String Google Drive item view/open url or item id

Examples

// fetch public video info
const info = await fetchInfo('https://drive.google.com/open?id=1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD');
console.log(info.downloadUrl);
//=> https://doc-00-6c-docs.googleusercontent.com/docs/securesc/…/1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD

// generate poster url
const thumbnailUrl = await info.thumbnailUrl({ width: 1280, height: 720 });
//=> https://lh3.googleusercontent.com/9CwZKAQJ2U0CjjcIt5iZCqd-w-0d5ClJuYHVlS4olLrzt6AZr9rCdDu4jVzrz9b-tK5aswE4vdA=w1280-h720-p
  • Throws GDriveError throws on querying missing/private items
  • Throws TypeError throws on invalid ID provided

Returns Promise<FileInfo> item info

getItemId

Extract item id from Google Drive shareable link

Parameters

  • url String Google Drive item view/open url

Examples

// with _open_ link
const id = getItemId('https://drive.google.com/open?id=1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD');
//=> 1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD

// with _view_ link
const id = getItemId('https://drive.google.com/file/d/1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD/view?usp=sharing');
//=> 1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD

// with _edit_ link
const id = getItemId('https://docs.google.com/document/d/1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA/edit');
// => 1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA

Returns String item id