Exemplo n.º 1
0
        public static async Task <List <string> > GetFileDownloadLink(IEnumerable <YunFile> files)
        {
            var metas = await BaiduYun.GetFileMetadata(files);

            if (metas == null)
            {
                return(null);
            }

            var ret = new List <string>();

            foreach (var meta in metas)
            {
                if (meta.dlink == null)
                {
                    return(null);
                }
                var url = meta.dlink + String.Format("&cflg={0}", Utils.GetCookieValue("cflag", Constants.PAN_URL));
                using (var request = Utils.GetRequest(url)) {
                    request.Headers.Add("Accept", Constants.ACCEPT_HTML);

                    using (var response = await Utils.RequestNoRedirectAsync(request)) {
                        if (response != null && response.StatusCode == Windows.Web.Http.HttpStatusCode.Found)
                        {
                            ret.Add(response.Headers.Location.ToString());
                        }
                        else
                        {
                            var guanjia = await BaiduYun.GuanjiaDownload(meta.path);

                            if (guanjia != null)
                            {
                                ret.Add(guanjia);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
        public async Task AddTask(YunFile file, IStorageItem location)
        {
            if (file.isdir == 0)
            {
                var url = await BaiduYun.GetFileDownloadLink(new[] { file });

                if (url == null)
                {
                    return;
                }
                await NewAsyncDownloadTask(url[0], location as IStorageFile);
            }
            else
            {
                var subfolder = await(location as IStorageFolder).CreateFolderAsync(file.server_filename, CreationCollisionOption.OpenIfExists);
                var tasks     = await HandleFolder(file, subfolder);

                await Task.WhenAll(tasks);
            }
        }
Exemplo n.º 3
0
        private async Task <List <Task> > HandleFolder(YunFile folder, IStorageFolder location)
        {
            var tasks = new List <Task>();
            var files = new List <YunFile>();

            foreach (var file in await BaiduYun.GetFileList(folder.path))
            {
                if (file.isdir == 1)
                {
                    var subfolder = await location.CreateFolderAsync(file.server_filename, CreationCollisionOption.OpenIfExists);

                    tasks.AddRange(await HandleFolder(file, subfolder));
                }
                else
                {
                    files.Add(file);
                }
            }
            tasks.AddRange(await NewAsyncDownloadTasks(files, location));
            return(tasks);
        }
Exemplo n.º 4
0
        private async Task <List <Task> > NewAsyncDownloadTasks(IEnumerable <YunFile> files, IStorageFolder location)
        {
            var urllist = await BaiduYun.GetFileDownloadLink(files);

            var tasks = new List <Task>();

            if (urllist == null)
            {
                return(tasks);
            }
            var url = urllist.GetEnumerator();

            foreach (var file in files)
            {
                if (!url.MoveNext())
                {
                    return(tasks);
                }
                var fileitem = await location.CreateFileAsync(file.server_filename, CreationCollisionOption.GenerateUniqueName);

                tasks.Add(NewAsyncDownloadTask(url.Current, fileitem));
            }
            return(tasks);
        }
Exemplo n.º 5
0
        public static async Task <string> GetFileDownloadLink(YunFile file)
        {
            var url = await BaiduYun.GetFileDownloadLink(new List <YunFile>() { file });

            return(url.FirstOrDefault());
        }