public void SetQueryParamTest() { UriBuilder uriBuilder = new UriBuilder("http://", "mccoysoftware.uk"); uriBuilder.SetQueryParam("FirstName", "Arthur"); Assert.AreEqual("http://mccoysoftware.uk/?FirstName=Arthur", uriBuilder.ToString()); uriBuilder.SetQueryParam("Surname", "Dent"); Assert.AreEqual("http://mccoysoftware.uk/?FirstName=Arthur&Surname=Dent", uriBuilder.ToString()); // It should be possible to overwrite the values set above uriBuilder.SetQueryParam("FirstName", "Ford"); uriBuilder.SetQueryParam("Surname", "Prefect"); Assert.AreEqual("http://mccoysoftware.uk/?FirstName=Ford&Surname=Prefect", uriBuilder.ToString()); }
public override async Task<MediaInfo[]> GetMediaInfosAsync(Uri Url) { if (!this.IsMatch(Url)) throw new NotSupportedException("不正確的網址"); HtmlDocument youtubePage = await this.DownloadHtmlAsync(Url); OnProcess?.Invoke(this,0.2); JObject mediaJObject = this.GetMediaJObject(youtubePage); if(mediaJObject["args"]["livestream"]?.Value<string>() == "1") { throw new NotSupportedException("不支援直播串流解析"); } string description = youtubePage.DocumentNode.SelectSingleNode("//meta[@name='description']").GetAttributeValue("content", null); JsFactory.Func decoding = await this.GetDecodingSignature("https:" + (string)mediaJObject["assets"]["js"]); Dictionary<string, string> streamFormatList = this.GetStreamFormatList(mediaJObject); JObject[] streamMap = this.GetStreamMap(mediaJObject); Dictionary<string, MediaTypes> MIME = new Dictionary<string, MediaTypes>() { ["audio"] = MediaTypes.Audio, ["video"] = MediaTypes.Video }; OnProcess?.Invoke(this, 0.5); double processValue = 0.5; List<MediaInfo> result = new List<MediaInfo>(); foreach(var item in streamMap) { MediaInfo resultItem = new MediaInfo(); #region 通用屬性 resultItem.SourceUrl = Url; resultItem.ExtractorType = this.GetType(); resultItem.Name = mediaJObject["args"]["title"].Value<string>(); resultItem.Duration = mediaJObject["args"]["length_seconds"].Value<int>(); resultItem.Description = description; resultItem.Thumbnail = new Uri(mediaJObject["args"]["thumbnail_url"].Value<string>()); resultItem.Type = (MediaTypes)Enum.Parse( typeof(MediaTypes), new string( item["type"]["mime"].Value<string>() .TakeWhile(Ch => Ch != '/').ToArray() ), true ); #region 連結解密 UriBuilder realUrlBuilder = new UriBuilder(item["url"].Value<string>()); var UrlSignature = realUrlBuilder.GetQueryParam("s") ?? realUrlBuilder.GetQueryParam("sig") ?? realUrlBuilder.GetQueryParam("signature"); var ItemSignature = item["s"]?.Value<string>() ?? item["sig"]?.Value<string>() ?? item["signature"]?.Value<string>(); realUrlBuilder.SetQueryParam("signature",decoding(UrlSignature ?? ItemSignature , UrlSignature != null)); resultItem.RealUrl = realUrlBuilder.Uri; #endregion #endregion #region 擴充屬性 resultItem.Attributes["mime"] = item["type"]["mime"].Value<string>(); resultItem.Attributes["codecs"] = item["type"]["codecs"]?.Value<string>(); resultItem.Attributes["author"] = mediaJObject["args"]["author"].Value<string>(); if (resultItem.Type == MediaTypes.Video) { resultItem.Attributes["size"] = item["size"]?.Value<string>() ?? streamFormatList[item["itag"]?.Value<string>()]; resultItem.Attributes["quality"] = item["quality"]?.Value<string>(); } else if(resultItem.Type == MediaTypes.Audio) { resultItem.Attributes["bitrate"] = item["bitrate"].Value<string>(); } #endregion result.Add(resultItem); processValue = processValue + 0.5 / streamMap.Count(); OnProcess?.Invoke(this, processValue); } MediaInfo[] output = result.ToArray(); OnCompleted?.Invoke(this, output); return output; }
private static string GetQuery(int? limit = null, int? offset= null, DateTime? startDate = null, DateTime? endDate = null) { const string dateFormat = "yyyy-mm-ddThh:mm:ssZ"; var uri = new UriBuilder(HotmailBaseUrl); if (limit.HasValue) { uri.SetQueryParam(LiveSdkConstants.Limit, limit.Value.ToString()); } if (offset.HasValue) { uri.SetQueryParam(LiveSdkConstants.Offset, offset.Value.ToString()); } if (startDate.HasValue) { uri.SetQueryParam(HotmailConstants.StartDate, startDate.Value.ToString(dateFormat)); } if (endDate.HasValue) { uri.SetQueryParam(HotmailConstants.EndDate, endDate.Value.ToString(dateFormat)); } return uri.Query; }
private static string GetQuery(List<FolderFilter> filters, int? limit, int? offset, SortBy? sortBy, SortOrder? sortOrder) { var uri = new UriBuilder(SkyDriveBaseUrl + SkyDriveConstants.GetFiles); var filterString = ParseFilters(filters); uri.SetQueryParam(SkyDriveConstants.Filters, filterString); if (limit.HasValue) { uri.SetQueryParam(LiveSdkConstants.Limit, limit.Value.ToString()); } if (offset.HasValue) { uri.SetQueryParam(LiveSdkConstants.Offset, offset.Value.ToString()); } if (sortBy.HasValue) { uri.SetQueryParam(SkyDriveConstants.SortBy, sortBy.ToString().ToLower()); } if (sortOrder.HasValue) { uri.SetQueryParam(SkyDriveConstants.SortOrder, sortBy.ToString().ToLower()); } return uri.Query; }