-
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
17 changed files
with
893 additions
and
150 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,163 @@ | ||
// This file is part of the YTMDesktopCompanion.net472 project. | ||
// | ||
// Copyright (c) 2024 Dominic Ris | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#region | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using XeroxDev.YTMDesktop.Companion; | ||
using XeroxDev.YTMDesktop.Companion.Settings; | ||
|
||
#endregion | ||
|
||
namespace YTMDesktopCompanion.net472 | ||
{ | ||
internal class Program | ||
{ | ||
public static void Main(string[] _) | ||
{ | ||
// Run async method | ||
Test().Wait(); | ||
} | ||
|
||
private static async Task Test() | ||
{ | ||
#region Setup | ||
|
||
// Set YOUR version (or fetch them from anywhere) | ||
var version = "1.0.0"; | ||
|
||
// Check if file ".token" exists | ||
var tokenPath = Path.Combine(Path.GetTempPath(), "ytmd-csharp-lib-test.token"); | ||
if (!File.Exists(tokenPath)) | ||
{ | ||
// Create file (with empty content) | ||
File.Create(tokenPath).Close(); | ||
} | ||
|
||
// Read token from file | ||
var token = File.ReadAllText(tokenPath); | ||
|
||
// Define settings | ||
var settings = new ConnectorSettings( | ||
"127.0.0.1", | ||
9863, | ||
"ytmdesktop-cs-companion-example", | ||
"YTMDesktop C# Companion Example", | ||
version | ||
); | ||
|
||
// Check if token is set | ||
if (!string.IsNullOrWhiteSpace(token)) settings.Token = token; | ||
|
||
var connector = new CompanionConnector(settings); | ||
|
||
// extract clients for easier access | ||
var restClient = connector.RestClient; | ||
var socketClient = connector.SocketClient; | ||
|
||
#endregion | ||
|
||
#region RestClient | ||
|
||
// Get metadata | ||
var metadata = await restClient.GetMetadata(); | ||
if (metadata is null) | ||
{ | ||
Console.WriteLine("Failed to get metadata. Probably the server is not running or the settings are wrong."); | ||
return; | ||
} | ||
|
||
Console.WriteLine(JsonSerializer.Serialize(metadata)); | ||
|
||
// Example Rest Client usage | ||
|
||
// Check if token is set | ||
if (string.IsNullOrWhiteSpace(token)) | ||
{ | ||
// If not, try to request one and show it to the user | ||
var code = await restClient.GetAuthCode(); | ||
if (code is null) | ||
{ | ||
Console.WriteLine("Failed to get auth code. Probably the server is not running or the settings are wrong."); | ||
return; | ||
} | ||
|
||
Console.WriteLine($"Got new code, please compare it with the code from YTMDesktop: {code}"); | ||
|
||
token = await restClient.GetAuthToken(code); | ||
if (string.IsNullOrWhiteSpace(token)) | ||
{ | ||
Console.WriteLine("Something went wrong..."); | ||
return; | ||
} | ||
|
||
// Save token to file | ||
File.WriteAllText(tokenPath, token); | ||
|
||
// Show full path | ||
var fullPath = Path.GetFullPath(tokenPath); | ||
Console.WriteLine($"Authorization successful! Token saved to: {fullPath}"); | ||
|
||
connector.SetAuthToken(token); | ||
} | ||
|
||
// Get the current state and print it | ||
var state = await restClient.GetState(); | ||
Console.WriteLine(JsonSerializer.Serialize(state)); | ||
|
||
// Pause current track | ||
await restClient.Pause(); | ||
|
||
// wait 2 seconds | ||
await Task.Delay(2000); | ||
|
||
// Resume current track | ||
await restClient.Play(); | ||
|
||
#endregion | ||
|
||
#region SocketClient | ||
|
||
// Example Socket Client usage | ||
|
||
// Register events | ||
socketClient.OnError += (sender, args) => Console.WriteLine($"Error: {args.Message}"); | ||
socketClient.OnConnectionChange += (sender, args) => Console.WriteLine($"Connection changed: {args}"); | ||
socketClient.OnStateChange += (sender, args) => Console.WriteLine(JsonSerializer.Serialize(args)); | ||
socketClient.OnPlaylistCreated += (sender, args) => Console.WriteLine(JsonSerializer.Serialize(args)); | ||
socketClient.OnPlaylistDeleted += (sender, args) => Console.WriteLine($"Playlist deleted: {args}"); | ||
|
||
// Connect to the server | ||
await socketClient.Connect(); | ||
|
||
#endregion | ||
|
||
// Wait for user input to close the application | ||
Console.WriteLine("Press any key to exit..."); | ||
Console.ReadKey(); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("YTMDesktopCompanion.net472")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("YTMDesktopCompanion.net472")] | ||
[assembly: AssemblyCopyright("Copyright © 2024")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("6E7924FB-18BD-43AA-858C-358E29789E2C")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0")] |
94 changes: 94 additions & 0 deletions
94
YTMDesktopCompanion.net472/YTMDesktopCompanion.net472.csproj
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,94 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" | ||
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{6E7924FB-18BD-43AA-858C-358E29789E2C}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>YTMDesktopCompanion.net472</RootNamespace> | ||
<AssemblyName>YTMDesktopCompanion.net472</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath> | ||
</Reference> | ||
<Reference Include="mscorlib" /> | ||
<Reference Include="System"/> | ||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Core"/> | ||
<Reference Include="System.Data"/> | ||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Numerics" /> | ||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Text.Json, Version=8.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Text.Json.8.0.2\lib\net462\System.Text.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Xml"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs"/> | ||
<Compile Include="Properties\AssemblyInfo.cs"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\YTMDesktopCompanion\YTMDesktopCompanion.csproj"> | ||
<Project>{749f5eba-0cfb-4f3a-84a7-9d0e288620d2}</Project> | ||
<Name>YTMDesktopCompanion</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
|
||
</Project> |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net472" /> | ||
<package id="System.Buffers" version="4.5.1" targetFramework="net472" /> | ||
<package id="System.Memory" version="4.5.5" targetFramework="net472" /> | ||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" /> | ||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" /> | ||
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net472" /> | ||
<package id="System.Text.Json" version="8.0.2" targetFramework="net472" /> | ||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" /> | ||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> | ||
</packages> |
Oops, something went wrong.