Skip to content

Commit

Permalink
feat: use proxy (none, system, http) for downloads
Browse files Browse the repository at this point in the history
Suggested in #70
  • Loading branch information
Otiel committed Dec 7, 2018
1 parent e278e43 commit e41d0ce
Showing 1 changed file with 70 additions and 10 deletions.
80 changes: 70 additions & 10 deletions Sources/BandcampDownloader/Windows/WindowMain.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,20 @@ private Boolean DownloadAndTagTrack(String albumDirectoryPath, Album album, Trac
var doneEvent = new AutoResetEvent(false);

using (var webClient = new WebClient()) {
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
switch (App.UserSettings.Proxy) {
case ProxyType.None:
webClient.Proxy = null;
break;
case ProxyType.System:
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
}
break;
case ProxyType.Manual:
webClient.Proxy = new WebProxy(App.UserSettings.ProxyHttpAddress, App.UserSettings.ProxyHttpPort);
break;
default:
throw new NotImplementedException(); // Shouldn't happen
}

// Update progress bar when downloading
Expand Down Expand Up @@ -306,8 +318,20 @@ private TagLib.Picture DownloadCoverArt(Album album, String downloadsFolder) {
var doneEvent = new AutoResetEvent(false);

using (var webClient = new WebClient()) {
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
switch (App.UserSettings.Proxy) {
case ProxyType.None:
webClient.Proxy = null;
break;
case ProxyType.System:
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
}
break;
case ProxyType.Manual:
webClient.Proxy = new WebProxy(App.UserSettings.ProxyHttpAddress, App.UserSettings.ProxyHttpPort);
break;
default:
throw new NotImplementedException(); // Shouldn't happen
}

// Update progress bar when downloading
Expand Down Expand Up @@ -408,8 +432,20 @@ private List<Album> GetAlbums(List<String> urls) {
// Retrieve URL HTML source code
String htmlCode = "";
using (var webClient = new WebClient() { Encoding = Encoding.UTF8 }) {
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
switch (App.UserSettings.Proxy) {
case ProxyType.None:
webClient.Proxy = null;
break;
case ProxyType.System:
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
}
break;
case ProxyType.Manual:
webClient.Proxy = new WebProxy(App.UserSettings.ProxyHttpAddress, App.UserSettings.ProxyHttpPort);
break;
default:
throw new NotImplementedException(); // Shouldn't happen
}

if (this.userCancelled) {
Expand Down Expand Up @@ -450,8 +486,20 @@ private List<String> GetArtistDiscography(List<String> urls) {
// Retrieve URL HTML source code
String htmlCode = "";
using (var webClient = new WebClient() { Encoding = Encoding.UTF8 }) {
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
switch (App.UserSettings.Proxy) {
case ProxyType.None:
webClient.Proxy = null;
break;
case ProxyType.System:
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
}
break;
case ProxyType.Manual:
webClient.Proxy = new WebProxy(App.UserSettings.ProxyHttpAddress, App.UserSettings.ProxyHttpPort);
break;
default:
throw new NotImplementedException(); // Shouldn't happen
}

if (this.userCancelled) {
Expand All @@ -477,8 +525,20 @@ private List<String> GetArtistDiscography(List<String> urls) {

// Retrieve artist "music" page HTML source code
using (var webClient = new WebClient() { Encoding = Encoding.UTF8 }) {
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
switch (App.UserSettings.Proxy) {
case ProxyType.None:
webClient.Proxy = null;
break;
case ProxyType.System:
if (webClient.Proxy != null) {
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
}
break;
case ProxyType.Manual:
webClient.Proxy = new WebProxy(App.UserSettings.ProxyHttpAddress, App.UserSettings.ProxyHttpPort);
break;
default:
throw new NotImplementedException(); // Shouldn't happen
}

if (this.userCancelled) {
Expand Down

0 comments on commit e41d0ce

Please sign in to comment.