我试图通过只提供URL来允许用户在我的网站上发布视频。现在,我只需解析网址并获得ID,然后将该ID插入到他们给定的“嵌入”代码中,并将其放到页面上,就可以允许YouTube视频。
这限制了我只能播放YouTube视频,然而,我想做的是类似facebook的东西,你可以输入YouTube的“分享”URL或者页面的url,或者任何其他的视频url,然后它就会把视频加载到他们的播放器中。
知道他们是怎么做到的吗?或者任何其他类似的方式,仅仅基于URL来显示视频?请记住,youtube视频(无论如何可能是最受欢迎的)不会给出视频的url,而是YouTube页面上视频的url (这就是为什么只需要ID就需要嵌入代码的原因)。
希望这是有意义的,我也希望有人能给我一些建议,告诉我去哪里看!
谢谢你们。
发布于 2012-03-29 03:11:47
我建议增加对OpenGraph attributes的支持,这在内容服务中很常见,可以让其他网站嵌入他们的内容。页面上的信息将包含在它们的<meta>标记中,这意味着您必须通过类似于HtmlAgilityPack的方式加载该URL
var doc = new HtmlDocument();
doc.Load(webClient.OpenRead(url)); // not exactly production quality
var openGraph = new Dictionary<string, string>();
foreach (var meta in doc.DocumentNode.SelectNodes("//meta"))
{
var property = meta["property"];
var content = meta["content"];
if (property != null && property.Value.StartsWith("og:"))
{
openGraph[property.Value]
= content != null ? content.Value : String.Empty;
}
}
// Supported by: YouTube, Vimeo, CollegeHumor, etc
if (openGraph.ContainsKey("og:video"))
{
// 1. Get the MIME Type
string mime;
if (!openGraph.TryGetValue("og:video:type", out mime))
{
mime = "application/x-shockwave-flash"; // should error
}
// 2. Get width/height
string _w, _h;
if (!openGraph.TryGetValue("og:video:width", out _w)
|| !openGraph.TryGetValue("og:video:height", out _h))
{
_w = _h = "300"; // probably an error :)
}
int w = Int32.Parse(_w), h = Int32.Parse(_h);
Console.WriteLine(
"<embed src=\"{0}\" type=\"{1}\" width=\"{2}\" height=\"{3}\" />",
openGraph["og:video"],
mime,
w,
h);
}https://stackoverflow.com/questions/9913580
复制相似问题