Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,6 @@ MALClient.Desktop/BundleArtifacts/
MALClient.Dekstop/BundleArtifacts/
MALClient.Android/Resources/Resource.Designer.cs
MALClient.XShared/Secrets.cs

# Ignore Nuget file that contains credentials
nuget.config
2 changes: 1 addition & 1 deletion MALClient.Models/MALClient.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JikanDotNet" Version="2.6.3" />
<PackageReference Include="JikanDotNet" Version="[2.10.4-gatewayerrorfix]" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>
48 changes: 26 additions & 22 deletions MALClient.XShared/Comm/Anime/AnimeGeneralDetailsQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
using System;
using Android.Runtime;
using JikanDotNet;
using MALClient.Models.Enums;
using MALClient.Models.Models.Anime;
using MALClient.XShared.Comm.Manga;
using MALClient.XShared.JsonModels.MAL;
using MALClient.XShared.Utils;
using MALClient.XShared.ViewModels;
using System.Text.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand All @@ -7,14 +16,7 @@
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Android.Runtime;
using JikanDotNet;
using MALClient.Models.Enums;
using MALClient.Models.Models.Anime;
using MALClient.XShared.Comm.Manga;
using MALClient.XShared.Utils;
using MALClient.XShared.ViewModels;
using Newtonsoft.Json;
using static System.Net.WebRequestMethods;

