示例#1
0
        public static string RemoveQueryStringByKey(string url, string key)
        {
            var uri = new Uri(url);

            // this gets all the query string key value pairs as a collection
            var newQueryString = MyHttpUtility.ParseQueryString(uri.Query);

            var originalCount = newQueryString.Count;

            if (originalCount == 0)
            {
                return(url);
            }

            // this removes the key if exists
            newQueryString.Remove(key);

            if (originalCount == newQueryString.Count)
            {
                return(url);
            }

            // this gets the page path from root without QueryString
            string pagePathWithoutQueryString = url.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];

            return(newQueryString.Count > 0
                ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
                : pagePathWithoutQueryString);
        }
            public static StreamParams ParseFromUrl(string url, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager)
            {
                if (string.IsNullOrEmpty(url))
                {
                    throw new ArgumentNullException("url");
                }

                var request = new StreamParams
                {
                    ItemId = GetItemId(url)
                };

                Guid parsedId;

                if (string.IsNullOrWhiteSpace(request.ItemId) || !Guid.TryParse(request.ItemId, out parsedId))
                {
                    return(request);
                }

                var index = url.IndexOf('?');

                if (index == -1)
                {
                    return(request);
                }

                var query = url.Substring(index + 1);
                QueryParamCollection values = MyHttpUtility.ParseQueryString(query);

                request.DeviceProfileId = values.Get("DeviceProfileId");
                request.DeviceId        = values.Get("DeviceId");
                request.MediaSourceId   = values.Get("MediaSourceId");
                request.LiveStreamId    = values.Get("LiveStreamId");
                request.IsDirectStream  = string.Equals("true", values.Get("Static"), StringComparison.OrdinalIgnoreCase);

                request.AudioStreamIndex    = GetIntValue(values, "AudioStreamIndex");
                request.SubtitleStreamIndex = GetIntValue(values, "SubtitleStreamIndex");
                request.StartPositionTicks  = GetLongValue(values, "StartPositionTicks");

                request.Item = string.IsNullOrEmpty(request.ItemId)
                    ? null
                    : libraryManager.GetItemById(parsedId);

                request._mediaSourceManager = mediaSourceManager;

                return(request);
            }
示例#3
0
        public static string RemoveQueryStringByKey(string url, string key)
        {
            var uri = new Uri(url);

            // this gets all the query string key value pairs as a collection
            var newQueryString = MyHttpUtility.ParseQueryString(uri.Query);

            if (newQueryString.Count == 0)
            {
                return(url);
            }

            // this removes the key if exists
            newQueryString.Remove(key);

            // this gets the page path from root without QueryString
            string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path);

            return(newQueryString.Count > 0
                ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
                : pagePathWithoutQueryString);
        }