Skip to content

Commit

Permalink
Merge pull request #9 from madeyoga/linux-macos-support
Browse files Browse the repository at this point in the history
Linux & macos Support
  • Loading branch information
madeyoga authored Apr 9, 2022
2 parents 71d9b9b + 895c220 commit 846349b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
15 changes: 13 additions & 2 deletions Discord.Addons.Music/Common/TrackLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Web;

Expand Down Expand Up @@ -61,10 +62,20 @@ public static async Task<List<AudioTrack>> LoadAudioTrack(string query, bool fro

public static Process LoadFFmpegProcess(string url)
{
string filename = $"/bin/bash";
string command = $"-c \"youtube-dl --format bestaudio -o - {url} | ffmpeg -loglevel panic -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1\"";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
filename = "cmd.exe";
command = $"/C youtube-dl.exe --format bestaudio --audio-quality 0 -o - {url} | " +
"ffmpeg.exe -loglevel warning -re -vn -i pipe:0 -f s16le -b:a 128k -ar 48000 -ac 2 pipe:1";
}

return Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C youtube-dl.exe --format --audio-quality 0 bestaudio -o - {url} | ffmpeg.exe -loglevel panic -i pipe:0 -c:a libopus -b:a 96K -ac 2 -f s16le -ar 48000 pipe:1",
FileName = filename,
Arguments = command,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
Expand Down
6 changes: 3 additions & 3 deletions Discord.Addons.Music/Discord.Addons.Music.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<Copyright>MIT</Copyright>
<PackageProjectUrl>https://github.com/madeyoga/Discord.Addons.Music</PackageProjectUrl>
<RepositoryUrl>https://github.com/madeyoga/Discord.Addons.Music</RepositoryUrl>
<Version>0.1.1</Version>
<Version>0.2.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyVersion>0.1.1.0</AssemblyVersion>
<FileVersion>0.1.1.0</FileVersion>
<AssemblyVersion>0.2.0.0</AssemblyVersion>
<FileVersion>0.2.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
13 changes: 11 additions & 2 deletions Discord.Addons.Music/Source/AudioTrack.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -11,11 +12,19 @@ public class AudioTrack : FFmpegAudioSource

public override void LoadProcess()
{
string command = $"/C youtube-dl.exe --format bestaudio --audio-quality 0 -o - {Url} | " +
string filename = $"/bin/bash";
string command = $"-c \"youtube-dl --format bestaudio -o - {Url} | ffmpeg -loglevel panic -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1\"";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
filename = "cmd.exe";
command = $"/C youtube-dl.exe --format bestaudio --audio-quality 0 -o - {Url} | " +
"ffmpeg.exe -loglevel warning -re -vn -i pipe:0 -f s16le -b:a 128k -ar 48000 -ac 2 pipe:1";
}

FFmpegProcess = Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
FileName = filename,
Arguments = command,
RedirectStandardOutput = true,
UseShellExecute = false,
Expand Down
5 changes: 1 addition & 4 deletions ExampleMusicBot/ExampleMusicBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Addons.Music" Version="0.2.0" />
<PackageReference Include="Discord.Net" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageReference Include="YoutubeSearchApi.Net" Version="2021.8.24" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Discord.Addons.Music\Discord.Addons.Music.csproj" />
</ItemGroup>

</Project>

0 comments on commit 846349b

Please sign in to comment.