Skip to content

Commit

Permalink
Use UWP APIs to get media information instead of openedfilesview.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdude123 committed Feb 15, 2021
1 parent ad0408e commit 58ec605
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 603 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,5 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
/MigrationBackup/2d4660d8/GroovyRPCore
4 changes: 4 additions & 0 deletions GroovyRPCore/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
48 changes: 7 additions & 41 deletions GroovyRPCore/GrooveInfoFetcher.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using CSCore.CoreAudioAPI;
using CsvHelper;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using Windows.Media.Control;

namespace GroovyRP
{
Expand All @@ -15,46 +15,12 @@ public TrackInfo GetTrackInfo()
{
var result = new TrackInfo();

var handleFinder = Process.Start("openedfilesview\\OpenedFilesView.exe", "/processfilter Music.UI.exe /scomma files.csv");
handleFinder.WaitForExit();
var streamReader = File.OpenText("files.csv");
var csvParser = new CsvParser(streamReader, CultureInfo.InvariantCulture);

var row = csvParser.Read();
var rows = new List<string[]>();

while (row != null)
{
rows.Add(row);
row = csvParser.Read();
}

foreach (string[] data in rows)
{
try
{
if (supportedFileTypes.Contains(data[20], StringComparer.OrdinalIgnoreCase))
{
var media = TagLib.File.Create(data[1]);

result.Title = media.Tag.Title ?? "Unknown Title";
result.Artist = media.Tag.Performers.DefaultIfEmpty(null).First() ?? media.Tag.AlbumArtists.DefaultIfEmpty(null).First() ?? "Unknown Artist";
result.Album = media.Tag.Album ?? "Unknown Album";

break;
}
streamReader.Close();
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message} \n{ex.StackTrace}");
csvParser.Dispose();
streamReader.Dispose();
return result;
}
}
csvParser.Dispose();
streamReader.Dispose();
GlobalSystemMediaTransportControlsSessionMediaProperties currentTrack = null;
currentTrack = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult().GetCurrentSession().TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
result.Title = currentTrack.Title ?? "Unknown Title";
result.Artist = currentTrack.Artist ?? currentTrack.AlbumArtist ?? "Unknown Artist";
result.Album = currentTrack.AlbumTitle ?? currentTrack.AlbumTitle;

return result;
}

Expand Down
96 changes: 45 additions & 51 deletions GroovyRPCore/GroovyRPCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -59,50 +61,11 @@
<ApplicationIcon>groovyrp.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CSCore, Version=1.2.1.2, Culture=neutral, PublicKeyToken=5a08f2b6f4415dea, processorArchitecture=MSIL">
<HintPath>..\packages\CSCore.1.2.1.2\lib\net35-client\CSCore.dll</HintPath>
</Reference>
<Reference Include="CsvHelper, Version=15.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823, processorArchitecture=MSIL">
<HintPath>..\packages\CsvHelper.15.0.0\lib\net47\CsvHelper.dll</HintPath>
</Reference>
<Reference Include="DiscordRPC, Version=1.0.175.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DiscordRichPresence.1.0.175\lib\net35\DiscordRPC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.HashCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
</Reference>
<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.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\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=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.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.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -111,8 +74,14 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\packages\taglib.2.1.0.0\lib\taglib-sharp.dll</HintPath>
<Reference Include="windows">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0\Facade\windows.winmd</HintPath>
</Reference>
<Reference Include="Windows.Foundation.FoundationContract">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
</Reference>
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -124,19 +93,9 @@
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
<None Include="openedfilesview\OpenedFilesView.chm">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="groovyrp.ico" />
<Content Include="openedfilesview\OpenedFilesView.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="openedfilesview\readme.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6">
Expand All @@ -150,5 +109,40 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSCore">
<Version>1.2.1.2</Version>
</PackageReference>
<PackageReference Include="DiscordRichPresence">
<Version>1.0.175</Version>
</PackageReference>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Bcl.HashCode">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.CSharp">
<Version>4.7.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
<Version>10.0.17763.1000</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="System.Memory">
<Version>4.5.4</Version>
</PackageReference>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
</PackageReference>
<PackageReference Include="taglib">
<Version>2.1.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 0 additions & 1 deletion GroovyRPCore/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
Expand Down
Binary file removed GroovyRPCore/openedfilesview/OpenedFilesView.chm
Binary file not shown.
Binary file removed GroovyRPCore/openedfilesview/OpenedFilesView.exe
Binary file not shown.
Loading

0 comments on commit 58ec605

Please sign in to comment.