• Stars
    star
    189
  • Rank 204,649 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Get the YouTube, Vimeo, Vine, VideoPress, TikTok, Microsoft Stream, Loom or Dailymotion video id from a url or embed string.

get-video-id codecov

Get the YouTube, Vimeo, Vine, VideoPress, TikTok, Microsoft Stream and Dailymotion video id from a url or embed string.

Pull Requests are welcome if you would like to see support for other video services or if you find an unsupported video url pattern.

Install

$ npm install --save get-video-id

Import

You can use this module in Node.js or in the browser. See below for the different importing options.

CommonJS

const getVideoId = require('get-video-id');

ES2015 Module

import getVideoId from 'get-video-id';

Browser

<script src="https://cdn.jsdelivr.net/npm/get-video-id/dist/get-video-id.min.js"></script>
Download
CDN

Usage

Simply supply the module with a url or embed string matching any of the patterns known by this module and its metadata of id and service will be returned:

import getVideoId from 'get-video-id';

getVideoId('https://www.youtube.com/watch?v=8rSH8-pbHZ0');
//=> { id: '8rSH8-pbHZ0', service: 'youtube' }

const { id } = getVideoId('https://www.youtube.com/watch?v=8rSH8-pbHZ0');
//=> '8rSH8-pbHZ0'

get-video-id can also find the video buried in a Google redirection URL if it contains a reference to any of the supported URL patterns.

getVideoId('https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeG1uDU0rSLw&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA');
//=> { id: 'eG1uDU0rSLw', service: 'youtube' }

API

getVideoId(input)

Returns a metadata Object with the video id and service name:

{
  id: 'String',
  service: 'String'
}

input

Type: String

The url (or embed code) from which you want to find the video id. See the Patterns section to see the formats that can be supplied.

Patterns

This module works on the url / embed patterns below. (where * is the id and ? or & are parameter strings):

YouTube

YouTube Shortcodes

http://youtu.be/*?
https://youtu.be/*
http://youtu.be/*
http://y2u.be/*
youtube://

YouTube Shorts*

https://youtube.com/shorts/*
https://www.youtube.com/shorts/*

YouTube /v/ or /vi/

http://www.youtube.com/v/*
http://youtube.com/vi/*?
http://youtube.com/v/*?

YouTube v= or vi=

http://www.youtube.com/ytscreeningroom?v=*
http://www.youtube.com/watch?v=*?&
https://www.youtube.com/watch?v=*
http://youtube.com/watch?vi=*&
http://youtube.com/?vi=*&
http://youtube.com/?v=*

YouTube /e/

https://www.youtube.com/e/*
https://www.youtube.com/e/*?
http://www.youtube.com/e/*
http://www.youtube.com/e/*?

YouTube image links /vi/*/ or /an_webp/*/

https://i.ytimg.com/vi/*/hqdefault.jpg
https://i.ytimg.com/an_webp/MYDcdp-VNmQ/mqdefault_6s.webp

YouTube embed

http://www.youtube.com/embed/*?
https://www.youtube.com/embed/*

YouTube user

http://www.youtube.com/user/username#p/a/u/2/*
http://www.youtube.com/user/username#p/u/1/*?
http://www.youtube.com/user/username#p/u/1/*

YouTube iframe

<iframe width="560" height="315" src="https://www.youtube.com/embed/*" frameborder="0" allowfullscreen></iframe>

YouTube -nocookie

www.youtube-nocookie.com/embed/*?

YouTube Attribution Link

http://www.youtube.com/attribution_link?u=%2Fwatch%3Fv%3D*%26
http://www.youtube.com/attribution_link?u=%2Fwatch%3Fv%3D
http://www.youtube.com/attribution_link?u=/watch?v=*&
http://www.youtube.com/attribution_link?u=/watch?v=*
http://www.youtube.com/attribution_link?/watch?v=*

Google Redirection to YouTube

https://google.cz/url?source=web&url=<YOUTUBE_URL>
https://google.com/image?url=<YOUTUBE_URL>

Vimeo

Vimeo urls

https://vimeo.com/*
https://vimeo.com/*?
https://player.vimeo.com/video/*
https://player.vimeo.com/video/*?
https://www.vimeo.com/*
https://www.vimeo.com/*?

Vimeo swf embed

http://vimeo.com/foo.swf?clip_id=1234

Vimeo events

https://vimeo.com/event/*

Vimeo iframe

<iframe src="https://player.vimeo.com/video/*" ...

Vimeo unlisted/private urls

https://vimeo.com/*/privateHash

