Skip to content

Commit 27d2dc9

Browse files
committed
Merge branch 'develop'
2 parents eb37502 + b0a4ef7 commit 27d2dc9

26 files changed

Lines changed: 140 additions & 171 deletions

Source/MultiFunPlayer/MediaSource/AbstractMediaSource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace MultiFunPlayer.MediaSource;
1313

1414
internal abstract class AbstractMediaSource : Screen, IMediaSource, IHandle<IMediaSourceControlMessage>
1515
{
16-
protected abstract Logger Logger { get; }
16+
protected Logger Logger { get; }
1717

1818
private readonly Channel<IMediaSourceControlMessage> _messageChannel;
1919
private readonly IEventAggregator _eventAggregator;
@@ -38,6 +38,7 @@ protected AbstractMediaSource(IShortcutManager shortcutManager, IEventAggregator
3838
_eventAggregator.Subscribe(this);
3939

4040
Name = GetType().GetCustomAttribute<DisplayNameAttribute>(inherit: false).DisplayName;
41+
Logger = LogManager.GetLogger(GetType().FullName);
4142

4243
RegisterActions(shortcutManager);
4344
}

Source/MultiFunPlayer/MediaSource/ViewModels/DeoVRMediaSource.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1818
[DisplayName("DeoVR")]
1919
internal sealed class DeoVRMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
2020
{
21-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
22-
2321
public override ConnectionStatus Status { get; protected set; }
2422
public bool IsConnected => Status == ConnectionStatus.Connected;
2523
public bool IsDisconnected => Status == ConnectionStatus.Disconnected;
@@ -118,12 +116,12 @@ private async Task ReadAsync(TcpClient client, NetworkStream stream, Cancellatio
118116
playerState ??= new PlayerState();
119117

120118
var dataBuffer = await stream.ReadExactlyAsync(length, token);
119+
var data = Encoding.UTF8.GetString(dataBuffer);
120+
Logger.Trace("Received \"{0}\" from \"{1}\"", data, Name);
121+
121122
try
122123
{
123-
var json = Encoding.UTF8.GetString(dataBuffer);
124-
var document = JObject.Parse(json);
125-
Logger.Trace("Received \"{0}\" from \"{1}\"", json, Name);
126-
124+
var document = JObject.Parse(data);
127125
if (document.TryGetValue("path", out var pathToken) && pathToken.TryToObject<string>(out var path))
128126
{
129127
if (string.IsNullOrWhiteSpace(path))

Source/MultiFunPlayer/MediaSource/ViewModels/EmbyMediaSource.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1313
[DisplayName("Emby")]
1414
internal sealed class EmbyMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
1515
{
16-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
17-
1816
private CancellationTokenSource _refreshCancellationSource = new();
1917
private EmbySession _currentSession;
2018

@@ -125,13 +123,11 @@ private async Task ReadAsync(HttpClient client, CancellationToken token)
125123

126124
var sessionsUri = new Uri(ServerBaseUri, $"/Sessions?api_key={ApiKey}&DeviceId={SelectedDeviceId}");
127125
var response = await client.GetAsync(sessionsUri, token);
128-
if (response == null)
129-
continue;
130-
131126
response.EnsureSuccessStatusCode();
132-
var message = await response.Content.ReadAsStringAsync(token);
133127

128+
var message = await response.Content.ReadAsStringAsync(token);
134129
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
130+
135131
try
136132
{
137133
var o = JArray.Parse(message).Children<JObject>().FirstOrDefault();
@@ -368,13 +364,13 @@ protected override void Dispose(bool disposing)
368364
base.Dispose(disposing);
369365
}
370366

371-
internal sealed record EmbyDevice(string Name, [JsonProperty("ReportedDeviceId")] string Id, string AppName, string AppVersion)
367+
internal sealed record EmbyDevice(string Name, [property: JsonProperty("ReportedDeviceId")] string Id, string AppName, string AppVersion)
372368
{
373369
public bool Equals(EmbyDevice other) => string.Equals(Id, other?.Id, StringComparison.Ordinal);
374370
public override int GetHashCode() => Id.GetHashCode();
375371
}
376372

377-
internal sealed record EmbySession(string Id, [JsonProperty("PlayState")] PlayState State, [JsonProperty("NowPlayingItem")] PlayItem Item);
378-
internal sealed record PlayState(long PositionTicks, bool IsPaused, double PlaybackRate);
379-
internal sealed record PlayItem(long RunTimeTicks, string Path);
373+
private sealed record EmbySession(string Id, [property: JsonProperty("PlayState")] PlayState State, [property: JsonProperty("NowPlayingItem")] PlayItem Item);
374+
private sealed record PlayState(long PositionTicks, bool IsPaused, double PlaybackRate);
375+
private sealed record PlayItem(long RunTimeTicks, string Path);
380376
}

Source/MultiFunPlayer/MediaSource/ViewModels/HereSphereMediaSource.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1818
[DisplayName("HereSphere")]
1919
internal sealed class HereSphereMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
2020
{
21-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
22-
2321
public override ConnectionStatus Status { get; protected set; }
2422
public bool IsConnected => Status == ConnectionStatus.Connected;
2523
public bool IsDisconnected => Status == ConnectionStatus.Disconnected;
@@ -117,12 +115,12 @@ private async Task ReadAsync(TcpClient client, NetworkStream stream, Cancellatio
117115
playerState ??= new PlayerState();
118116

119117
var dataBuffer = await stream.ReadExactlyAsync(length, token);
118+
var data = Encoding.UTF8.GetString(dataBuffer);
119+
Logger.Trace("Received \"{0}\" from \"{1}\"", data, Name);
120+
120121
try
121122
{
122-
var json = Encoding.UTF8.GetString(dataBuffer);
123-
var document = JObject.Parse(json);
124-
Logger.Trace("Received \"{0}\" from \"{1}\"", json, Name);
125-
123+
var document = JObject.Parse(data);
126124
if (document.TryGetValue("resource", out var resourceToken) && resourceToken.TryToObject<string>(out var resource))
127125
{
128126
if (string.IsNullOrWhiteSpace(resource))

Source/MultiFunPlayer/MediaSource/ViewModels/InternalMediaSource.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using MultiFunPlayer.Common;
1+
using MultiFunPlayer.Common;
22
using MultiFunPlayer.Script;
33
using MultiFunPlayer.Script.Repository;
44
using MultiFunPlayer.Shortcut;
@@ -18,8 +18,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1818
[DisplayName("Internal")]
1919
internal sealed class InternalMediaSource(ILocalScriptRepository localRepository, IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
2020
{
21-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
22-
2321
private readonly object _playlistLock = new();
2422

2523
private bool _isPlaying;

Source/MultiFunPlayer/MediaSource/ViewModels/JellyfinMediaSource.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1313
[DisplayName("Jellyfin")]
1414
internal sealed class JellyfinMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
1515
{
16-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
17-
1816
private CancellationTokenSource _refreshCancellationSource = new();
1917
private JellyfinSession _currentSession;
2018

@@ -125,13 +123,11 @@ private async Task ReadAsync(HttpClient client, CancellationToken token)
125123

126124
var sessionsUri = new Uri(ServerBaseUri, $"/Sessions?ApiKey={ApiKey}&DeviceId={SelectedDeviceId}");
127125
var response = await client.GetAsync(sessionsUri, token);
128-
if (response == null)
129-
continue;
130-
131126
response.EnsureSuccessStatusCode();
132-
var message = await response.Content.ReadAsStringAsync(token);
133127

128+
var message = await response.Content.ReadAsStringAsync(token);
134129
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
130+
135131
try
136132
{
137133
var o = JArray.Parse(message).Children<JObject>().FirstOrDefault();
@@ -371,7 +367,7 @@ internal sealed record JellyfinDevice(string Name, string Id, string AppName, st
371367
public override int GetHashCode() => Id.GetHashCode();
372368
}
373369

374-
internal sealed record JellyfinSession(string Id, [JsonProperty("PlayState")] PlayState State, [JsonProperty("NowPlayingItem")] PlayItem Item);
375-
internal sealed record PlayState(long PositionTicks, bool IsPaused);
376-
internal sealed record PlayItem(long RunTimeTicks, string Path);
370+
private sealed record JellyfinSession(string Id, [property: JsonProperty("PlayState")] PlayState State, [property: JsonProperty("NowPlayingItem")] PlayItem Item);
371+
private sealed record PlayState(long PositionTicks, bool IsPaused);
372+
private sealed record PlayItem(long RunTimeTicks, string Path);
377373
}

Source/MultiFunPlayer/MediaSource/ViewModels/MpcMediaSource.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1515
[DisplayName("MPC-HC")]
1616
internal sealed class MpcMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
1717
{
18-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
19-
2018
public override ConnectionStatus Status { get; protected set; }
2119
public bool IsConnected => Status == ConnectionStatus.Connected;
2220
public bool IsDisconnected => Status == ConnectionStatus.Disconnected;
@@ -96,15 +94,12 @@ private async Task ReadAsync(HttpClient client, CancellationToken token)
9694
await Task.Delay(200, token);
9795

9896
var response = await client.GetAsync(variablesUri, token);
99-
if (response == null)
100-
continue;
101-
10297
response.EnsureSuccessStatusCode();
103-
var message = await response.Content.ReadAsStringAsync(token);
10498

99+
var message = await response.Content.ReadAsStringAsync(token);
105100
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
106-
var variables = variableRegex.Matches(message).NotNull().ToDictionary(m => m.Groups["name"].Value, m => m.Groups["value"].Value);
107101

102+
var variables = variableRegex.Matches(message).NotNull().ToDictionary(m => m.Groups["name"].Value, m => m.Groups["value"].Value);
108103
if (variables.TryGetValue("state", out var stateString) && int.TryParse(stateString, out var state) && state != playerState.State)
109104
{
110105
PublishMessage(new MediaPlayingChangedMessage(state == 2));

Source/MultiFunPlayer/MediaSource/ViewModels/MpvMediaSource.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1919
[DisplayName("MPV")]
2020
internal sealed class MpvMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
2121
{
22-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
2322
private static string PipeName { get; } = "multifunplayer-mpv";
2423

2524
public override ConnectionStatus Status { get; protected set; }
@@ -155,13 +154,13 @@ private async Task ReadAsync(NamedPipeClientStream client, StreamReader reader,
155154
while (!token.IsCancellationRequested && client.IsConnected)
156155
{
157156
var message = await reader.ReadLineAsync(token);
157+
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
158+
158159
if (message == null)
159160
continue;
160161

161162
try
162163
{
163-
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
164-
165164
var document = JObject.Parse(message);
166165
if (!document.TryGetValue<string>("event", out var eventType))
167166
continue;

Source/MultiFunPlayer/MediaSource/ViewModels/OfsMediaSource.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1616
[DisplayName("OFS")]
1717
internal sealed class OfsMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
1818
{
19-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
20-
2119
public override ConnectionStatus Status { get; protected set; }
2220
public bool IsConnected => Status == ConnectionStatus.Connected;
2321
public bool IsDisconnected => Status == ConnectionStatus.Disconnected;
@@ -95,13 +93,13 @@ private async Task ReadAsync(ClientWebSocket client, CancellationToken token)
9593
while (!token.IsCancellationRequested && client.State == WebSocketState.Open)
9694
{
9795
var message = Encoding.UTF8.GetString(await client.ReceiveAsync(token));
96+
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
97+
9898
if (message == null)
9999
continue;
100100

101101
try
102102
{
103-
Logger.Trace("Received \"{0}\" from \"{1}\"", message, Name);
104-
105103
var document = JObject.Parse(message);
106104
if (!document.TryGetValue<string>("type", out var type) || !string.Equals(type, "event", StringComparison.OrdinalIgnoreCase))
107105
continue;

Source/MultiFunPlayer/MediaSource/ViewModels/PlexMediaSource.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ namespace MultiFunPlayer.MediaSource.ViewModels;
1515
[DisplayName("Plex")]
1616
internal sealed class PlexMediaSource(IShortcutManager shortcutManager, IEventAggregator eventAggregator) : AbstractMediaSource(shortcutManager, eventAggregator)
1717
{
18-
protected override Logger Logger { get; } = LogManager.GetCurrentClassLogger();
19-
2018
private CancellationTokenSource _refreshCancellationSource = new();
2119
private XmlNode _currentTimeline;
2220
private long _commandId;

0 commit comments

Comments
 (0)