Example #1
0
        public DualSourceHTTPDownloader(DualSourceHTTPDownloadInfo info, IHttpClient hc = null,
                                        AuthenticationInfo?authentication = null, ProxyInfo?proxy = null,
                                        BaseMediaProcessor mediaProcessor = null)
        {
            Id = Guid.NewGuid().ToString();

            var uri1 = new Uri(info.Uri1);
            var uri2 = new Uri(info.Uri2);

            this.state = new DualSourceHTTPDownloaderState
            {
                Url1           = uri1,
                Url2           = uri2,
                Id             = Id,
                Cookies1       = info.Cookies1,
                Cookies2       = info.Cookies2,
                Headers1       = info.Headers1,
                Headers2       = info.Headers2,
                TempDir        = Path.Combine(Config.Instance.TempDir, Id),
                Authentication = authentication,
                Proxy          = proxy
            };

            if (this.state.Authentication == null)
            {
                this.state.Authentication = Helpers.GetAuthenticationInfoFromConfig(this.state.Url1);
            }

            this.http           = hc;
            this.TargetFileName = FileHelper.SanitizeFileName(info.File);
            this.mediaProcessor = mediaProcessor;
        }
Example #2
0
 public override void RestoreState()
 {
     state = DownloadStateIO.LoadDualSourceHTTPDownloaderState(Id !);
     try
     {
         if (!TransactedIO.ReadStream("chunks.db", state !.TempDir !, s =>
         {
             pieces = ChunkStateFromBytes(s);
         }))
         {
             throw new FileNotFoundException(Path.Combine(state.TempDir, "chunks.db"));
         }
     }
     catch
     {
         // ignored
         Log.Debug("Chunk restore failed");
     }
     TicksAndSizeAtResume();
 }