⚠️ Please note: That get-video-id will extract the id from the private/unlisted URLs formats for Vimeo, but the private hash would still be required to rebuild the URL in order to make it reachable/sharable in a browser. If you use get-video-id to help you rebuild URLs, you will want to look for this pattern yourself and remember to include the privateHash in the url you want to share. get-video-id focuses on extracing video ids, and ignores any other special paramaters or formats at the moment.

Vine

Vine urls

https://vine.co/v/*

Vine iframe

<iframe src="https://vine.co/v/*/embed/simple" width="600" height="600" frameborder="0"></iframe>
<iframe src="https://vine.co/v/*/embed/postcard" width="600" height="600" frameborder="0"></iframe>

VideoPress

VideoPress urls

https://videopress.com/v/*
https://videopress.com/embed/*

VideoPress iframes

<iframe src="https://videopress.com/embed/zcnJVzQF" width="600" height="600"></iframe>

Microsoft Stream

Microsoft Stream urls

https://web.microsoftstream.com/video/*
https://web.microsoftstream.com/embed/video/*

Microsoft Stream iframes

<iframe src="https://web.microsoftstream.com/embed/video/*?&" width="640" height="360"></iframe>

TikTok

TikTok urls

https://www.tiktok.com/*/video/*
https://www.tiktok.com/*/video/*?

⚠️ Unsupported TikTok urls

  • Shortlink URL (requires a fetch/redirect to find the real id) : https://vm.tiktok.com/shorLinkId/

Dailymotion

Dailymotion urls

http://www.dailymotion.com/video/*_text
http://www.dailymotion.com/video/*
http://www.dailymotion.com/fr/relevance/search/search+query/1#video=*
https://www.dailymotion.com/video/*?playlist=
http://dai.ly/*

Dailymotion iframes

<iframe src="https://www.dailymotion.com/embed/video/*" width="600" height="600"></iframe>

⚠️ Unsupported Dailymotion urls

  • Channel id urls: http://www.dailymotion.com/hub/*_title

Contributing

If you discover a url pattern that is not covered by this module, please open an issue to report it, or submit a Pull Request. For any submitted pull requests, please ensure that you include unit test(s) to fully cover your code contribution(s).

License

MIT Β© Michael Wuergler

More Repositories

1

functional-programming-resources

Archive the best resources surrounding the functional programming paradigm for JavaScript developers.
55
star
2

unicode-range-json

A list of all the Unicode Range Names and their hex/decimal range numbers.
JavaScript
22
star
3

timecard

Keep track of your project development time.
JavaScript
18
star
4

npm-install-que

Que up your project's dependencies, and automatically install them one-by-one.
JavaScript
18
star
5

metalsmith-rootpath

Easily find the relative path to the root directory in your Metalsmith templates.
JavaScript
12
star
6

birdwatch

Monitor, filter, cache and serve raw tweets from one or more specific twitter feeds.
JavaScript
11
star
7

markdown-for-everyone

Explaining the Markdown syntax for inquiring minds.
11
star
8

awesome-interactive

A curated list of awesome interactive web experiences
11
star
9

metalsmith-gulp-boilerplate

A starter template for Metalsmith + Gulp + Jest projects
JavaScript
11
star
10

html-colors

Get a list of all the HTML and CSS color names and their hex values.
JavaScript
10
star
11

port-pid

Get the pids of processes on a given port
JavaScript
7
star
12

react-redux-user-management-demo

A User Management application demo written in React and Redux
JavaScript
7
star
13

convert-seconds

Convert seconds to hours, minutes, seconds
JavaScript
7
star
14

xml-to-json-promise

Convert an XML file or XML data to JSON (via xml2js), with promises.
JavaScript
6
star
15

unicode-range

Get the category range name of any Unicode value. U+3071 ➝ Hiragana
JavaScript
5
star
16

github-npm-lookup

Turn selected text on a Chrome webpage into an npm package lookup.
HTML
5
star
17

cheatsheets

A collection of developer-driven cheatsheets for quick reference.
JavaScript
4
star
18

icon-generator

Batch-automate the creation of image icons from a single source image.
JavaScript
3
star
19

get-user-mentions

Get all @user mentions in a string
JavaScript
3
star
20

netstats

Get the netstat activity on a given port.
JavaScript
3
star
21

ffmpeg-reciepes

A list of my commonly-used ffmpeg scripts (MacOS)
2
star
22

srt-to-obj

Convert an .srt subtitle file to an array of object literals.
JavaScript
2
star
23

taghash

Convert plain-text hashtags to twitter-ready hashtags
JavaScript
2
star
24

