참고
형식
<https://img.youtube.com/vi/___영상ID___/mqdefault.jpg>
소스코드
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
// 주어진 유튜브 주소들
string[] youtubeUrls =
{
"<https://www.youtube.com/watch?v=x6i3_LfeTjY>",
"<https://www.youtube.com/watch?v=HCsCmmcQaz4>",
"<https://www.youtube.com/watch?v=sd0ZXF5Y6-M>",
// ... 다른 주소들
"<https://youtu.be/-Zwen3HE-50?si=xj3tTsGP9DPEXNuo>"
};
foreach(var url in youtubeUrls)
{
string thumbnailUrl = ConvertToThumbnailUrl(url);
if (!string.IsNullOrEmpty(thumbnailUrl))
Console.WriteLine(thumbnailUrl);
}
}
static string ConvertToThumbnailUrl(string youtubeUrl)
{
string pattern = @"(?:watch\\?v=|youtu.be\\/)([A-Za-z0-9_\\-]+)";
var match = Regex.Match(youtubeUrl, pattern);
if (match.Success)
{
string videoId = match.Groups[1].Value;
return $"<https://img.youtube.com/vi/{videoId}/mqdefault.jpg>";
}
return null;
}
}