Last active
July 22, 2021 09:20
-
-
Save DominusKelvin/6006e179a68dbc37221a2cb3f42dc430 to your computer and use it in GitHub Desktop.
This code snippet conversts a given Wistia shareable URL to an Id
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
/// Converts fully qualified Wistia Url to video id. | |
/// | |
/// If videoId is passed as url then we will skip conversion. | |
/// This will match: | |
/// http://home.wistia.com/medias/e4a27b971d | |
/// https://home.wistia.com/medias/e4a27b971d | |
/// http://home.wi.st/medias/e4a27b971d | |
/// http://home.wistia.com/embed/e4a27b971d | |
/// https://home.wistia.com/embed/e4a27b971d | |
/// https://home.wi.st/embed/e4a27b971d | |
String? convertUrlToId(String url, {bool trimWhitespaces = true}) { | |
bool isWistiaVideoId = | |
!url.contains(RegExp(r'https?:\/\/')) && url.length == 10; | |
if (isWistiaVideoId) return url; | |
if (trimWhitespaces) url = url.trim(); | |
var wistiaShareLinkPattern = | |
RegExp(r"https?:\/\/(?:www\.)?\w+\.(wistia\.com|wi\.st)\/(medias|embed)\/(\w{10}).*"); | |
RegExpMatch? match = wistiaShareLinkPattern.firstMatch(url); | |
return match?.group(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment