Created
June 12, 2019 12:00
-
-
Save romanoffs/55a0607e7aa20b66d48a792dbfa4290c to your computer and use it in GitHub Desktop.
YouTubeParce Video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static youtubePattern(isString?: boolean): string | RegExp { | |
const p: string = '^((?:https?:)?\\/\\/)?((?:www|m)\\.)?((?:youtube\\.com|youtu.be))(\\/(?:[\\w\\-]+\\?v=|embed\\/|v\\/)?)([\\w\\-]+)(\\S+)?$'; | |
return isString ? p : new RegExp(p); | |
} | |
static parseYouTubeVideo(url: string): string { | |
if (!Utils.isString(url)) throw new Error('Url is not a string'); | |
return url.replace(Utils.youtubePattern(), '$5'); | |
} | |
static calculateRatioHeight(width: number): number { | |
return Math.round((width / 16) * 9); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment