From 1458fd75349b2e910844dddc72824ab9a90460f6 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 8 Sep 2020 16:35:21 -0600 Subject: [PATCH] simkl only likes snake_case --- Jellyfin.Plugin.Simkl/API/Objects/Account.cs | 18 --------- .../API/Objects/Connections.cs | 13 ------- Jellyfin.Plugin.Simkl/API/Objects/Season.cs | 4 +- .../API/Objects/ShowEpisode.cs | 2 +- .../API/Objects/SimklEpisode.cs | 10 ++--- .../API/Objects/SimklFile.cs | 6 +-- .../API/Objects/SimklHistory.cs | 12 +++--- Jellyfin.Plugin.Simkl/API/Objects/SimklIds.cs | 33 +++++++++++------ .../API/Objects/SimklMediaObject.cs | 2 +- .../API/Objects/SimklMovie.cs | 16 ++++---- .../API/Objects/SimklMovieIds.cs | 12 +++--- .../API/Objects/SimklShow.cs | 22 +++++------ .../API/Objects/SimklShowIds.cs | 12 +++--- Jellyfin.Plugin.Simkl/API/Objects/User.cs | 37 +------------------ .../API/Objects/UserSettings.cs | 9 +---- Jellyfin.Plugin.Simkl/API/SimklApi.cs | 32 ++++++++-------- .../Configuration/configPage.html | 2 +- .../Jellyfin.Plugin.Simkl.csproj | 2 +- 18 files changed, 93 insertions(+), 151 deletions(-) delete mode 100644 Jellyfin.Plugin.Simkl/API/Objects/Account.cs delete mode 100644 Jellyfin.Plugin.Simkl/API/Objects/Connections.cs diff --git a/Jellyfin.Plugin.Simkl/API/Objects/Account.cs b/Jellyfin.Plugin.Simkl/API/Objects/Account.cs deleted file mode 100644 index ee6502d..0000000 --- a/Jellyfin.Plugin.Simkl/API/Objects/Account.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Jellyfin.Plugin.Simkl.API.Objects -{ - /// - /// Account. - /// - public class Account - { - /// - /// Gets or sets account id. - /// - public int Id { get; set; } - - /// - /// Gets or sets timezone. - /// - public string Timezone { get; set; } - } -} \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/Connections.cs b/Jellyfin.Plugin.Simkl/API/Objects/Connections.cs deleted file mode 100644 index b111558..0000000 --- a/Jellyfin.Plugin.Simkl/API/Objects/Connections.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Jellyfin.Plugin.Simkl.API.Objects -{ - /// - /// Connections. - /// - public class Connections - { - /// - /// Gets or sets a value indicating whether facebook. - /// - public bool Facebook { get; set; } - } -} \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/Season.cs b/Jellyfin.Plugin.Simkl/API/Objects/Season.cs index cd52654..1fcbe84 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/Season.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/Season.cs @@ -8,11 +8,11 @@ /// /// Gets or sets the season number. /// - public int? Number { get; set; } + public int? number { get; set; } /// /// Gets or sets the episodes. /// - public ShowEpisode[] Episodes { get; set; } + public ShowEpisode[] episodes { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/ShowEpisode.cs b/Jellyfin.Plugin.Simkl/API/Objects/ShowEpisode.cs index 5bb7879..ccb6811 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/ShowEpisode.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/ShowEpisode.cs @@ -8,7 +8,7 @@ /// /// Gets or sets episode number. /// - public int? Number { get; set; } + public int? number { get; set; } // TODO: watched_at } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs index b4a44b4..76d35a3 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs @@ -17,26 +17,26 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets ids. /// - public override SimklIds Ids { get; set; } + public override SimklIds ids { get; set; } /// /// Gets or sets the title. /// - public string Title { get; set; } + public string title { get; set; } /// /// Gets or sets the season. /// - public int Season { get; set; } + public int season { get; set; } /// /// Gets or sets the episode. /// - public int Episode { get; set; } + public int episode { get; set; } /// /// Gets or sets multipart. /// - public bool? Multipart { get; set; } + public bool? multipart { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklFile.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklFile.cs index 389e97d..f4ee5ef 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklFile.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklFile.cs @@ -8,16 +8,16 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets the file. /// - public string File { get; set; } + public string file { get; set; } /// /// Gets or sets the part. /// - public int? Part { get; set; } + public int? part { get; set; } /// /// Gets or sets the hash. /// - public string Hash { get; set; } + public string hash { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklHistory.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklHistory.cs index eebbc4e..af87d9f 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklHistory.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklHistory.cs @@ -14,24 +14,24 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// public SimklHistory() { - Movies = new List(); - Shows = new List(); - Episodes = new List(); + movies = new List(); + shows = new List(); + episodes = new List(); } /// /// Gets or sets list of movies. /// - public List Movies { get; set; } + public List movies { get; set; } /// /// Gets or sets the list of shows. /// - public List Shows { get; set; } + public List shows { get; set; } /// /// Gets or sets the list of episodes. /// - public List Episodes { get; set; } + public List episodes { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklIds.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklIds.cs index e9b0e8b..5190e87 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklIds.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklIds.cs @@ -1,6 +1,6 @@ +using System; using System.Collections.Generic; using System.Globalization; -using System.Reflection; namespace Jellyfin.Plugin.Simkl.API.Objects { @@ -17,14 +17,25 @@ namespace Jellyfin.Plugin.Simkl.API.Objects { foreach (var (key, value) in providerIds) { - var prop = GetType().GetProperty(key, BindingFlags.IgnoreCase); - if (prop.PropertyType == typeof(int?)) + if (key.Equals(nameof(simkl), StringComparison.OrdinalIgnoreCase)) { - prop.SetValue(this, int.Parse(value, NumberStyles.Any, CultureInfo.InvariantCulture)); + simkl = Convert.ToInt32(value, CultureInfo.InvariantCulture); } - else if (prop.PropertyType == typeof(string)) + else if (key.Equals(nameof(imdb), StringComparison.OrdinalIgnoreCase)) { - prop.SetValue(this, value); + imdb = value; + } + else if (key.Equals(nameof(slug), StringComparison.OrdinalIgnoreCase)) + { + slug = value; + } + else if (key.Equals(nameof(netflix), StringComparison.OrdinalIgnoreCase)) + { + netflix = value; + } + else if (key.Equals(nameof(tmdb), StringComparison.OrdinalIgnoreCase)) + { + tmdb = value; } } } @@ -32,26 +43,26 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets simkl. /// - public int? Simkl { get; set; } + public int? simkl { get; set; } /// /// Gets or sets the imdb id. /// - public string Imdb { get; set; } + public string imdb { get; set; } /// /// Gets or sets the slug. /// - public string Slug { get; set; } + public string slug { get; set; } /// /// Gets or sets the netflix id. /// - public string Netflix { get; set; } + public string netflix { get; set; } /// /// Gets or sets the TMDb id. /// - public string Tmdb { get; set; } + public string tmdb { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklMediaObject.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklMediaObject.cs index a7e3195..70a9d90 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklMediaObject.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklMediaObject.cs @@ -8,6 +8,6 @@ /// /// Gets or sets ids. /// - public abstract SimklIds Ids { get; set; } + public abstract SimklIds ids { get; set; } } } diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklMovie.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklMovie.cs index d7fa1eb..36cc90a 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklMovie.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklMovie.cs @@ -15,28 +15,28 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// The base item dto. public SimklMovie(BaseItemDto item) { - Title = item.OriginalTitle; - Year = item.ProductionYear; - Ids = new SimklMovieIds(item.ProviderIds); - WatchedAt = DateTime.UtcNow.ToString("yyyy-MM-dd HH\\:mm\\:ss", CultureInfo.InvariantCulture); + title = item.OriginalTitle; + year = item.ProductionYear; + ids = new SimklMovieIds(item.ProviderIds); + watched_at = DateTime.UtcNow.ToString("yyyy-MM-dd HH\\:mm\\:ss", CultureInfo.InvariantCulture); } /// /// Gets or sets the movie title. /// - public string Title { get; set; } + public string title { get; set; } /// /// Gets or sets the year. /// - public int? Year { get; set; } + public int? year { get; set; } /// - public override SimklIds Ids { get; set; } + public override SimklIds ids { get; set; } /// /// Gets watched at. /// - public string WatchedAt { get; } + public string watched_at { get; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklMovieIds.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklMovieIds.cs index ed82bbe..5c5fa9c 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklMovieIds.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklMovieIds.cs @@ -19,31 +19,31 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets the tvdb id. /// - public int? Tvdb { get; set; } + public int? tvdb { get; set; } /// /// Gets or sets the mal id. /// - public int? Mal { get; set; } + public int? mal { get; set; } /// /// Gets or sets the anidb id. /// - public int? Anidb { get; set; } + public int? anidb { get; set; } /// /// Gets or sets the hulu id. /// - public int? Hulu { get; set; } + public int? hulu { get; set; } /// /// Gets or sets the crunchyroll id. /// - public int? Crunchyroll { get; set; } + public int? crunchyroll { get; set; } /// /// Gets or sets the movie db id. /// - public string Moviedb { get; set; } + public string moviedb { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklShow.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklShow.cs index ad8cb7a..840f94d 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklShow.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklShow.cs @@ -13,19 +13,19 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// The media info. public SimklShow(BaseItemDto mediaInfo) { - Title = mediaInfo.SeriesName; - Ids = new SimklShowIds(mediaInfo.ProviderIds); - Year = mediaInfo.ProductionYear; - Seasons = new Season[] + title = mediaInfo.SeriesName; + ids = new SimklShowIds(mediaInfo.ProviderIds); + year = mediaInfo.ProductionYear; + seasons = new[] { new Season { - Number = mediaInfo.ParentIndexNumber, - Episodes = new[] + number = mediaInfo.ParentIndexNumber, + episodes = new[] { new ShowEpisode { - Number = mediaInfo.IndexNumber + number = mediaInfo.IndexNumber } } } @@ -35,21 +35,21 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets title. /// - public string Title { get; set; } + public string title { get; set; } /// /// Gets or sets year. /// - public int? Year { get; set; } + public int? year { get; set; } /// /// Gets or sets seasons. /// - public Season[] Seasons { get; set; } + public Season[] seasons { get; set; } /// /// Gets or sets ids. /// - public override SimklIds Ids { get; set; } + public override SimklIds ids { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklShowIds.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklShowIds.cs index 31c6da3..6635a24 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklShowIds.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklShowIds.cs @@ -19,31 +19,31 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets tvdb. /// - public int? Tvdb { get; set; } + public int? tvdb { get; set; } /// /// Gets or sets mal. /// - public int? Mal { get; set; } + public int? mal { get; set; } /// /// Gets or sets anidb. /// - public int? Anidb { get; set; } + public int? anidb { get; set; } /// /// Gets or sets hulu. /// - public int? Hulu { get; set; } + public int? hulu { get; set; } /// /// Gets or sets crunchyroll. /// - public int? Crunchyroll { get; set; } + public int? crunchyroll { get; set; } /// /// Gets or sets zap2it. /// - public string Zap2It { get; set; } + public string zap2It { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/User.cs b/Jellyfin.Plugin.Simkl/API/Objects/User.cs index 1094b14..06a5efb 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/User.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/User.cs @@ -1,6 +1,4 @@ -using System; -using System.Text.Json.Serialization; -#pragma warning disable SA1300 +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API.Objects { @@ -12,37 +10,6 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// /// Gets or sets name. /// - public string Name { get; set; } - - /// - /// Gets or sets joined at. - /// - [JsonPropertyName("joined_at")] - public DateTime joined_at { get; set; } - - /// - /// Gets or sets gender. - /// - public string Gender { get; set; } - - /// - /// Gets or sets avatar. - /// - public string Avatar { get; set; } - - /// - /// Gets or sets bio. - /// - public string Bio { get; set; } - - /// - /// Gets or sets loc. - /// - public string Loc { get; set; } - - /// - /// Gets or sets age. - /// - public string Age { get; set; } + public string name { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/UserSettings.cs b/Jellyfin.Plugin.Simkl/API/Objects/UserSettings.cs index 166a6d1..ec29200 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/UserSettings.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/UserSettings.cs @@ -8,16 +8,11 @@ /// /// Gets or sets user. /// - public User User { get; set; } - - /// - /// Gets or sets account. - /// - public Account Account { get; set; } + public User user { get; set; } /// /// Gets or sets error. /// - public string Error { get; set; } + public string error { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/SimklApi.cs b/Jellyfin.Plugin.Simkl/API/SimklApi.cs index 74710ab..5b491d5 100644 --- a/Jellyfin.Plugin.Simkl/API/SimklApi.cs +++ b/Jellyfin.Plugin.Simkl/API/SimklApi.cs @@ -93,7 +93,7 @@ namespace Jellyfin.Plugin.Simkl.API // Wontfix: Custom status codes // "You don't get to pick your response code" - Luke (System Architect of Emby) // https://emby.media/community/index.php?/topic/61889-wiki-issue-resultfactorythrowerror/ - return new UserSettings { Error = "user_token_failed" }; + return new UserSettings { error = "user_token_failed" }; } } @@ -108,7 +108,7 @@ namespace Jellyfin.Plugin.Simkl.API var history = CreateHistoryFromItem(item); var r = await SyncHistoryAsync(history, userToken).ConfigureAwait(false); _logger.LogDebug("Response: " + _json.SerializeToString(r)); - if (history.Movies.Count == r.Added.Movies && history.Shows.Count == r.Added.Shows) + if (history.movies.Count == r.Added.Movies && history.shows.Count == r.Added.Shows) { return (true, item); } @@ -129,7 +129,7 @@ namespace Jellyfin.Plugin.Simkl.API r = await SyncHistoryAsync(history, userToken).ConfigureAwait(false); _logger.LogDebug("Response: " + _json.SerializeToString(r)); - return (history.Movies.Count == r.Added.Movies && history.Shows.Count == r.Added.Shows, item); + return (history.movies.Count == r.Added.Movies && history.shows.Count == r.Added.Shows, item); } /// @@ -139,10 +139,10 @@ namespace Jellyfin.Plugin.Simkl.API /// Search file response. private async Task GetFromFile(string filename) { - var f = new SimklFile { File = filename }; + var f = new SimklFile { file = filename }; _logger.LogInformation("Posting: " + _json.SerializeToString(f)); using var r = new StreamReader(await Post("/search/file/", null, f).ConfigureAwait(false)); - var t = r.ReadToEnd(); + var t = await r.ReadToEndAsync().ConfigureAwait(false); _logger.LogDebug("Response: " + t); return _json.DeserializeFromString(t); } @@ -166,9 +166,9 @@ namespace Jellyfin.Plugin.Simkl.API throw new InvalidDataException("type != movie (" + mo.Type + ")"); } - item.Name = mo.Movie.Title; - item.ProductionYear = mo.Movie.Year; - history.Movies.Add(mo.Movie); + item.Name = mo.Movie.title; + item.ProductionYear = mo.Movie.year; + history.movies.Add(mo.Movie); } else if (item.IsSeries == true || item.Type == "Episode") { @@ -177,12 +177,12 @@ namespace Jellyfin.Plugin.Simkl.API throw new InvalidDataException("type != episode (" + mo.Type + ")"); } - item.Name = mo.Episode.Title; - item.SeriesName = mo.Show.Title; - item.IndexNumber = mo.Episode.Episode; - item.ParentIndexNumber = mo.Episode.Season; - item.ProductionYear = mo.Show.Year; - history.Episodes.Add(mo.Episode); + item.Name = mo.Episode.title; + item.SeriesName = mo.Show.title; + item.IndexNumber = mo.Episode.episode; + item.ParentIndexNumber = mo.Episode.season; + item.ProductionYear = mo.Show.year; + history.episodes.Add(mo.Episode); } return (history, item); @@ -212,12 +212,12 @@ namespace Jellyfin.Plugin.Simkl.API if (item.IsMovie == true || item.Type == "Movie") { - history.Movies.Add(new SimklMovie(item)); + history.movies.Add(new SimklMovie(item)); } else if (item.IsSeries == true || item.Type == "Episode") { // TODO: TV Shows scrobbling (WIP) - history.Shows.Add(new SimklShow(item)); + history.shows.Add(new SimklShow(item)); } return history; diff --git a/Jellyfin.Plugin.Simkl/Configuration/configPage.html b/Jellyfin.Plugin.Simkl/Configuration/configPage.html index c4df61f..9880408 100644 --- a/Jellyfin.Plugin.Simkl/Configuration/configPage.html +++ b/Jellyfin.Plugin.Simkl/Configuration/configPage.html @@ -101,7 +101,7 @@ ApiClient.updatePluginConfiguration(this.guid, this.configCache).then(Dashboard.processPluginConfigurationUpdateResult); }, populateOptionsContainer : async function(userConfig) { - $("#simklName").html(SimklAPI.getUserSettings(userConfig.Id).User.Name); + $("#simklName").html(SimklAPI.getUserSettings(userConfig.Id).user.name); for (var key in userConfig) { console.log(key, userConfig[key]); diff --git a/Jellyfin.Plugin.Simkl/Jellyfin.Plugin.Simkl.csproj b/Jellyfin.Plugin.Simkl/Jellyfin.Plugin.Simkl.csproj index 3ad2262..580728e 100644 --- a/Jellyfin.Plugin.Simkl/Jellyfin.Plugin.Simkl.csproj +++ b/Jellyfin.Plugin.Simkl/Jellyfin.Plugin.Simkl.csproj @@ -6,7 +6,7 @@ 1.0.0.0 true true - CA1707;CA1819 + CA1707;CA1819;SA1300