private void saveOriginalProxyConfiguration(RegistryKey reg) { if (originalValues != null) { return; } originalValues = getProxyInfoFromRegistry(reg); }
private WebProxyInfo ParseWebProxyInfo(ProxyInfo?proxyInfo) { bool doNotUseProxy = false; IWebProxy proxy = null; if (proxyInfo != null) { doNotUseProxy = (proxyInfo?.Disabled ?? false); if (!doNotUseProxy) { proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = new NetworkCredential(proxyInfo?.Username.Value ?? "", proxyInfo?.Password.Value ?? ""); } } return(new WebProxyInfo() { DoNotUseProxy = doNotUseProxy, Proxy = proxy }); }
internal static IWebProxy?GetProxy(ProxyInfo?proxy) { if (proxy.HasValue) { Log.Debug("Proxy type: " + proxy.Value.ProxyType); if (proxy.Value.ProxyType == ProxyType.Direct) { return(new WebProxy()); } else if (proxy.Value.ProxyType == ProxyType.Custom) { var p = new WebProxy(proxy.Value.Host, proxy.Value.Port); if (!string.IsNullOrEmpty(proxy.Value.UserName)) { p.Credentials = new NetworkCredential(proxy.Value.UserName, proxy.Value.Password); } return(p); } } return(null); }
public void AddItemToTop( string id, string targetFileName, DateTime date, long fileSize, string type, FileNameFetchMode fileNameFetchMode, string primaryUrl, DownloadStartType startType, AuthenticationInfo?authentication, ProxyInfo?proxyInfo) { var downloadEntry = new InProgressDownloadItem { Name = targetFileName, DateAdded = date, DownloadType = type, Id = id, Progress = 0, Size = fileSize, Status = startType == DownloadStartType.Waiting ? DownloadStatus.Waiting : DownloadStatus.Stopped, TargetDir = "", PrimaryUrl = primaryUrl, Authentication = authentication, Proxy = proxyInfo }; AppDB.Instance.Downloads.AddNewDownload(downloadEntry); RunOnUiThread(() => { ApplicationContext.MainWindow.AddToTop(downloadEntry); ApplicationContext.MainWindow.SwitchToInProgressView(); ApplicationContext.MainWindow.ClearInProgressViewSelection(); UpdateToolbarButtonState(); }); }
public MultiSourceHLSDownloader(MultiSourceHLSDownloadInfo info, IHttpClient http = null, BaseMediaProcessor mediaProcessor = null, AuthenticationInfo?authentication = null, ProxyInfo?proxy = null) : base(info, http, mediaProcessor) { var state = new MultiSourceHLSDownloadState { Id = base.Id, Cookies = info.Cookies, Headers = info.Headers, Authentication = authentication, Proxy = proxy, TempDirectory = Path.Combine(Config.Instance.TempDir, Id) }; if (state.Authentication == null) { state.Authentication = Helpers.GetAuthenticationInfoFromConfig(new Uri(info.VideoUri ?? info.AudioUri)); } Log.Debug("Video playlist url: " + info.VideoUri + " Audio playlist url: " + info.AudioUri); if (info.VideoUri != null && info.AudioUri != null) { state.NonMuxedVideoPlaylistUrl = new Uri(info.VideoUri); state.NonMuxedAudioPlaylistUrl = new Uri(info.AudioUri); state.Demuxed = true; } else { state.MuxedPlaylistUrl = new Uri(info.VideoUri); state.Demuxed = false; } this._state = state; this.TargetFileName = FileHelper.SanitizeFileName(info.File); }
internal void RestoreOriginalSettings() { if (originalValues == null) { return; } using (var reg = Registry.CurrentUser.OpenSubKey(regKeyInternetSettings, true)) { if (reg == null) { return; } var ov = originalValues; if (ov.AutoConfigUrl != null) { reg.SetValue(regAutoConfigUrl, ov.AutoConfigUrl); } else { reg.DeleteValue(regAutoConfigUrl, false); } if (ov.ProxyEnable.HasValue) { reg.SetValue(regProxyEnable, ov.ProxyEnable.Value); } else { reg.DeleteValue(regProxyEnable, false); } if (ov.ProxyServer != null) { reg.SetValue(regProxyServer, ov.ProxyServer); } else { reg.DeleteValue(regProxyServer, false); } if (ov.ProxyOverride != null) { reg.SetValue(regProxyOverride, ov.ProxyOverride); } else { reg.DeleteValue(regProxyOverride, false); } // This should not be needed, but sometimes the values are not stored into the registry // at system shutdown without flushing. reg.Flush(); originalValues = null; const int SM_SHUTTINGDOWN = 0x2000; Version windows7Version = new Version(6, 1); if (Environment.OSVersion.Version > windows7Version || NativeMethods.GetSystemMetrics(SM_SHUTTINGDOWN) == 0) { // Do not call refresh() in Windows 7 or earlier at system shutdown. // SetInternetOption in the refresh method re-enables ProxyEnable registry value // in Windows 7 or earlier at system shutdown. refresh(); } } }
internal WinHttpClient(ProxyInfo?proxy) { this.proxy = proxy; }
public MultiSourceDASHDownloader(MultiSourceDASHDownloadInfo info, IHttpClient http = null, BaseMediaProcessor mediaProcessor = null, AuthenticationInfo?authentication = null, ProxyInfo?proxy = null) : base(info, http, mediaProcessor) { var state = new MultiSourceDASHDownloadState { Id = base.Id, Demuxed = info.VideoSegments != null && info.AudioSegments != null, Cookies = info.Cookies, Headers = info.Headers, Url = info.Url, Authentication = authentication, Proxy = proxy, TempDirectory = Path.Combine(Config.Instance.TempDir, Id) }; if (state.Authentication == null) { state.Authentication = Helpers.GetAuthenticationInfoFromConfig(new Uri(info.Url)); } this._state = state; this.TargetFileName = FileHelper.SanitizeFileName(info.File); state.FileSize = -1; var i = 0; if (state.Demuxed) { state.AudioChunkCount = info.AudioSegments.Count; state.VideoChunkCount = info.VideoSegments.Count; state.AudioSegments = info.AudioSegments; state.VideoSegments = info.VideoSegments; state.Duration = info.Duration; state.AudioContainerFormat = info.AudioFormat ?? FileExtensionHelper.GetExtensionFromMimeType(info.AudioMimeType) ?? GuessContainerFormatFromPlaylist(info.AudioSegments); state.VideoContainerFormat = info.VideoFormat ?? FileExtensionHelper.GetExtensionFromMimeType(info.VideoMimeType) ?? GuessContainerFormatFromPlaylist(info.VideoSegments); CreateChunks2(state, _chunks, _chunkStreamMap); //for (; i < Math.Min(this._state.AudioChunkCount, this._state.VideoChunkCount); i++) //{ // var chunk1 = CreateChunk(info.VideoSegments[i], 0); // _chunks.Add(chunk1); // _chunkStreamMap.StreamMap[chunk1.Id] = Path.Combine(_state.TempDirectory, "1_" + chunk1.Id + FileHelper.GetFileName(chunk1.Uri)); // var chunk2 = CreateChunk(info.AudioSegments[i], 1); // _chunks.Add(chunk2); // _chunkStreamMap.StreamMap[chunk2.Id] = Path.Combine(_state.TempDirectory, "2_" + chunk2.Id + FileHelper.GetFileName(chunk2.Uri)); //} //for (; i < this._state.VideoChunkCount; i++) //{ // var chunk = CreateChunk(info.VideoSegments[i], 0); // _chunks.Add(chunk); // _chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(_state.TempDirectory, "1_" + chunk.Id + FileHelper.GetFileName(chunk.Uri)); //} //for (; i < this._state.AudioChunkCount; i++) //{ // var chunk = CreateChunk(info.AudioSegments[i], 1); // _chunks.Add(chunk); // _chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(_state.TempDirectory, "2_" + chunk.Id + FileHelper.GetFileName(chunk.Uri)); //} var ext = FileExtensionHelper.GetExtensionFromMimeType(info.VideoMimeType) ?? FileExtensionHelper.GuessContainerFormatFromSegmentExtension(state.VideoContainerFormat); //if (!(string.IsNullOrWhiteSpace(state.VideoContainerFormat) || state.VideoContainerFormat == ".")) //{ // ext = Helpers.GetExtensionFromMimeType(info.VideoMimeType) // ?? Helpers.GuessContainerFormatFromSegmentExtension( // state.VideoContainerFormat.ToLowerInvariant(), true); //} TargetFileName = Path.GetFileNameWithoutExtension(TargetFileName ?? "video") + ext; } else { var segments = info.VideoSegments ?? info.AudioSegments; state.VideoChunkCount = segments.Count; state.VideoSegments = segments; state.Duration = info.Duration; CreateChunks1(state, _chunks, _chunkStreamMap); //for (; i < this._state.VideoChunkCount; i++) //{ // var chunk = CreateChunk(segments[i], 0); // _chunks.Add(chunk); // _chunkStreamMap.StreamMap[chunk.Id] = Path.Combine(_state.TempDirectory, "1_" + chunk.Id + FileHelper.GetFileName(chunk.Uri)); //} state.VideoContainerFormat = GuessContainerFormatFromPlaylist(segments); var ext = FileExtensionHelper.GuessContainerFormatFromSegmentExtension( this._state.VideoContainerFormat.ToLowerInvariant()); TargetFileName = Path.GetFileNameWithoutExtension(TargetFileName ?? "video") + ext; } }