mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 18:23:32 +00:00
Google Play Music support for #190
This commit is contained in:
parent
852500c3e3
commit
8e0df35dd7
@ -9,6 +9,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
public WindowsProfileDataModel()
|
public WindowsProfileDataModel()
|
||||||
{
|
{
|
||||||
Spotify = new Spotify();
|
Spotify = new Spotify();
|
||||||
|
GooglePlayMusic = new GooglePlayMusic();
|
||||||
Cpu = new CpuDataModel();
|
Cpu = new CpuDataModel();
|
||||||
Performance = new PerformanceDataModel();
|
Performance = new PerformanceDataModel();
|
||||||
CurrentTime = new CurrentTime();
|
CurrentTime = new CurrentTime();
|
||||||
@ -17,6 +18,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
public CpuDataModel Cpu { get; set; }
|
public CpuDataModel Cpu { get; set; }
|
||||||
public PerformanceDataModel Performance { get; set; }
|
public PerformanceDataModel Performance { get; set; }
|
||||||
public Spotify Spotify { get; set; }
|
public Spotify Spotify { get; set; }
|
||||||
|
public GooglePlayMusic GooglePlayMusic { get; set; }
|
||||||
public CurrentTime CurrentTime { get; set; }
|
public CurrentTime CurrentTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,4 +65,39 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
public bool Playing { get; set; }
|
public bool Playing { get; set; }
|
||||||
public int SongLength { get; set; }
|
public int SongLength { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MoonSharpUserData]
|
||||||
|
public class GooglePlayMusic
|
||||||
|
{
|
||||||
|
public bool playing { get; set; }
|
||||||
|
public Song song { get; set; }
|
||||||
|
public Rating rating { get; set; }
|
||||||
|
public Time time { get; set; }
|
||||||
|
public string shuffle { get; set; }
|
||||||
|
public string repeat { get; set; }
|
||||||
|
public int volume { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[MoonSharpUserData]
|
||||||
|
public class Song
|
||||||
|
{
|
||||||
|
public string title { get; set; }
|
||||||
|
public string artist { get; set; }
|
||||||
|
public string album { get; set; }
|
||||||
|
public string albumArt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[MoonSharpUserData]
|
||||||
|
public class Rating
|
||||||
|
{
|
||||||
|
public bool liked { get; set; }
|
||||||
|
public bool disliked { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Time
|
||||||
|
{
|
||||||
|
public int current { get; set; }
|
||||||
|
public int total { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,12 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.DAL;
|
using Artemis.DAL;
|
||||||
using Artemis.Managers;
|
using Artemis.Managers;
|
||||||
using Artemis.Models;
|
using Artemis.Models;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
using SpotifyAPI.Local;
|
using SpotifyAPI.Local;
|
||||||
|
|
||||||
@ -20,13 +22,13 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
private PerformanceCounter _overallCpu;
|
private PerformanceCounter _overallCpu;
|
||||||
private SpotifyLocalAPI _spotify;
|
private SpotifyLocalAPI _spotify;
|
||||||
private bool _spotifySetupBusy;
|
private bool _spotifySetupBusy;
|
||||||
private DateTime _lastSpotifyUpdate;
|
private DateTime _lastMusicUpdate;
|
||||||
|
|
||||||
public WindowsProfileModel(ILogger logger, MainManager mainManager)
|
public WindowsProfileModel(ILogger logger, MainManager mainManager)
|
||||||
: base(mainManager, SettingsProvider.Load<WindowsProfileSettings>(), new WindowsProfileDataModel())
|
: base(mainManager, SettingsProvider.Load<WindowsProfileSettings>(), new WindowsProfileDataModel())
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_lastSpotifyUpdate = DateTime.Now;
|
_lastMusicUpdate = DateTime.Now;
|
||||||
|
|
||||||
Name = "WindowsProfile";
|
Name = "WindowsProfile";
|
||||||
}
|
}
|
||||||
@ -49,7 +51,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
{
|
{
|
||||||
var dataModel = (WindowsProfileDataModel) DataModel;
|
var dataModel = (WindowsProfileDataModel) DataModel;
|
||||||
UpdateCpu(dataModel);
|
UpdateCpu(dataModel);
|
||||||
UpdateSpotify(dataModel);
|
UpdateMusicPlayers(dataModel);
|
||||||
UpdateDay(dataModel);
|
UpdateDay(dataModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,13 +187,20 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateSpotify(WindowsProfileDataModel dataModel)
|
public void UpdateMusicPlayers(WindowsProfileDataModel dataModel)
|
||||||
{
|
{
|
||||||
// This is quite resource hungry so only update it once every two seconds
|
// This is quite resource hungry so only update it once every two seconds
|
||||||
if (DateTime.Now - _lastSpotifyUpdate < TimeSpan.FromSeconds(2))
|
if (DateTime.Now - _lastMusicUpdate < TimeSpan.FromSeconds(2))
|
||||||
return;
|
return;
|
||||||
_lastSpotifyUpdate = DateTime.Now;
|
_lastMusicUpdate = DateTime.Now;
|
||||||
|
|
||||||
|
UpdateSpotify(dataModel);
|
||||||
|
UpdateGooglePlayMusic(dataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateSpotify(WindowsProfileDataModel dataModel)
|
||||||
|
{
|
||||||
|
// Spotify
|
||||||
if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning())
|
if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning())
|
||||||
SetupSpotify();
|
SetupSpotify();
|
||||||
|
|
||||||
@ -217,6 +226,18 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateGooglePlayMusic(WindowsProfileDataModel dataModel)
|
||||||
|
{
|
||||||
|
// Google Play Music
|
||||||
|
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||||
|
if (!File.Exists(appData + @"\Google Play Music Desktop Player\json_store\playback.json"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
dataModel.GooglePlayMusic =
|
||||||
|
JsonConvert.DeserializeObject<GooglePlayMusic>(
|
||||||
|
File.ReadAllText(appData + @"\Google Play Music Desktop Player\json_store\playback.json"));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user