Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Miced library issue #1844

Merged
merged 22 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion EmbyStat.Clients.Base/Http/BaseHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
Expand Down
1 change: 0 additions & 1 deletion EmbyStat.Clients.Tmdb/TmdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using EmbyStat.Clients.Base.Metadata;
using EmbyStat.Common.Models.Show;
using EmbyStat.Configuration;
using EmbyStat.Configuration.Interfaces;
Expand Down
2 changes: 1 addition & 1 deletion EmbyStat.Clients.TvMaze/EmbyStat.Clients.TvMaze.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TvMaze.Api.Client" Version="0.1.72" />
<PackageReference Include="TvMaze.Api.Client" Version="0.1.75" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions EmbyStat.Clients.TvMaze/TvMazeShowClient.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using AutoMapper;
using EmbyStat.Clients.Base.Metadata;
using EmbyStat.Clients.Tmdb;
using EmbyStat.Common.Models.Show;
using EmbyStat.Configuration;
using EmbyStat.Configuration.Interfaces;
using TvMaze.Api.Client;
using TvMaze.Api.Client.Models;
Expand Down
6 changes: 6 additions & 0 deletions EmbyStat.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ public static class JwtClaimIdentifiers

//COMMON
public static string Unknown => "UNKNOWN";

public static class Users
{
public static string TotalWatchedEpisodes => "USERS.WATCHED.EPISODES";
public static string TotalWatchedMovies => "USERS.WATCHED.MOVIES";
}
}
2 changes: 1 addition & 1 deletion EmbyStat.Common/Converters/SessionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static IEnumerable<Session> ConvertToSessions(JArray sessions)

