Skip to content

Commit 85ee74e

Browse files
committed
add video meta fetch using oEmbed
1 parent 4741095 commit 85ee74e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import YoutubeIframe from "./src/YoutubeIframe";
1+
import YoutubeIframe from './src/YoutubeIframe';
2+
import {getYoutubeMeta} from './src/oEmbed';
23

34
export default YoutubeIframe;
5+
export {getYoutubeMeta};

src/oEmbed.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @typedef {Object} youtubeMeta
3+
* @property {String} author_name
4+
* @property {String} author_url
5+
* @property {Number} height
6+
* @property {String} html
7+
* @property {String} provider_name
8+
* @property {String} provider_url
9+
* @property {Number} thumbnail_height
10+
* @property {String} thumbnail_url
11+
* @property {Number} thumbnail_width
12+
* @property {String} title
13+
* @property {String} type
14+
* @property {String} version
15+
* @property {Number} width
16+
*/
17+
18+
/**
19+
* Fetch metadata of a youtube video using the oEmbed Spec -
20+
* https://oembed.com/#section7
21+
*
22+
* @param {String} videoId - youtube video id
23+
* @returns {Promise<youtubeMeta>} A promise that resolves into an object with the video metadata
24+
*/
25+
export const getYoutubeMeta = async videoId => {
26+
const response = await fetch(
27+
`https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${videoId}&format=json`,
28+
);
29+
return await response.json();
30+
};

0 commit comments

Comments
 (0)