File: D:/HostingSpaces/TDijk1/erp-apps.eu/wwwroot/App_Code/Pux/Utils/EmbedTools.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
namespace Pux
{
public class EmbedTools
{
public static readonly Regex VimeoVideoRegex = new Regex(@"vimeo\.com/(?:.*#|.*/videos/)?([0-9]+)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
public static readonly Regex YoutubeVideoRegex = new Regex(@"^(?:https?\:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v\=))([\w-]{10,12})(?:$|\&|\?\#).*", RegexOptions.IgnoreCase);
public static string GetVideoID(string url, Regex regex)
{
if (!String.IsNullOrEmpty(url))
{
Match videoMatch = regex.Match(url);
string videoId = String.Empty;
if (videoMatch.Success)
{
videoId = videoMatch.Groups[1].Value;
}
return videoId;
}
return String.Empty;
}
public static string GetYoutubeID(string url)
{
if (url.Contains("youtube"))
{
return GetVideoID(url, YoutubeVideoRegex);
}
return url;
}
public static string GetVimeoID(string url)
{
if (url.Contains("vimeo"))
{
return GetVideoID(url, VimeoVideoRegex);
}
return url;
}
}
}