Example #1
0
        public async Task Start_WithMock_DualSource_Success()
        {
            var mockId1 = Guid.NewGuid().ToString();
            var mockId2 = Guid.NewGuid().ToString();

            using MockServer.MockServer mockServer = new MockServer.MockServer();
            mockServer.AddMockHandler(mockId1, start: 20, end: 30);
            mockServer.AddMockHandler(mockId2);
            mockServer.StartAsync();

            string id = Guid.NewGuid().ToString();

            string outDir = Path.Combine(Path.GetTempPath(), id);

            Directory.CreateDirectory(outDir);

            var success = false;

            var cs = new CancellationTokenSource();

            var hc = new DualSourceHTTPDownloader(
                new DualSourceHTTPDownloadInfo
            {
                Uri1 = $"http://127.0.0.1:39000/{mockId1}",
                Uri2 = $"http://127.0.0.1:39000/{mockId2}"
            },
                mediaProcessor: new FakeMediaProcessor());

            hc.Finished += (a, b) =>
            {
                success = true;
                cs.Cancel();
            };
            hc.Failed += (a, b) =>
            {
                success = false;
                cs.Cancel();
            };
            hc.TargetDir = outDir;
            hc.Start();
            try
            {
                await Task.Delay(Int32.MaxValue, cs.Token);
            }
            catch { }

            Assert.IsTrue(success);

            Console.WriteLine(hc.FileSize);
            Assert.NotZero(hc.FileSize);

            //mockServer.Stop();
            string hash1 = mockServer.GetHash(mockId1);
            string hash2 = mockServer.GetHash(mockId2);

            Assert.AreEqual(hash1, GetFileHash(Path.Combine(Config.DataDir, hc.Id, "1_" + hc.Id)));
            Assert.AreEqual(hash2, GetFileHash(Path.Combine(Config.DataDir, hc.Id, "2_" + hc.Id)));
        }
Example #2
0
        public static bool RefreshLink(DownloadItemBase item, IRefreshLinkDialog dialog)
        {
            try
            {
                if (item.DownloadType != "Http" && item.DownloadType != "Dash")
                {
                    return(false);
                }
                string?referer = null;
                if (item.DownloadType == "Http")
                {
                    var state = DownloadStateIO.LoadSingleSourceHTTPDownloaderState(item.Id);
                    referer = GetReferer(state.Headers);
                }
                else if (item.DownloadType == "Dash")
                {
                    var state = DownloadStateIO.LoadDualSourceHTTPDownloaderState(item.Id);
                    referer = GetReferer(state.Headers1);
                }
                else
                {
                    return(false);
                }
                Log.Debug("Referer: " + referer);
                if (referer != null)
                {
                    dialog.WatchingStopped += (a, b) =>
                    {
                        ApplicationContext.LinkRefresher.ClearWatchList();
                    };

                    OpenBrowser(referer);
                    if (item.DownloadType == "Http")
                    {
                        var downloader = new SingleSourceHTTPDownloader(item.Id);
                        downloader.RestoreState();
                        ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
                        ApplicationContext.LinkRefresher.AddToWatchList(downloader);
                    }
                    else if (item.DownloadType == "Dash")
                    {
                        var downloader = new DualSourceHTTPDownloader(item.Id);
                        downloader.RestoreState();
                        ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
                        ApplicationContext.LinkRefresher.AddToWatchList(downloader);
                    }

                    dialog.ShowWindow();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Log.Debug(e, e.Message);
            }
            return(false);
        }