if (session["PlayState"]["MediaSourceId"] != null)
{
Enum.TryParse(session["NowPlayingItem"]["Type"].Value<string>(), true, out PlayType playType);
Enum.TryParse(session["NowPlayingItem"]["Type"].Value<string>(), true, out MediaType playType);
var play = new Play
{
MediaId = session["NowPlayingItem"]["Id"].Value<string>(),
Expand Down
8 changes: 4 additions & 4 deletions EmbyStat.Common/EmbyStat.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.6" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.19.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.7" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.21.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Rollbar.NetCore.AspNet" Version="5.2.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.19.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace EmbyStat.Common.Enums;

public enum PlayType
public enum MediaType
{
Unknown = 0,
Movie = 1,
Expand Down
16 changes: 16 additions & 0 deletions EmbyStat.Common/Extensions/LibrarySyncTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using EmbyStat.Common.Enums;
using EmbyStat.Common.Models.Entities;

namespace EmbyStat.Common.Extensions;

public static class LibrarySyncTypeExtensions
{
public static DateTime? GetLastSyncedDateForLibrary(this IEnumerable<LibrarySyncType> items, string libraryId, LibraryType type)
{
return items.FirstOrDefault(x => x.LibraryId == libraryId && x.SyncType == type)?.LastSynced;
}
}
4 changes: 2 additions & 2 deletions EmbyStat.Common/Models/Cards/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace EmbyStat.Common.Models.Cards;

public class Card<T>
public class Card
{
public string Title { get; set; }
public T Value { get; set; }
public string Value { get; set; }
public CardType Type { get; set; }
public string Icon { get; set; }
}
2 changes: 1 addition & 1 deletion EmbyStat.Common/Models/Entities/Events/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Play
public Guid Id { get; set; }
public string SessionId { get; set; }
public string UserId { get; set; }
public PlayType Type { get; set; }
public MediaType Type { get; set; }
public string MediaId { get; set; }
public ICollection<PlayState> PlayStates { get; set; }
public string SubtitleCodec { get; set; }
Expand Down
1 change: 1 addition & 0 deletions EmbyStat.Common/Models/Entities/Helpers/ILinkedMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface ILinkedMedia
ICollection<MediaPerson> People { get; set; }
ICollection<Genre> Genres { get; set; }
Library Library { get; set; }
public string LibraryId { get; set; }
}
3 changes: 1 addition & 2 deletions EmbyStat.Common/Models/Entities/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class Library
public string Name { get; set; }
public string Primary { get; set; }
public LibraryType Type { get; set; }
public bool Sync { get; set; }
public DateTime? LastSynced { get; set; }
public ICollection<Movie> Movies { get; set; }
public ICollection<Shows.Show> Shows { get; set; }
public ICollection<LibrarySyncType> SyncTypes { get; set; }
}
13 changes: 13 additions & 0 deletions EmbyStat.Common/Models/Entities/LibrarySyncType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
 using System;
using EmbyStat.Common.Enums;

namespace EmbyStat.Common.Models.Entities;

public class LibrarySyncType
{
public string Id { get; set; }
public string LibraryId { get; set; }
public Library Library { get; set; }
public LibraryType SyncType { get; set; }
public DateTime? LastSynced { get; set; }
}
3 changes: 2 additions & 1 deletion EmbyStat.Common/Models/Entities/MediaServerUserView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using EmbyStat.Common.Enums;
using EmbyStat.Common.Models.Entities.Users;

namespace EmbyStat.Common.Models.Entities;
Expand All @@ -7,7 +8,7 @@ public class MediaServerUserView
{
public string UserId { get; set; }
public MediaServerUser User { get; set; }
public string MediaType { get; set; }
public MediaType MediaType { get; set; }
public string MediaId { get; set; }
public int PlayCount { get; set; }
public DateTime LastPlayedDate { get; set; }
Expand Down
1 change: 1 addition & 0 deletions EmbyStat.Common/Models/Entities/Movies/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public override int GetHashCode()
public ICollection<MediaPerson> People { get; set; }
public ICollection<Genre> Genres { get; set; }
public Library Library { get; set; }
public string LibraryId { get; set; }
#endregion
}
2 changes: 0 additions & 2 deletions EmbyStat.Common/Models/Entities/Users/MediaServerUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ public class MediaServerUser
public string PrimaryImageTag { get; set; }
public DateTimeOffset? LastLoginDate { get; set; }
public DateTimeOffset? LastActivityDate { get; set; }

public bool PlayDefaultAudioTrack { get; set; }
public string SubtitleLanguagePreference { get; set; }
public bool DisplayMissingEpisodes { get; set; }
public string SubtitleMode { get; set; }

public bool IsAdministrator { get; set; }
public bool IsHidden { get; set; }
public bool IsHiddenRemotely { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions EmbyStat.Controllers/EmbyStat.Controllers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aiursoft.XelNaga" Version="6.0.5" />
<PackageReference Include="Aiursoft.XelNaga" Version="6.0.6" />
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" />
<PackageReference Include="TvMaze.Api.Client" Version="0.1.72" />
<PackageReference Include="TvMaze.Api.Client" Version="0.1.75" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions EmbyStat.Controllers/HelperClasses/CardViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace EmbyStat.Controllers.HelperClasses;

public class CardViewModel<T>
public class CardViewModel
{
public string Title { get; set; }
public T Value { get; set; }
public string Value { get; set; }
public string Type { get; set; }
public string Icon { get; set; }
}
22 changes: 18 additions & 4 deletions EmbyStat.Controllers/MapProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public MapProfiles()
src => src.MapFrom((org, _) =>
org.EndTimeUtc?.ToString("O") ?? string.Empty));

CreateMap(typeof(Card<>), typeof(CardViewModel<>))
CreateMap<Card, CardViewModel>()
.ForMember("Type", src => src.MapFrom((org, _) =>
{
return ((Card<string>) org).Type switch
return ((Card) org).Type switch
{
CardType.Text => "text",
CardType.Size => "size",
Expand All @@ -79,7 +79,8 @@ public MapProfiles()
};
}));

CreateMap<Library, LibraryViewModel>();
CreateMap<Library, LibraryViewModel>()
.ForMember(x => x.Sync, x => x.Ignore());
CreateMap<Chart, ChartViewModel>();

CreateMap<SystemInfo, MediaServerInfo>()
Expand Down Expand Up @@ -145,13 +146,16 @@ private void CreateMediaServerUserMappings()
.ForMember(x => x.DisplayMissingEpisodes, x => x.MapFrom(y => y.Configuration.DisplayMissingEpisodes))
.ForMember(x => x.SubtitleMode, x => x.MapFrom(y => y.Configuration.SubtitleMode));

CreateMap<UserMediaView, UserMediaViewViewModel>();
CreateMap<MediaServerUserRow, MediaServerUserRowViewModel>();
CreateMap<MediaServerUser, UserOverviewViewModel>();
CreateMap<MediaServerUser, UserFullViewModel>();

CreateMap<MediaServerUserStatistics, MediaServerUserStatisticsViewModel>();

CreateMap<BaseItemDto, MediaServerUserView>()
.ForMember(x => x.MediaId, x => x.MapFrom(y => y.Id))
.ForMember(x => x.MediaType, x => x.MapFrom(y => y.Type))
.ForMember(x => x.MediaType, x => x.MapFrom(y => MapMediaType(y.Type)))
.ForMember(x => x.PlayCount, x => x.MapFrom(y => y.UserData.PlayCount))
.ForMember(x => x.UserId, x => x.Ignore())
.ForMember(x => x.LastPlayedDate, x => x.MapFrom(y => y.UserData.LastPlayedDate));
Expand Down Expand Up @@ -324,6 +328,16 @@ private void CreateLibraryMappings()
.ForMember(x => x.Type, x => x.MapFrom(y => y.CollectionType.ToLibraryType()))
.ForMember(x => x.Primary, x => x.MapFrom(y => y.ImageTags.ConvertToImageTag()));
}

