本文整理汇总了C#中System.VideoInfo.GetPlaybackOptionUrl方法的典型用法代码示例。如果您正苦于以下问题:C# VideoInfo.GetPlaybackOptionUrl方法的具体用法?C# VideoInfo.GetPlaybackOptionUrl怎么用?C# VideoInfo.GetPlaybackOptionUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.VideoInfo
的用法示例。
在下文中一共展示了VideoInfo.GetPlaybackOptionUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SortPlaybackOptions
/// <summary>
/// Sorts and filters all video links (hosters) for a given video
/// </summary>
/// <param name="video">The video that is handled</param>
/// <param name="baseUrl">The base url of the video</param>
/// <param name="tmp"></param>
/// <param name="limit">How many playback options are at most shown per hoster (0=all)</param>
/// <param name="showUnknown">Also show playback options where no hoster is available yet</param>
/// <returns></returns>
public string SortPlaybackOptions(VideoInfo video, string baseUrl, string tmp, int limit, bool showUnknown)
{
List<PlaybackElement> lst = new List<PlaybackElement>();
if (video.PlaybackOptions == null) // just one
lst.Add(new PlaybackElement("100%justone", FormatHosterUrl(tmp)));
else
foreach (string name in video.PlaybackOptions.Keys)
{
PlaybackElement element = new PlaybackElement(FormatHosterName(name), FormatHosterUrl(video.PlaybackOptions[name]));
element.status = "ns";
if (element.server.Equals("videoclipuri") ||
HosterFactory.ContainsName(element.server.ToLower().Replace("google", "googlevideo")))
element.status = String.Empty;
lst.Add(element);
}
Dictionary<string, int> counts = new Dictionary<string, int>();
foreach (PlaybackElement el in lst)
{
if (counts.ContainsKey(el.server))
counts[el.server]++;
else
counts.Add(el.server, 1);
}
Dictionary<string, int> counts2 = new Dictionary<string, int>();
foreach (string name in counts.Keys)
if (counts[name] != 1)
counts2.Add(name, counts[name]);
lst.Sort(PlaybackComparer);
for (int i = lst.Count - 1; i >= 0; i--)
{
if (counts2.ContainsKey(lst[i].server))
{
lst[i].dupcnt = counts2[lst[i].server];
counts2[lst[i].server]--;
}
}
video.PlaybackOptions = new Dictionary<string, string>();
bool lastPlaybackOptionUrlPresent = false;
foreach (PlaybackElement el in lst)
{
if (!Uri.IsWellFormedUriString(el.url, System.UriKind.Absolute))
el.url = new Uri(new Uri(baseUrl), el.url).AbsoluteUri;
if ((limit == 0 || el.dupcnt <= limit) && (showUnknown || el.status == null || !el.status.Equals("ns")))
{
video.PlaybackOptions.Add(el.GetName(), el.url);
lastPlaybackOptionUrlPresent |= (el.url == lastPlaybackOptionUrl);
}
}
if (lst.Count == 1)
{
video.VideoUrl = video.GetPlaybackOptionUrl(lst[0].GetName());
video.PlaybackOptions = null;
return video.VideoUrl;
}
if (lastPlaybackOptionUrlPresent)
return lastPlaybackOptionUrl;
if (lst.Count > 0)
tmp = lst[0].url;
return tmp;
}