This repository was archived by the owner on Apr 12, 2026. It is now read-only.
forked from Stephanzion/YandexMusicBetaMod
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.cs
More file actions
52 lines (42 loc) · 1.57 KB
/
Utils.cs
File metadata and controls
52 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Globalization;
using System.Net;
using Avalonia.Data.Converters;
namespace YandexMusicPatcherGui;
public class ProgressToWidthConverter : IValueConverter
{
public static readonly ProgressToWidthConverter Instance = new();
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not (double progress and >= 0 and <= 100) || parameter is not double width) return 0.0;
return progress / 100.0 * width;
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
public static class Utils
{
private const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36";
public static readonly HttpClient HttpClient;
public static readonly HttpClient NoRedirectHttpClient;
static Utils()
{
HttpClient = CreateHttpClient(true);
NoRedirectHttpClient = CreateHttpClient(false);
}
private static HttpClient CreateHttpClient(bool allowAutoRedirect)
{
var handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
AllowAutoRedirect = allowAutoRedirect
};
var client = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(45)
};
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
return client;
}
}