private static MediaType MapMediaType(string type)
{
return type switch
{
"Movie" => MediaType.Movie,
"Episode" => MediaType.Episode,
_ => MediaType.Unknown
};
}
}

public static class DictionaryMappingExtensions
Expand Down
13 changes: 6 additions & 7 deletions EmbyStat.Controllers/MediaServer/MediaServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public async Task<IActionResult> GetMediaServerStatus()
public async Task<IActionResult> GetMediaServerLibraries()
{
var result = await _mediaServerService.GetMediaServerLibraries();
return Ok(_mapper.Map<IList<LibraryViewModel>>(result));
var map = _mapper.Map<IList<LibraryViewModel>>(result);
return Ok(map);
}

[HttpPost]
Expand Down Expand Up @@ -144,13 +145,11 @@ public async Task<IActionResult> GetUserById(string id)

var mappedUser = _mapper.Map<UserFullViewModel>(user);

var viewedEpisodeCount = _mediaServerService.GetViewedEpisodeCountByUserId(id);
var viewedMovieCount = _mediaServerService.GetViewedMovieCountByUserId(id);
var lastWatchedMedia = _mediaServerService.GetUserViewPageByUserId(id, 0,10).ToList();
var viewedEpisodeCount = await _mediaServerService.GetViewedEpisodeCountByUserId(id);
var viewedMovieCount = await _mediaServerService.GetViewedMovieCountByUserId(id);

mappedUser.ViewedEpisodeCount = _mapper.Map<CardViewModel<int>>(viewedEpisodeCount);
mappedUser.ViewedMovieCount = _mapper.Map<CardViewModel<int>>(viewedMovieCount);
mappedUser.LastWatchedMedia = _mapper.Map<IList<UserMediaViewViewModel>>(lastWatchedMedia);
mappedUser.ViewedEpisodeCount = _mapper.Map<CardViewModel>(viewedEpisodeCount);
mappedUser.ViewedMovieCount = _mapper.Map<CardViewModel>(viewedMovieCount);

return Ok(mappedUser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ namespace EmbyStat.Controllers.MediaServer;

public class MediaServerUserStatisticsViewModel
{
public List<CardViewModel<string>> Cards { get; set; }

public List<CardViewModel> Cards { get; set; }
}
28 changes: 23 additions & 5 deletions EmbyStat.Controllers/MediaServer/UserFullViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System;
using EmbyStat.Controllers.HelperClasses;

namespace EmbyStat.Controllers.MediaServer;
Expand All @@ -7,10 +7,28 @@ public class UserFullViewModel
{
public string Id { get; set; }
public string Name { get; set; }
public string PrimaryImageTag { get; set; }
public DateTimeOffset? LastLoginDate { get; set; }
public DateTimeOffset? LastActivityDate { get; set; }
public string SubtitleLanguagePreference { get; set; }
public string ServerId { get; set; }
public bool IsAdministrator { get; set; }
public bool Deleted { get; set; }
public CardViewModel<int> ViewedMovieCount { get; set; }
public CardViewModel<int> ViewedEpisodeCount { get; set; }
public IList<UserMediaViewViewModel> LastWatchedMedia { get; set; }
public bool IsHidden { get; set; }
public bool IsHiddenRemotely { get; set; }
public bool IsHiddenFromUnusedDevices { get; set; }
public bool IsDisabled { get; set; }
public bool EnableLiveTvAccess { get; set; }
public bool EnableContentDeletion { get; set; }
public bool EnableContentDownloading { get; set; }
public bool EnableSubtitleDownloading { get; set; }
public bool EnableSubtitleManagement { get; set; }
public bool EnableSyncTranscoding { get; set; }
public bool EnableMediaConversion { get; set; }
public int InvalidLoginAttemptCount { get; set; }
public bool EnablePublicSharing { get; set; }
public int RemoteClientBitrateLimit { get; set; }
public int SimultaneousStreamLimit { get; set; }
public bool EnableAllDevices { get; set; }
public CardViewModel ViewedMovieCount { get; set; }
public CardViewModel ViewedEpisodeCount { get; set; }
}
Loading