Skip to content

Commit

Permalink
merge YTExplode 6.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Sep 19, 2024
2 parents a78dc08 + 3513192 commit efa813d
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 94 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Additionally, the streams are further divided into 3 categories based on their c
> To download the video in the highest available quality, you will need to resolve the best audio-only and video-only streams separately and then mux them together.
> The muxing process can be performed using FFmpeg with the help of the [**YoutubeExplode.Converter**](YoutubeExplode.Converter) package.
> **Warning**:
> Muxed streams are deprecated by YouTube and are not guaranteed to be available for every video.
> If possible, avoid relying on them too much and instead perform muxing manually using the provided audio-only and video-only streams.
You can request the manifest that lists all available streams for a particular video by calling `Videos.Streams.GetManifestAsync(...)`:

```csharp
Expand Down
31 changes: 15 additions & 16 deletions YoutubeDownloader.Converter.Tests/Utils/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ public static class FFmpeg
{
private static readonly SemaphoreSlim Lock = new(1, 1);

public static Version Version { get; } = new(6, 1);
public static Version Version { get; } = new(7, 0);

private static string FileName { get; } =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "ffmpeg.exe" : "ffmpeg";
private static string FileName { get; } = OperatingSystem.IsWindows() ? "ffmpeg.exe" : "ffmpeg";

public static string FilePath { get; } =
Path.Combine(
Expand All @@ -32,13 +31,13 @@ private static string GetDownloadUrl()
{
static string GetPlatformMoniker()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
return "windows";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (OperatingSystem.IsLinux())
return "linux";

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
return "osx";

throw new NotSupportedException("Unsupported OS platform.");
Expand Down Expand Up @@ -68,31 +67,31 @@ private static byte[] GetDownloadHash()
{
static string GetHashString()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
return "48130a80aebffb61d06913350c3ad3187efd85096f898045fd65001bf89d7d7f";
return "96f2d2fae3a298adadf8aaa19c8b79c04ba18afef61f8b8d157032ccd5170992";

if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
return "71e83e4d5b4ed8e9e5b13a8bc118b73affef2ff12f9e14c388bfb17db7008f8d";
return "81b49b5d9cd3ff9ace26f29b0b3cf7cd6358769f27ad32f8079b14a9db0a1e7a";

if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
return "cd2d765565d1cc36e3fc0653d8ad6444c1736b883144de885c1f178a404c977c";
return "58efff14efe66ae666f9d9145ee035e360e80cc0d61b0ebc4162e3528e7aa933";
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (OperatingSystem.IsLinux())
{
if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
return "856b4f0e5cd9de45c98b703f7258d578bbdc0ac818073a645315241f9e7d5780";
return "d1e03fb8dbe439b5f626706140973d48e5704bf0b30d529828a0fcb8cf5abed8";
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
return "1671abe5dcc0b4adfaea6f2e531e377a3ccd8ea21aa2b5a0589b0e5ae7d85a37";
return "af9ef6994ef259ae3ae6dc215170c80db5d4390ea7cfe53cc30a544dd8f68a9b";

if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
return "bcbc7de089f68c3565dd40e8fe462df28a181af8df756621fc4004a747b845cf";
return "d799c74e8b17bd40b42cf7a2ad02b6045022085bcd14ecfaea3cd1012d6add30";
}

throw new NotSupportedException("Unsupported architecture.");
Expand Down Expand Up @@ -138,7 +137,7 @@ private static async ValueTask DownloadAsync()
}

// Add the execute permission on Unix
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (!OperatingSystem.IsWindows())
{
File.SetUnixFileMode(
FilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader.Converter/ConversionPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public enum ConversionPreset
/// <summary>
/// Fastest conversion speed and biggest output file size.
/// </summary>
UltraFast = 3
UltraFast = 3,
}
2 changes: 1 addition & 1 deletion YoutubeDownloader.Converter/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private async ValueTask ProcessAsync(
}

// Metadata for subtitles
foreach (var (subtitleInput, i) in subtitleInputs.WithIndex())
foreach (var (i, subtitleInput) in subtitleInputs.Index())
{
// Language codes can be stored in any format, but most players expect
// three-letter codes, so we'll try to convert to that first.
Expand Down
4 changes: 1 addition & 3 deletions YoutubeDownloader.Converter/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ internal partial class FFmpeg
public static string GetFilePath() =>
// Try to find FFmpeg in the probe directory
Directory
.EnumerateFiles(
AppDomain.CurrentDomain.BaseDirectory ?? Directory.GetCurrentDirectory()
)
.EnumerateFiles(AppContext.BaseDirectory ?? Directory.GetCurrentDirectory())
.FirstOrDefault(f =>
string.Equals(
Path.GetFileNameWithoutExtension(f),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public static TOut Pipe<TIn, TOut>(this TIn input, Func<TIn, TOut> transform) =>

public static T Clamp<T>(this T value, T min, T max)
where T : IComparable<T> =>
value.CompareTo(min) <= 0
? min
: value.CompareTo(max) >= 0
? max
: value;
value.CompareTo(min) <= 0 ? min
: value.CompareTo(max) >= 0 ? max
: value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ internal static class LanguageExtensions
"za" => "zha",
"zh" => "zho",
"zu" => "zul",
_ => null
_ => null,
};
}
}
7 changes: 4 additions & 3 deletions YoutubeDownloader.Converter/Utils/ProgressMuxer.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using System.Collections.Generic;
using System.Threading;

namespace YoutubeExplode.Converter.Utils;

internal class ProgressMuxer(IProgress<double> target)
{
private readonly object _lock = new();
private readonly Lock _lock = new();
private readonly Dictionary<int, double> _splitWeights = new();
private readonly Dictionary<int, double> _splitValues = new();

public IProgress<double> CreateInput(double weight = 1)
{
lock (_lock)
using (_lock.EnterScope())
{
var index = _splitWeights.Count;

Expand All @@ -20,7 +21,7 @@ public IProgress<double> CreateInput(double weight = 1)

return new Progress<double>(p =>
{
lock (_lock)
using (_lock.EnterScope())
{
_splitValues[index] = p;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.12.0" PrivateAssets="all" />
<PackageReference Include="PolyShim" Version="1.13.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader.Demo.Gui/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Video is not null
FileTypeChoices = fileTypes
?.Select(t => new FilePickerFileType($"{t} file") { Patterns = [$"*.{t}"] })
.ToArray(),
DefaultExtension = Path.GetExtension(defaultFileName)
DefaultExtension = Path.GetExtension(defaultFileName),
}
);

Expand Down
14 changes: 7 additions & 7 deletions YoutubeDownloader.Demo.Gui/YoutubeDownloader.Demo.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.2.1" />
<PackageReference Include="Avalonia" Version="11.0.11" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.11" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.11" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2" PrivateAssets="all" />
<PackageReference Include="Material.Avalonia" Version="3.6.0" />
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.3.0" />
<PackageReference Include="Avalonia" Version="11.1.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.1.3" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.0" />
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
<PackageReference Include="Material.Avalonia" Version="3.7.2" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions YoutubeDownloader.Tests/PlaylistSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task I_can_get_videos_included_in_a_playlist()
"dN3gkBBffhs",
"8Kg-8ZjgLAQ",
"E9zfpKsw6f8",
"eBCw9sC5D40"
"eBCw9sC5D40",
]
);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public async Task I_can_get_videos_included_in_a_large_playlist()
"RnGJ3KJri1g",
"x-IR7PtA7RA",
"N-8E9mHxDy0",
"5ly88Ju1N6A"
"5ly88Ju1N6A",
]
);
}
Expand Down
10 changes: 5 additions & 5 deletions YoutubeDownloader.Tests/YoutubeDownloader.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.29.1" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="PolyShim" Version="1.12.0" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="PolyShim" Version="1.13.0" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/Channels/ChannelClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async ValueTask<Channel> GetAsync(
new Thumbnail(
"https://www.gstatic.com/youtube/img/tvfilm/clapperboard_profile.png",
new Resolution(1024, 1024)
)
),
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/Common/Thumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static IReadOnlyList<Thumbnail> GetDefaultSet(VideoId videoId) =>
new Thumbnail(
$"https://img.youtube.com/vi/{videoId}/hqdefault.jpg",
new Resolution(480, 360)
)
),
];
}

Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/Search/SearchFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public enum SearchFilter
/// <summary>
/// Only search for channels.
/// </summary>
Channel
Channel,
}
7 changes: 0 additions & 7 deletions YoutubeDownloader/Utils/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ namespace YoutubeExplode.Utils.Extensions;

internal static class CollectionExtensions
{
public static IEnumerable<(T value, int index)> WithIndex<T>(this IEnumerable<T> source)
{
var i = 0;
foreach (var o in source)
yield return (o, i++);
}

public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
where T : class
{
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/Utils/Extensions/HttpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static HttpRequestMessage Clone(this HttpRequestMessage request)
// Don't dispose the original request's content
Content = request.Content is not null
? new NonDisposableHttpContent(request.Content)
: null
: null,
};

foreach (var (key, value) in request.Headers)
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/Utils/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static string SwapChars(this string str, int firstCharIndex, int secondCh
new StringBuilder(str)
{
[firstCharIndex] = str[secondCharIndex],
[secondCharIndex] = str[firstCharIndex]
[secondCharIndex] = str[firstCharIndex],
}.ToString();

public static int? ParseIntOrNull(this string str) =>
Expand Down
12 changes: 6 additions & 6 deletions YoutubeDownloader/Utils/Json.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json;
using YoutubeExplode.Utils.Extensions;

namespace YoutubeExplode.Utils;

Expand All @@ -16,20 +16,20 @@ public static string Extract(string source)

// We trust that the source contains valid json, we just need to extract it.
// To do it, we will be matching curly braces until we even out.
foreach (var (c, i) in source.WithIndex())
foreach (var (i, ch) in source.Index())
{
var prev = i > 0 ? source[i - 1] : default;

buffer.Append(c);
buffer.Append(ch);

// Detect if inside a string
if (c == '"' && prev != '\\')
if (ch == '"' && prev != '\\')
isInsideString = !isInsideString;
// Opening brace
else if (c == '{' && !isInsideString)
else if (ch == '{' && !isInsideString)
depth++;
// Closing brace
else if (c == '}' && !isInsideString)
else if (ch == '}' && !isInsideString)
depth--;

// Break when evened out
Expand Down
Loading

0 comments on commit efa813d

Please sign in to comment.