当前位置: 首页>>代码示例>>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;未经允许,请勿转载。