async Task<string> LoadContents(IResourceNetworkLayer networkLayer, IProgress<float> progress, CancellationToken token)
            {
                var reset = _cancelTokenSource.AddToken(token);
                if (_pageContentLoadPack == null || reset)
                {
                    lock(this)
                    {
                        if (_pageContentLoadPack == null || reset)
                        {
                            if (_originalUrl.Contains("&ajax=1"))
                                _pageContentLoadPack = Tuple.Create(networkLayer.Get(_originalUrl, _cancelTokenSource.Token, progress, null, false), progress);
                            else
                                _pageContentLoadPack = Tuple.Create(networkLayer.Get(_originalUrl + "&ajax=1", token, progress, null, false), progress);
                        }
                    }
                    
                }

                if (_pageContentLoadPack.Item2 != progress)
                {
                    HttpClientUtility.NetworkLayer.JoinProgress(_pageContentLoadPack.Item2, progress);
                }

                try
                {
                    return await _pageContentLoadPack.Item1;
                }
                finally
                {
                    _cancelTokenSource.Clear();
                }
            }
			public async Task<IEnumerable<Tuple<string, string>>> PlayableStreams(IResourceNetworkLayer networkLayer, IProgress<float> progress, System.Threading.CancellationToken cancelToken)
			{
				string gfyName = GetGfyName(_originalUrl);
				var jsonResult = await networkLayer.Get("http://gfycat.com/cajax/get/" + gfyName, cancelToken, progress, null, false);
				var gfyResult = JsonConvert.DeserializeObject<GfyResult>(jsonResult);
				return new List<Tuple<string, string>> { Tuple.Create(gfyResult.gfyItem.mp4Url, "MP4") };
			}
        public async Task <IEnumerable <Tuple <string, string> > > GetImagesFromUri(string title, Uri uri, IResourceNetworkLayer networkLayer, IProgress <float> progress, CancellationToken token)
        {
            try
            {
                var href = uri.OriginalString;
                if (href.IndexOf("/sizes") == -1)
                {
                    var inPosition = href.IndexOf("/in/");
                    var inFragment = "";
                    if (inPosition != -1)
                    {
                        inFragment = href.Substring(inPosition);
                        href       = href.Substring(0, inPosition);
                    }

                    href += "/sizes/c" + inFragment;
                }
                href = href.Replace("/lightbox", "");
                var jsonResult = await networkLayer.Get("http://www.flickr.com/services/oembed/?format=json&url=" + Uri.EscapeUriString(href), token, progress, null, false);

                var resultObject = JsonConvert.DeserializeObject <OEmbedResult>(jsonResult);
                return(new Tuple <string, string>[] { Tuple.Create(resultObject.author_name + " via " + resultObject.provider_name + " : " + resultObject.title, resultObject.url) });
            }
            catch
            {
                return(Enumerable.Empty <Tuple <string, string> >());
            }
        }
		public async Task<IEnumerable<Tuple<string, string>>> GetImagesFromUri(string title, Uri uri, IResourceNetworkLayer networkLayer, IProgress<float> progress, CancellationToken token)
        {
            try
            {
                var href = uri.OriginalString;
                if (href.IndexOf("/sizes") == -1)
                {
                    var inPosition = href.IndexOf("/in/");
                    var inFragment = "";
                    if (inPosition != -1)
                    {
                        inFragment = href.Substring(inPosition);
                        href = href.Substring(0, inPosition);
                    }

                    href += "/sizes/c" + inFragment;
                }
                href = href.Replace("/lightbox", "");
                var jsonResult = await networkLayer.Get("http://www.flickr.com/services/oembed/?format=json&url=" + Uri.EscapeUriString(href), token, progress, null, false);
                var resultObject = JsonConvert.DeserializeObject<OEmbedResult>(jsonResult);
                return new Tuple<string, string>[] { Tuple.Create(resultObject.author_name + " via " + resultObject.provider_name + " : " + resultObject.title, resultObject.url) };
            }
            catch
            {
                return Enumerable.Empty<Tuple<string, string>>();
            }
        }
        public async Task <IEnumerable <Tuple <string, string> > > GetImagesFromUri(string title, Uri uri, IResourceNetworkLayer networkLayer, IProgress <float> progress, CancellationToken token)
        {
            var href   = uri.OriginalString.Split('?')[0];
            var groups = hashRe.Match(href).Groups;

            if (groups.Count > 2 && string.IsNullOrWhiteSpace(groups[2].Value))
            {
                var hash = groups[1].Value;
                if (hash.StartsWith("m"))
                {
                    var apiURL     = "http://min.us/api/GetItems/" + hash;
                    var jsonResult = await networkLayer.Get(apiURL, token, progress, null, false);

                    dynamic result = JsonConvert.DeserializeObject(jsonResult);
                    return(new Tuple <string, string>[] { Tuple.Create(title, (string)result.src) });
                }
                else
                {
                    return(Enumerable.Empty <Tuple <string, string> >());
                }
            }
            else
            {
                return(Enumerable.Empty <Tuple <string, string> >());
            }
        }
 private static async Task <string> HttpGet(string uri, IResourceNetworkLayer networkLayer, IProgress <float> progress, CancellationToken token)
 {
     using (var headeredNetworkLayer = networkLayer.Clone())
     {
         networkLayer.AddHeaders("User-Agent", BotUserAgent);
         return(await networkLayer.Get(uri, token, progress, null, true));
     }
 }