inject-tag-style

Inject inline styles into the tags of an HTML string.
JavaScript
2
star
25

generator-nmx

Scaffold out a node module
JavaScript
2
star
26

detonate

Go boom! with a clean, compact syntax for your javascript type checking & error throwing.
JavaScript
2
star
27

github-tweaks

Don't let GitHub's new blue URL color burn a hole in your eye.
JavaScript
2
star
28

selective-whitespace

Condense all whitespace in a string, with options to preserve specific whitespace characters.
JavaScript
2
star
29

gulp-recipes

A collection of some useful gulp tasks
2
star
30

all-html-tags

Get all HTML tags, with options for filtering deprecated, HTML5 tags, etc.
JavaScript
2
star
31

ascii-hex

Get the hexidecimal value of an ASCII character
JavaScript
2
star
32

local-csp-reporter

A simple localhost server to log CSP violations
JavaScript
1
star
33

radiovisual

About me
1
star
34

werdino-daily

Get the Werdino daily menu in English and German
JavaScript
1
star
35

rep-watcher

1
star
36

emtee

A super-small echo module β†’ returning values like nobody's business.
JavaScript
1
star
37

benjmark

Super-simple benchmarking library with clean API
JavaScript
1
star
38

pendel

Get the time difference between two date strings or two time strings.
JavaScript
1
star
39

strapi-boilerplate

A starting boilerplate for a custom Strapi CMS
1
star
40

ckeditor-metadata

Manage metadata of selected CKEditor elements
JavaScript
1
star
41

ckeditor-calendar

Insulate Google Calendar iframes with a contextMenu-friendly div.
JavaScript
1
star
42

timestamp-to-seconds

Convert a timestamp string to seconds. '00:01:02' β†’ 62
JavaScript
1
star
43

ckeditor-mediaboxconvert

Easily convert your images and iframe-insulator embeds into Mediabox widgets.
JavaScript
1
star
44

jenkins-sample

Just a sample Jenkins file
1
star
45

tokenize-whitespace

Tokenize a string into words and whitespace tokens
JavaScript
1
star
46

radiovisual.github.io

My [archived] online portfolio
HTML
1
star
47

wait-p

Wait for a specified amount of time, then return a promise.
JavaScript
1
star
48

zeropad

Zeropad your integers with n-length padding.
JavaScript
1
star
49

date-from-clocktime

Get a valid Date object from any clocktime string. '09:30 AM' β†’ [Date object]
JavaScript
1
star
50

legal-lorem

Lorem Ipsum Placeholder Samples for your Application's Legal Documents (Terms of Service, Privacy Policy, etc)
HTML
1
star
51

ascii-decimal

Get the decimal value of an ASCII character
JavaScript
1
star
52

ckeditor-iframeinsulator

Insulate ckeditor iframes with a contextMenu-friendly div.
JavaScript
1
star
53

keeli

Fast, configurable and extendable CLI to look for common problems in your translated source files.
TypeScript
1
star
54

zaport

Gracefully close all processes on a specific port. Target TCP, UDP or both.
JavaScript
1
star
55

blender-cheatsheet

A handy guide to Blender's hotkeys
1
star
56

noop-server

Launch a noop server on a free port. Useful for testing.
JavaScript
1
star
57

date-components

Extract individual date components from a Date String.
JavaScript
1
star
58

doodle-greenbot

An experimental earth-aware notification app built with Heroku, Strapi API, Gatsby and Slack
1
star
59

hash-regex

Converts an array of strings to a regular expression of hashtags
JavaScript
1
star
60

is-datestring

Check if a string is a datetime string
JavaScript
1
star
61

ckeditor-mediabox

Wrap your media up with a title, caption, credit, tweet and facebook text.
JavaScript
1
star
62

eslint-bom-test

Demonstrate the ESLint/XO BOM Issue (#5766)
JavaScript
1
star
63

ckeditor-plugin-demo

Demo the simple setup of a basic CKEditor Plugin, with annotated source.
JavaScript
1
star
64

no-whitespace

Remove absolutely all whitespace from a string.
JavaScript
1
star
65

vscode-copy-with-replace

A VS Code Extension to replace specific text snippets before copying to the clipboard.
JavaScript
1
star
66

cybereason-yarn-demo

A small demo of the Cybereason + yarn problems
1
star
67

ckeditor-audioinsulator

Embed contextMenu/metadata-friendly audio tags into CKEditor.
JavaScript
1
star
68

node-oauth-error

Convert oauth object-literal errors into actual Error() objects.
JavaScript
1
star