HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
        }
    }
}