An open API service indexing awesome lists of open source software.

https://github.com/iktakahiro/youtube-url-parser

Parser for Youtube URL
https://github.com/iktakahiro/youtube-url-parser

javascript nodejs typescript url-parser

Last synced: 25 days ago
JSON representation

Parser for Youtube URL

Awesome Lists containing this project

README

        

# youtube-url-parser

[![Build Status](https://travis-ci.org/iktakahiro/youtube-url-parser.svg?branch=master)](https://travis-ci.org/iktakahiro/youtube-url-parser)

## Install

```bash
npm install @iktakahiro/youtube-url-parser
```

## How to use

```typescript
import { YouTubeURLParser } from "@iktakahiro/youtube-url-parser"

const parser = new YouTubeURLParser("https://youtu.be/7lmCu8wz8ro?t=2m10s")

console.log(parser.isValid())
// -> true
console.log(parser.getId())
// -> "7lmCu8wz8ro"
console.log(parser.getCanonicalURL())
// -> "https://www.youtube.com/watch?v=7lmCu8wz8ro&t=2m10s"
console.log(parser.getShortURL())
// -> "https://youtu.be/7lmCu8wz8ro&t=2m10s"
console.log(parser.getThumbnailURL())
// -> "https://img.youtube.com/vi/7lmCu8wz8ro/0.jpg"
console.log(parser.getStartAtSecond())
// -> 130 (2m * 60s + 10s)
```

`getIframe()`:

```js
console.log(parser.getIframe())
```

`getIframe()` method returns HTML strings containing an iframe element for embedding.

```html


```

with options:

```js
const options = {
allowFullScreen: false,
frameBorder: 1,
noCookie: true,
}
console.log(parser.getIframe(options))
```

When the params is set, the following HTML strings are returned.

```html


```

## Test

```bash
npm test
```