Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Shorten YouTube Link

Description
This macro shortens a YouTube video from the full https://www.youtube.com/watch?v= to the youtu.be version.
Language
C#.net
Minimum Version
Created By
Joshua T
Contributors
-
Date Created
Jan 4, 2017
Date Last Modified
Jan 4, 2017

Macro Code

using System;
using System.Text.RegularExpressions;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        Regex youtubeRegex = new Regex(@"https://www\.youtube\.com\/watch\?v\=(?<id>[^\&]*)(?:\&.*)?");
        Match match = youtubeRegex.Match(text);

        if (!match.Success) {
            // If this isn't a YouTube video, don't do anything to it
            return text;
        }

        Group idGroup = match.Groups["id"];
        string idText = idGroup.Value;
        return "https://youtu.be/" + idText;
    }
}