// Clipboard Fusion Macro: "Convert YouTube/Vimeo URL to Embed Code"
// Michael Seman (@AphixJS)
// v1.0.0
// 2017-02-22
using System;
public static class ClipboardFusionHelper
{
public static string ProcessText(string url)
{
if (url.Contains("youtube.com") || url.Contains("youtu.be"))
{
return ClipboardFusionHelper.ConvertYouTubeToEmbed(url);
}
if (url.Contains("vimeo.com"))
{
return ClipboardFusionHelper.ConvertVimeoToEmbed(url);
}
return url;
}
private static string ConvertYouTubeToEmbed(string url)
{
string[] parts = url.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
string idWithPotentialQueryParams = parts[parts.Length - 1].ToString().Replace("?t=","?start=");
string joiner = idWithPotentialQueryParams.Contains("?") ? "&" : "?";
string suffix = "ecver=2";
return "https://www.youtube.com/embed/"+idWithPotentialQueryParams+joiner+suffix;
}
private static string ConvertVimeoToEmbed(string url)
{
string[] parts = url.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
string id = parts[parts.Length - 1].ToString();
return "https://player.vimeo.com/video/"+id;
}
}