This repository has been archived on 2026-03-14. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Eco/VideoBrowser/Helpers/UrlHelper.cs
2023-07-24 12:00:34 +02:00

53 lines
1.4 KiB
C#

namespace VideoBrowser.Helpers
{
using System;
using System.Web;
/// <summary>
/// Defines the <see cref="UrlHelper" />.
/// </summary>
internal static class UrlHelper
{
#region Methods
/// <summary>
/// The GetValidUrl.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="string"/>.</returns>
public static string GetValidUrl(string url)
{
if (!IsValidUrl(url))
{
var encodedUrl = HttpUtility.UrlEncode(url);
url = $"https://www.youtube.com/results?search_query={encodedUrl}";
}
return url;
}
/// <summary>
/// The IsValidUrl.
/// </summary>
/// <param name="url">The url<see cref="string"/>.</param>
/// <returns>The <see cref="bool"/>.</returns>
public static bool IsValidUrl(string url)
{
if (!url.Contains("."))
{
return false;
}
if (!url.Contains("http"))
{
url = $"http://{url}";
}
var result = Uri.TryCreate(url, UriKind.Absolute, out Uri uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
return result;
}
#endregion Methods
}
}