我在C#中编写了一个函数,它提取了你管内嵌URL的缩略图,但仅用于像“https://youtu.be/8YDKDfkTbZU”这样的URL我无法提取实际的拇指。我怎么能从那种提取图像URL。它适用于像“https://www.youtube.com/watch?v=F2lN25IayH8”这样的网址。
这是我目前的代码
if( ShareHolocPostDesc.Contains( "youtube.com" ) )
{
int endPoint = ShareHolocPostDesc.IndexOf( "<iframe" );
ShareHolocPostDesc = ShareHolocPostDesc.Substring( 0, endPoint - 1 );
ShareHolocPostDesc = ShareHolocPostDesc.Replace( "<br/><br", "" );
string[] arrShareHolicDesc = ShareHolocPostDesc.Replace( "<br/><br", "" ).Split( "?v=".ToCharArray() );
string YouTubeVideoID = arrShareHolicDesc[arrShareHolicDesc.Length - 1];
YouTubeVideoID = YouTubeVideoID.Replace( "<br/>", "" );
YouTubeVideoID = YouTubeVideoID.Replace( "<br/", "" );
ogImage = "http://img.youtube.com/vi/" + YouTubeVideoID.Trim() + "/0.jpg";
}
ShareHolocPostDesc="https://youtu.be/8YDKDfkTbZU <br/><iframe width='100%' height='450' src='https://www.youtube.com/embed/8YDKDfkTbZU'></iframe>"
请帮忙。
答案 0 :(得分:0)
好的,我不得不修改一下。 https://youtu.be/在我的图片网址中是额外的。
YouTubeVideoID = YouTubeVideoID.Replace( "<br/", "" ).Replace( "https://youtu.be/","" );
现在可行。