Skip to content

Commit

Permalink
Merge pull request #95 from PythonCoderAS/patch-1
Browse files Browse the repository at this point in the history
Add NSFW param to MAL API calls
  • Loading branch information
vosmiic committed Jan 16, 2024
2 parents 7a8109d + 1e62e04 commit 4e1f46c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Api/Anilist/AniListApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public AniListApiCalls(IHttpClientFactory httpClientFactory, ILoggerFactory logg
synonyms
episodes
status
isAdult
}
}
}
Expand Down Expand Up @@ -108,6 +109,7 @@ public AniListApiCalls(IHttpClientFactory httpClientFactory, ILoggerFactory logg
Media(id: $id) {
id
episodes
isAdult
title {
romaji
english
Expand Down
7 changes: 5 additions & 2 deletions Api/Mal/MalApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task<User> GetUserInformation() {
/// <param name="query">Search by title.</param>
/// <param name="fields">The fields you would like returned.</param>
/// <returns>List of anime.</returns>
public async Task<List<Anime>> SearchAnime(string? query, string[]? fields) {
public async Task<List<Anime>> SearchAnime(string? query, string[]? fields, bool updateNsfw = false) {
UrlBuilder url = new UrlBuilder {
Base = $"{ApiUrl}/anime"
};
Expand All @@ -78,6 +78,9 @@ public async Task<List<Anime>> SearchAnime(string? query, string[]? fields) {
}

url.Parameters.Add(new KeyValuePair<string, string>("q", query));
if (updateNsfw) {
url.Parameters.Add(new KeyValuePair<string, string>("nsfw", "true"));
}
}

if (fields != null) {
Expand Down Expand Up @@ -250,4 +253,4 @@ public async Task<UpdateAnimeStatusResponse> UpdateAnimeStatus(int animeId, int
return updateResponse;
}
}
}
}
6 changes: 6 additions & 0 deletions Configuration/ConfigPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
your server crashing after ticking media as being completed please disable this option.</b>
</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="UpdateNsfw" name="UpdateNsfw" type="checkbox" is="emby-checkbox"/>
<span>Allow updating NSFW anime?</span>
</label>
</div>
<div class="selectContainer">
<select is="emby-select" id="selectProvider" name="selectProvider" label="Provider"></select>
</div>
Expand Down
3 changes: 3 additions & 0 deletions Configuration/ConfigPageJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ async function initialLoad() {
page.querySelector('#shikimoriAppName').value = config.shikimoriAppName;
if (config.simklUpdateAll)
page.querySelector('#simklUpdateAll').checked = config.simklUpdateAll;
if (config.updateNsfw)
page.querySelector('#UpdateNsfw').checked = config.updateNsfw;

page.querySelector('#clientSecretLabel').style.display = "block";
page.querySelector('#clientSecret').style.display = "block";
Expand Down Expand Up @@ -369,6 +371,7 @@ async function initialLoad() {
config.callbackRedirectUrl = document.querySelector('#callbackRedirectUrlInput').value;
config.shikimoriAppName = document.querySelector('#shikimoriAppName').value;
config.simklUpdateAll = document.querySelector('#simklUpdateAll').checked;
config.updateNsfw = document.querySelector('#UpdateNsfw').checked;

userConfig.LibraryToCheck = Array.prototype.map.call(document.querySelectorAll('.library:checked'), element => {
return element.getAttribute('id');
Expand Down
5 changes: 5 additions & 0 deletions Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@ public PluginConfiguration() {
/// True to update all simkl series episodes to current point.
/// </summary>
public bool simklUpdateAll { get; set; }

/// <summary>
/// True to update NSFW anime.
/// </summary>
public bool updateNsfw { get; set; }
}
}
4 changes: 3 additions & 1 deletion Helpers/ApiCallHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ public ApiCallHelpers(MalApiCalls malApiCalls = null,
}

public async Task<List<Anime>> SearchAnime(string query) {
bool updateNsfw = Plugin.Instance?.PluginConfiguration?.updateNsfw != null && Plugin.Instance.PluginConfiguration.updateNsfw;
if (_malApiCalls != null) {
return await _malApiCalls.SearchAnime(query, new[] { "id", "title", "alternative_titles", "num_episodes", "status" });
return await _malApiCalls.SearchAnime(query, new[] { "id", "title", "alternative_titles", "num_episodes", "status" }, updateNsfw);
}

if (_aniListApiCalls != null) {
List<AniListSearch.Media> animeList = await _aniListApiCalls.SearchAnime(query);
List<Anime> convertedList = new List<Anime>();
if (animeList != null) {
foreach (AniListSearch.Media media in animeList) {
if (!updateNsfw && media.IsAdult) continue; // Skip NSFW anime if the user doesn't want to update them
var synonyms = new List<string> {
{ media.Title.Romaji },
{ media.Title.UserPreferred }
Expand Down
2 changes: 2 additions & 0 deletions Models/AniList/AniListSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class Media {

[JsonPropertyName("siteUrl")]
public string SiteUrl { get; set; }

[JsonPropertyName("isAdult")] public bool IsAdult { get; set; }
}

public class Page {
Expand Down

0 comments on commit 4e1f46c

Please sign in to comment.