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
- Host: GitHub
- URL: https://github.com/iktakahiro/youtube-url-parser
- Owner: iktakahiro
- License: mit
- Created: 2017-10-10T06:38:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-29T04:14:30.000Z (over 6 years ago)
- Last Synced: 2024-09-18T00:09:51.597Z (7 months ago)
- Topics: javascript, nodejs, typescript, url-parser
- Language: TypeScript
- Size: 71.3 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# youtube-url-parser
[](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
```