public MuzlanClient GetNextMuzlanClient()
        {
            var config = new MuzlanClientConfig();

            if (Proxy != null)
            {
                config.ProxyAddress = $"{Proxy.Address}:{Proxy.Port}";

                config.NetworkUsername = Proxy.Username;
                config.NetworkPassword = Proxy.Password;
            }

            if (Proxies?.IsEmpty == false)
            {
                var proxy = Proxies.GetNextProxy();

                config.ProxyAddress = $"{proxy.Address}:{proxy.Port}";

                config.NetworkUsername = proxy.Username;
                config.NetworkPassword = proxy.Password;
            }

            _client = new MuzlanClient(config);

            return(_client);
        }
Beispiel #2
0
        public async static Task Main(string[] _)
        {
            var config = new MuzlanClientConfig();
            var client = new MuzlanClient();

            var auth = await client.Auth.Authenticate().ConfigureAwait(false);

            var searchResults = await client.Search.FindTracks("Landser", 1).ConfigureAwait(false);

            var track = searchResults.Result[0];

            Console.WriteLine($"Track: {track.Name} - {track.Artist}");

            client.Download.DownloadProgressChanged += Download_DownloadProgressChanged;

            var download = await client.Download.DownloadTrack(track, auth.Result).ConfigureAwait(false);

            await File.WriteAllBytesAsync(download.Result.Filename, download.Result.Data).ConfigureAwait(false);

            Console.ReadLine();
        }
Beispiel #3
0
        public static HttpClient Create(MuzlanClientConfig config)
        {
            var handler = new HttpClientHandler()
            {
                AllowAutoRedirect      = false,
                AutomaticDecompression = DecompressionMethods.All,
                CookieContainer        = new CookieContainer(),
                UseCookies             = true
            };

            if (config.NetworkUsername != null)
            {
                handler.Credentials     = new NetworkCredential(config.NetworkUsername, config.NetworkPassword);
                handler.PreAuthenticate = true;
            }

            if (!string.IsNullOrEmpty(config.ProxyAddress))
            {
                handler.Proxy = new WebProxy(config.ProxyAddress);

                if (config.ProxyUsername != null)
                {
                    handler.Proxy.Credentials = new NetworkCredential(config.ProxyUsername, config.ProxyPassword);
                }

                handler.UseProxy = true;
            }

            var client = new HttpClient(handler, true)
            {
                Timeout = TimeSpan.FromSeconds(10)
            };

            client.DefaultRequestHeaders.UserAgent.ParseAdd(config.UserAgent);

            return(client);
        }