Beispiel #7
0
            public async Task <IEnumerable <Tuple <string, string> > > PlayableStreams(IResourceNetworkLayer networkLayer, IProgress <float> progress, System.Threading.CancellationToken cancelToken)
            {
                string gfyName    = GetGfyName(_originalUrl);
                var    jsonResult = await networkLayer.Get("http://gfycat.com/cajax/get/" + gfyName, cancelToken, progress, null, false);

                var gfyResult = JsonConvert.DeserializeObject <GfyResult>(jsonResult);

                return(new List <Tuple <string, string> > {
                    Tuple.Create(gfyResult.gfyItem.mp4Url, "MP4")
                });
            }
Beispiel #8
0
            async Task <string> LoadContents(IResourceNetworkLayer networkLayer, IProgress <float> progress, CancellationToken token)
            {
                var reset = _cancelTokenSource.AddToken(token);

                if (_pageContentLoadPack == null || reset)
                {
                    lock (this)
                    {
                        if (_pageContentLoadPack == null || reset)
                        {
                            if (_originalUrl.Contains("&ajax=1"))
                            {
                                _pageContentLoadPack = Tuple.Create(networkLayer.Get(_originalUrl, _cancelTokenSource.Token, progress, null, false), progress);
                            }
                            else
                            {
                                _pageContentLoadPack = Tuple.Create(networkLayer.Get(_originalUrl + "&ajax=1", token, progress, null, false), progress);
                            }
                        }
                    }
                }

                if (_pageContentLoadPack.Item2 != progress)
                {
                    HttpClientUtility.NetworkLayer.JoinProgress(_pageContentLoadPack.Item2, progress);
                }

                try
                {
                    return(await _pageContentLoadPack.Item1);
                }
                finally
                {
                    _cancelTokenSource.Clear();
                }
            }
        public async Task<IEnumerable<Tuple<string, string>>> GetImagesFromUri(string title, Uri uri, IResourceNetworkLayer networkLayer, IProgress<float> progress, CancellationToken token)
        {
            var href = uri.OriginalString.Split('?')[0];
            var groups = hashRe.Match(href).Groups;

            if (groups.Count > 2 && string.IsNullOrWhiteSpace(groups[2].Value))
            {
                var hash = groups[1].Value;
                if (hash.StartsWith("m"))
                {
                    var apiURL = "http://min.us/api/GetItems/" + hash;
                    var jsonResult = await networkLayer.Get(apiURL, token, progress, null, false);
                    dynamic result = JsonConvert.DeserializeObject(jsonResult);
                    return new Tuple<string, string>[] { Tuple.Create(title, (string)result.src) };
                }
                else
                    return Enumerable.Empty<Tuple<string, string>>();
            }
            else
                return Enumerable.Empty<Tuple<string, string>>();
        }
		private static async Task<string> HttpGet(string uri, IResourceNetworkLayer networkLayer, IProgress<float> progress, CancellationToken token)
		{
            using (var headeredNetworkLayer = networkLayer.Clone())
            {
                networkLayer.AddHeaders("User-Agent", BotUserAgent);
                return await networkLayer.Get(uri, token, progress, null, true);
            }
		}