namespace MALClient.XShared.Comm.Anime
{
Expand All @@ -29,6 +31,7 @@ public async Task<AnimeGeneralDetailsData> GetAnimeDetails(bool force, string id

var requestedApiType = apiOverride ?? CurrentApiType;
var response = string.Empty;
var client = await ResourceLocator.MalHttpContextProvider.GetApiHttpContextAsync();
var jikan = JikanClient.Jikan;
try
{
Expand All @@ -38,23 +41,24 @@ public async Task<AnimeGeneralDetailsData> GetAnimeDetails(bool force, string id

if (animeMode)
{
var resultRequest = await jikan.GetAnimeAsync(long.Parse(id));
var result = resultRequest.Data;
var apiUrl = $"https://api.myanimelist.net/v2/anime/{id}?fields=num_episodes,status,media_type,alternative_titles,start_date,end_date,main_picture,pictures,mean,id,synopsis,title";
var result = JsonSerializer.Deserialize<AnimeEntry>(
await client.GetStringAsync(apiUrl));
output = new AnimeGeneralDetailsData
{
AllEpisodes = result.Episodes ?? 0,
Status = result.Status,
Type = result.Type,
AlternateTitle = result.TitleJapanese,
StartDate = result.Aired.From?.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) ?? "N/A",
EndDate = result.Aired.To?.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) ?? "N/A",
ImgUrl = result.Images.JPG.ImageUrl,
AllEpisodes = (int)(result.Episodes ?? 0),
Status = string.Join(" ", result.Status.Split('_').Select(word => char.ToUpper(word[0]) + word.Substring(1).ToLower())),
Type = result.Type.ToUpper(),
AlternateTitle = result.AlternativeTitle.Japanese,
StartDate = result.StartDate ?? "N/A",
EndDate = result.EndDate ?? "N/A",
ImgUrl = result.Picture.Medium,
GlobalScore = (float) (result.Score ?? 0),
Id = (int)result.MalId,
MalId = (int)result.MalId,
Synopsis = WebUtility.HtmlDecode(result.Synopsis),
Title = WebUtility.HtmlDecode(result.Title),
Synonyms = result.TitleSynonyms?.ToList() ?? new List<string>(),
Synopsis = result.Synopsis,
Title = result.Title,
Synonyms = result.AlternativeTitle.Synonyms?.ToList() ?? new List<string>(),
};

if ((output.Type == "Movie" || output.AllEpisodes == 1) && output.EndDate == "N/A" &&
Expand All @@ -64,7 +68,7 @@ public async Task<AnimeGeneralDetailsData> GetAnimeDetails(bool force, string id
}

ResourceLocator.EnglishTitlesProvider.AddOrUpdate(int.Parse(id), true,
result.TitleEnglish);
result.AlternativeTitle.English);
}
else
{
Expand Down
64 changes: 34 additions & 30 deletions MALClient.XShared/Comm/Anime/AnimeSeasonalQuery.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using System;
using HtmlAgilityPack;
using JikanDotNet;
using JikanDotNet.Config;
using MALClient.Models.Models.Anime;
using MALClient.Models.Models.AnimeScrapped;
using MALClient.XShared.JsonModels.MAL;
using MALClient.XShared.Utils;
using MALClient.XShared.ViewModels;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using HtmlAgilityPack;
using JikanDotNet;
using JikanDotNet.Config;
using MALClient.Models.Models.Anime;
using MALClient.Models.Models.AnimeScrapped;
using MALClient.XShared.Utils;
using VideoLibrary;

namespace MALClient.XShared.Comm.Anime
{
Expand All @@ -31,8 +36,7 @@ public async Task<List<SeasonalAnimeData>> GetSeasonalAnime(bool force = false)
//current season without suffix
if (output.Count != 0) return output;

using var client = new HttpClient();
int currentPage = 1;
var client = await ResourceLocator.MalHttpContextProvider.GetApiHttpContextAsync();
try
{
while (true)
Expand All @@ -48,39 +52,39 @@ public async Task<List<SeasonalAnimeData>> GetSeasonalAnime(bool force = false)
true => _season.Season,
false => DateTime.UtcNow.Month switch
{
> 0 and <= 3 => Season.Winter,
> 3 and <= 6 => Season.Spring,
> 6 and <= 9 => Season.Summer,
> 0 and <= 12 => Season.Fall
> 0 and <= 3 => JikanDotNet.Season.Winter,
> 3 and <= 6 => JikanDotNet.Season.Spring,
> 6 and <= 9 => JikanDotNet.Season.Summer,
> 0 and <= 12 => JikanDotNet.Season.Fall
}
};

try
{
var season = JsonSerializer.Deserialize<PaginatedJikanResponse<ICollection<JikanDotNet.Anime>>>(
await client.GetStringAsync(
$"https://api.jikan.moe/v4/seasons/{requestedYear}/{requestedSeason}?page={currentPage}"));
var apiUrl = $"https://api.myanimelist.net/v2/anime/season/{requestedYear}/{requestedSeason.ToString().ToLower()}?limit=500&nsfw=true&fields=id,title,main_picture,num_episodes,mean,genres,num_list_users,start_season";
var season = JsonSerializer.Deserialize<PaginatedMALResponse<ICollection<AnimeNode<SeasonEntry>>>>(
await client.GetStringAsync(apiUrl));
var orderedData = season.Data.OrderBy(seasonEntry =>
((seasonEntry.Node.StartSeason.Name == requestedSeason.ToString().ToLower()
& seasonEntry.Node.StartSeason.Year == requestedYear) ? 100000000 : 0)
+ seasonEntry.Node.MembersCount)
.Reverse();

foreach (var seasonSeasonEntry in season.Data)
foreach (var seasonSeasonEntry in orderedData)
{
output.Add(new SeasonalAnimeData
{
Title = seasonSeasonEntry.Title,
Id = (int)(seasonSeasonEntry.MalId ?? -1),
ImgUrl = seasonSeasonEntry.Images.JPG.ImageUrl,
Episodes = (seasonSeasonEntry.Episodes ?? 0).ToString(),
Score = (float)(seasonSeasonEntry.Score ?? 0),
Genres = seasonSeasonEntry.Genres.Select(item => item.Name).ToList(),
Index = season.Data.FindIndex(seasonSeasonEntry) + (25 * (currentPage - 1)) + 1
Title = seasonSeasonEntry.Node.Title,
Id = (int)(seasonSeasonEntry.Node.MalId ?? -1),
ImgUrl = seasonSeasonEntry.Node.Picture.Medium,
Episodes = (seasonSeasonEntry.Node.Episodes ?? 0).ToString(),
Score = (float)(seasonSeasonEntry.Node.Score ?? 0),
Genres = (seasonSeasonEntry.Node.Genres ?? new List<JsonModels.MAL.Genre>()).Select(item => item.Name).ToList(),
Index = orderedData.FindIndex(seasonSeasonEntry)
});
}

if (!season.Pagination.HasNextPage)
break;

await Task.Delay(TimeSpan.FromMilliseconds(500));

currentPage++;
break;
}
catch (HttpRequestException e)
{
Expand Down
19 changes: 19 additions & 0 deletions MALClient.XShared/JsonModels/MAL/AlternativeTitles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class AlternativeTitles
{
[JsonPropertyName("synonyms")]
public ICollection<String> Synonyms { get; set; }

[JsonPropertyName("en")]
public string English { get; set; }

[JsonPropertyName("ja")]
public string Japanese { get; set; }
}
}
52 changes: 52 additions & 0 deletions MALClient.XShared/JsonModels/MAL/AnimeEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class AnimeEntry
{
[JsonPropertyName("id")]
public long? MalId { get; set; }

[JsonPropertyName("title")]
public string Title { get; set; }

[JsonPropertyName("main_picture")]
public MainPicture Picture { get; set; }

[JsonPropertyName("num_episodes")]
public long? Episodes { get; set; }

[JsonPropertyName("mean")]
public double? Score { get; set; }

[JsonPropertyName("genres")]
public ICollection<Genre> Genres { get; set; }

[JsonPropertyName("num_list_users")]
public long? MembersCount { get; set; }

[JsonPropertyName("start_season")]
public Season StartSeason { get; set; }

[JsonPropertyName("status")]
public string Status { get; set; }

[JsonPropertyName("media_type")]
public string Type { get; set; }

[JsonPropertyName("alternative_titles")]
public AlternativeTitles AlternativeTitle { get; set; }

[JsonPropertyName("start_date")]
public string StartDate { get; set; }

[JsonPropertyName("end_date")]
public string EndDate { get; set; }

[JsonPropertyName("synopsis")]
public string Synopsis { get; set; }
}
}
13 changes: 13 additions & 0 deletions MALClient.XShared/JsonModels/MAL/AnimeNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class AnimeNode<TResponse>
{
[JsonPropertyName("node")]
public TResponse Node { get; set; }
}
}
16 changes: 16 additions & 0 deletions MALClient.XShared/JsonModels/MAL/Genre.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class Genre
{
[JsonPropertyName("id")]
public long? Id { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }
}
}
13 changes: 13 additions & 0 deletions MALClient.XShared/JsonModels/MAL/PaginatedMALResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class PaginatedMALResponse<TResponse>
{
[JsonPropertyName("data")]
public TResponse Data { get; set; }
}
}
16 changes: 16 additions & 0 deletions MALClient.XShared/JsonModels/MAL/Picture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class MainPicture
{
[JsonPropertyName("medium")]
public String Medium { get; set; }

[JsonPropertyName("large")]
public String Large { get; set; }
}
}
16 changes: 16 additions & 0 deletions MALClient.XShared/JsonModels/MAL/Season.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace MALClient.XShared.JsonModels.MAL
{
internal class Season
{
[JsonPropertyName("year")]
public long? Year { get; set; }

[JsonPropertyName("season")]
public string Name { get; set; }
}
}
11 changes: 11 additions & 0 deletions MALClient.XShared/JsonModels/MAL/SeasonEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Text.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Text;

namespace MALClient.XShared.JsonModels.MAL
{
internal class SeasonEntry : AnimeEntry
{
}
}
2 changes: 1 addition & 1 deletion MALClient.XShared/MALClient.XShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.28" />
<PackageReference Include="JikanDotNet" Version="2.6.3" />
<PackageReference Include="JikanDotNet" Version="[2.10.4-gatewayerrorfix]" />
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
### Compilation
You should be able to compile this thing out of the box, you may have to generate certificate for UWP though.
There's also "Secrets.cs" file with some configs... you will have to make it yourself.
Furthermore, you should copy `nuget.config.template` to `nuget.config` and edit the Username and the GitHub Personal Access Token (classic, scope: read:packages) in `nuget.config` to retrieve the correct JikanDotNet fork package that works around some entries not loading. Should be removed after [the MR](https://github.com/Ervie/jikan.net/pull/69) gets merged and new version is published.
### Code
Spaghetti landfill.
Well... there's a metric ton of legacy thingies especially in navigation and pages that were made in the beggining like anime list or anime details. I'm not proud of these but I'm not planning to rewrite them. Stuff that has been added later on is nicer and somewhat decently organised. I started this app when I knew nothing so yeah, works but code is smelly.
Expand Down
Loading