當前位置: 首頁>>代碼示例>>C#>>正文


C# UriBuilder.GetQueryParam方法代碼示例

本文整理匯總了C#中System.UriBuilder.GetQueryParam方法的典型用法代碼示例。如果您正苦於以下問題:C# UriBuilder.GetQueryParam方法的具體用法?C# UriBuilder.GetQueryParam怎麽用?C# UriBuilder.GetQueryParam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.UriBuilder的用法示例。


在下文中一共展示了UriBuilder.GetQueryParam方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetMediaInfosAsync

        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;
        }
開發者ID:XuPeiYao,項目名稱:MediaGetCore,代碼行數:82,代碼來源:YoutubeExtractor.cs


注:本文中的System.UriBuilder.GetQueryParam方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。