Skip to content

Commit

Permalink
fixed json case + added episode ids + empty response error
Browse files Browse the repository at this point in the history
  • Loading branch information
ekleop committed Oct 31, 2023
1 parent 5d51ec8 commit 906d1ab
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 27 deletions.
20 changes: 20 additions & 0 deletions Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text.Json.Serialization;
using MediaBrowser.Model.Dto;
#pragma warning disable SA1300

namespace Jellyfin.Plugin.Simkl.API.Objects
Expand All @@ -9,6 +10,19 @@ namespace Jellyfin.Plugin.Simkl.API.Objects
/// </summary>
public class SimklEpisode : SimklMediaObject
{
/// <summary>
/// Initializes a new instance of the <see cref="SimklEpisode"/> class.
/// </summary>
/// <param name="media">Episode Data.</param>
public SimklEpisode(BaseItemDto media)
{
Title = media?.SeriesName;
Ids = media is not null ? new SimklIds(media.ProviderIds) : null;
Year = media?.ProductionYear;
Season = media?.ParentIndexNumber;
Episode = media?.IndexNumber;
}

/// <summary>
/// Gets or sets watched at.
/// </summary>
Expand All @@ -21,6 +35,12 @@ public class SimklEpisode : SimklMediaObject
[JsonPropertyName("title")]
public string? Title { get; set; }

/// <summary>
/// Gets or sets the title.
/// </summary>
[JsonPropertyName("year")]
public int? Year { get; set; }

/// <summary>
/// Gets or sets the season.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions Jellyfin.Plugin.Simkl/API/Objects/SimklIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ public SimklIds(Dictionary<string, string> providerIds)
{
Simkl = Convert.ToInt32(value, CultureInfo.InvariantCulture);
}
else if (key.Equals(nameof(Anidb), StringComparison.OrdinalIgnoreCase))
{
Anidb = Convert.ToInt32(value, CultureInfo.InvariantCulture);
}
else if (key.Equals(nameof(Imdb), StringComparison.OrdinalIgnoreCase))
{
Imdb = value;
}
else if (key.Equals(nameof(Tvdb), StringComparison.OrdinalIgnoreCase))
{
Tvdb = value;
}
else if (key.Equals(nameof(Slug), StringComparison.OrdinalIgnoreCase))
{
Slug = value;
Expand Down Expand Up @@ -70,5 +78,17 @@ public SimklIds(Dictionary<string, string> providerIds)
/// </summary>
[JsonPropertyName("tmdb")]
public string? Tmdb { get; set; }

/// <summary>
/// Gets or sets the TVDB id.
/// </summary>
[JsonPropertyName("tvdb")]
public string? Tvdb { get; set; }

/// <summary>
/// Gets or sets the AniDB id.
/// </summary>
[JsonPropertyName("anidb")]
public int? Anidb { get; set; }
}
}
12 changes: 0 additions & 12 deletions Jellyfin.Plugin.Simkl/API/Objects/SimklMovieIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,12 @@ public SimklMovieIds(Dictionary<string, string> providerMovieIds)
{
}

/// <summary>
/// Gets or sets the tvdb id.
/// </summary>
[JsonPropertyName("tvdb")]
public int? Tvdb { get; set; }

/// <summary>
/// Gets or sets the mal id.
/// </summary>
[JsonPropertyName("mal")]
public int? Mal { get; set; }

/// <summary>
/// Gets or sets the anidb id.
/// </summary>
[JsonPropertyName("anidb")]
public int? Anidb { get; set; }

/// <summary>
/// Gets or sets the hulu id.
/// </summary>
Expand Down
12 changes: 0 additions & 12 deletions Jellyfin.Plugin.Simkl/API/Objects/SimklShowIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,12 @@ public SimklShowIds(Dictionary<string, string> providerMovieIds)
{
}

/// <summary>
/// Gets or sets tvdb.
/// </summary>
[JsonPropertyName("tvdb")]
public int? Tvdb { get; set; }

/// <summary>
/// Gets or sets mal.
/// </summary>
[JsonPropertyName("mal")]
public int? Mal { get; set; }

/// <summary>
/// Gets or sets anidb.
/// </summary>
[JsonPropertyName("anidb")]
public int? Anidb { get; set; }

/// <summary>
/// Gets or sets hulu.
/// </summary>
Expand Down
21 changes: 18 additions & 3 deletions Jellyfin.Plugin.Simkl/API/SimklApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.Tracing;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -113,8 +114,12 @@ public SimklApi(ILogger<SimklApi> logger, IHttpClientFactory httpClientFactory)
{
var history = CreateHistoryFromItem(item);
var r = await SyncHistoryAsync(history, userToken);
_logger.LogDebug("BaseItem: " + JsonSerializer.Serialize(item));
_logger.LogDebug("History: " + JsonSerializer.Serialize(history));
_logger.LogDebug("Response: {@Response}", r);
if (r != null && history.Movies.Count == r.Added.Movies && history.Shows.Count == r.Added.Shows)
if (r != null && history.Movies.Count == r.Added.Movies
&& history.Shows.Count == r.Added.Shows
&& history.Episodes.Count == r.Added.Episodes)
{
return (true, item);
}
Expand Down Expand Up @@ -218,11 +223,16 @@ private static SimklHistory CreateHistoryFromItem(BaseItemDto item)
{
history.Movies.Add(new SimklMovie(item));
}
else if (item.IsSeries == true || item.Type == BaseItemKind.Episode)
else if (item.IsSeries == true || (item.Type == BaseItemKind.Series))
{
// Jellyfin sends episode id instead of show id
// TODO: TV Shows scrobbling (WIP)
history.Shows.Add(new SimklShow(item));
}
else if (item.Type == BaseItemKind.Episode)
{
history.Episodes.Add(new SimklEpisode(item));
}

return history;
}
Expand Down Expand Up @@ -277,6 +287,7 @@ private static SimklHistory CreateHistoryFromItem(BaseItemDto item)
using var options = GetOptions(userToken);
options.RequestUri = new Uri(Baseurl + url);
options.Method = HttpMethod.Post;

if (data != null)
{
options.Content = new StringContent(
Expand All @@ -287,7 +298,11 @@ private static SimklHistory CreateHistoryFromItem(BaseItemDto item)

var responseMessage = await _httpClientFactory.CreateClient(NamedClient.Default)
.SendAsync(options);
return await responseMessage.Content.ReadFromJsonAsync<T1>(_jsonSerializerOptions);
var jsopt = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
return await responseMessage.Content.ReadFromJsonAsync<T1>(jsopt);
}
}
}
10 changes: 10 additions & 0 deletions Jellyfin.Plugin.Simkl/Jellyfin.Plugin.Simkl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<nullable>enable</nullable>
<Version>3.1.0</Version>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<FileVersion>3.1.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,15 +23,22 @@
</ItemGroup>
<ItemGroup>
<None Remove="Configuration\configPage.html" />
<Content Include="favicon.ico" />
<EmbeddedResource Include="Configuration\configPage.html" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
<Copyright></Copyright>
<ApplicationIcon>favicon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="taskkill /f /im &quot;jellyfin.exe&quot;&#xD;&#xA;xcopy &quot;$(TargetPath)&quot; &quot;%25localappdata%25\jellyfin\plugins\Simkl_3.1.0.0\&quot; /y&#xD;&#xA;explorer C:\Program Files\Jellyfin\Server\jellyfin.exe" />
</Target>

</Project>
Binary file added Jellyfin.Plugin.Simkl/favicon.ico
Binary file not shown.

0 comments on commit 906d1ab

Please sign in to comment.