forked from Tyrrrz/YoutubeExplode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
422 additions
and
1,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace YoutubeExplode.Utils; | ||
|
||
// Used to extend an externally provided HttpClient with additional behavior | ||
internal abstract class ClientDelegatingHandler : HttpMessageHandler | ||
{ | ||
private readonly HttpClient _http; | ||
private readonly bool _disposeClient; | ||
|
||
protected ClientDelegatingHandler(HttpClient http, bool disposeClient = false) | ||
{ | ||
_http = http; | ||
_disposeClient = disposeClient; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync( | ||
HttpRequestMessage request, | ||
CancellationToken cancellationToken) => | ||
await _http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing && _disposeClient) | ||
_http.Dispose(); | ||
|
||
base.Dispose(disposing); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace YoutubeExplode.Utils.Extensions; | ||
|
||
internal static class BinaryExtensions | ||
{ | ||
public static string ToHex(this byte[] data, bool isUpperCase = true) | ||
{ | ||
var buffer = new StringBuilder(2 * data.Length); | ||
|
||
foreach (var b in data) | ||
{ | ||
buffer.Append( | ||
b.ToString(isUpperCase ? "X2" : "x2", CultureInfo.InvariantCulture) | ||
); | ||
} | ||
|
||
return buffer.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace YoutubeExplode.Utils.Extensions; | ||
|
||
internal static class UriExtensions | ||
{ | ||
public static string GetDomain(this Uri uri) => uri.Scheme + Uri.SchemeDelimiter + uri.Host; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Security.Cryptography; | ||
|
||
namespace YoutubeExplode.Utils; | ||
|
||
internal static class Hash | ||
{ | ||
public static byte[] Compute(HashAlgorithm algorithm, byte[] data) | ||
{ | ||
using (algorithm) | ||
return algorithm.ComputeHash(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,11 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
|
||
namespace YoutubeExplode.Utils; | ||
|
||
internal static class Http | ||
{ | ||
private static readonly Lazy<HttpClient> HttpClientLazy = new(() => | ||
{ | ||
var handler = new HttpClientHandler | ||
{ | ||
// https://github.com/Tyrrrz/YoutubeExplode/issues/530 | ||
UseCookies = false | ||
}; | ||
|
||
if (handler.SupportsAutomaticDecompression) | ||
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; | ||
|
||
return new HttpClient(handler, true); | ||
}); | ||
private static readonly Lazy<HttpClient> HttpClientLazy = new(() => new HttpClient()); | ||
|
||
public static HttpClient Client => HttpClientLazy.Value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.