/// <summary> /// 抽取网页真实视频流地址 /// </summary> /// <param name="url">待抽取的网页地址</param> /// <returns>视频流的地址</returns> /// <exception cref="SWFExtractorNS.InvalidURLException">非法URL</exception> /// <exception cref="SWFExtractorNS.DomainNotSupportedException">域不支持</exception> public static Media Extract(String url) { try { String domain = ""; string youGetDomain = YouGetCommon.Url_to_key(url); try { domain = HTTPHelper.ParseDomain(url); } catch (Exception e) { Console.Write(e.Message); } Console.WriteLine("-------------------------------------------------------------"); if (domain == null || domain.Equals("") || extractors.ContainsKey(youGetDomain)) { domain = youGetDomain; } if (domain == null) { throw new InvalidURLException(url); } if (!extractors.ContainsKey(domain)) { int index = url.LastIndexOf('.'); if (index > 0) { String lastComponent = url.ToLower().Substring(index); if (lastComponent.CompareTo(".mp4") == 0 || lastComponent.CompareTo(".flv") == 0) { throw new DomainNotSupportedException(domain); } } HTML5Extractor extractor = new HTML5Extractor(); Media videoURL = extractor.Extract(url); if (videoURL != null) { return(videoURL); } throw new DomainNotSupportedException(domain); } else { Type extractorType = extractors[domain]; IExtractor extractor = Activator.CreateInstance(extractorType) as IExtractor; return(extractor.Extract(url)); } } catch (Exception) { return(null); } }
public string YoutGetExtract(string url) { String domain = YouGetCommon.Url_to_key(url); if (!youGetType.ContainsKey(domain)) { throw new DomainNotSupportedException(domain); } Type extractorType = youGetType[domain]; IYouGetExtractor extractor = Activator.CreateInstance(extractorType) as IYouGetExtractor; return(extractor.YoutGetExtract(url)); }