Skip to content

Commit

Permalink
Merge pull request #2655 from tidusjar/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tidusjar authored Nov 23, 2018
2 parents 50bd130 + 05a8846 commit 472ecdb
Show file tree
Hide file tree
Showing 21 changed files with 363 additions and 80 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@

## v3.0.3919 (2018-10-18)

### **New Features**

- Updated the emby api since we no longer need the extra parameters to send to emby to log in a local user #2546. [Jamie]

- Added the ability to get the ombi user via a Plex Token #2591. [Jamie]

### **Fixes**

- Made the subscribe/unsubscribe button more obvious on the UI #2309. [Jamie]

- Fixed #2603. [Jamie]

- Fixed the issue with the user overrides #2646. [Jamie]

- Fixed the issue where we could sometimes allow the request of a whole series when the user shouldn't be able to. [Jamie]

- Fixed the issue where we were marking episodes as available with the Emby connection when they have not yet aired #2417 #2623. [TidusJar]

- Fixed the issue where we were marking the whole season as wanted in Sonarr rather than the individual episode #2629. [TidusJar]

- Fixed #2623. [Jamie]

- Fixed #2633. [TidusJar]

- Fixed #2639. [Jamie]

- Show the TV show as available when we have all the episodes but future episodes have not aired. #2585. [Jamie]


## v3.0.3945 (2018-10-25)

### **New Features**

- Update Readme for Lidarr. [Qstick]

- Update CHANGELOG.md. [Jamie]

### **Fixes**

- New translations en.json (French) [Jamie]
Expand Down
12 changes: 10 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ configuration: Release
os: Visual Studio 2017
environment:
nodejs_version: "9.8.0"
typescript_version: "3.0.1"
typescript_version: "3.0.1"
github_auth_token:
secure: H/7uCrjmWHGJxgN3l9fbhhdVjvvWI8VVF4ZzQqeXuJwAf+PgSNBdxv4SS+rMQ+RH
sonarrcloudtoken:
secure: WGkIog4wuMSx1q5vmSOgIBXMtI/leMpLbZhi9MJnJdBBuDfcv12zwXg3LQwY0WbE

install:
# Get the latest stable version of Node.js or io.js
Expand All @@ -12,10 +16,14 @@ install:
- cmd: set path=%programfiles(x86)%\\Microsoft SDKs\TypeScript\3.0;%path%
- cmd: tsc -v
build_script:
# - dotnet tool install --global dotnet-sonarscanner
#- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { dotnet sonarscanner begin /k:"tidusjar_Ombi" /d:sonar.organization="tidusjar-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="$env.sonarrcloud_token" /d:sonar.analysis.mode="preview" /d:sonar.github.pullRequest="$env:APPVEYOR_PULL_REQUEST_NUMBER" /d:sonar.github.repository="https://github.com/tidusjar/ombi" /d:sonar.github.oauth="$env.github_auth_token" }
# - ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { dotnet sonarscanner begin /k:"tidusjar_Ombi" /d:sonar.organization="tidusjar-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="$env.SONARRCLOUDTOKEN" }
- ps: ./build.ps1 --settings_skipverification=true
# - dotnet sonarscanner end /d:sonar.login="%sonarrcloudtoken%"

test: off

after_build:
- cmd: >-
Expand Down
8 changes: 3 additions & 5 deletions src/Ombi.Api.Emby/EmbyApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public async Task<EmbyUser> LogIn(string username, string password, string apiKe
{
username,
pw = password,
password = password.GetSha1Hash().ToLower(),
passwordMd5 = password.CalcuateMd5Hash()
};

request.AddJsonBody(body);
Expand Down Expand Up @@ -98,7 +96,7 @@ public async Task<EmbyItemContainer<EmbyMovie>> GetCollection(string mediaId, st

request.AddQueryString("Fields", "ProviderIds,Overview");

request.AddQueryString("VirtualItem", "False");
request.AddQueryString("IsVirtualItem", "False");

return await Api.Request<EmbyItemContainer<EmbyMovie>>(request);
}
Expand Down Expand Up @@ -149,7 +147,7 @@ private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, s
request.AddQueryString("IncludeItemTypes", type);
request.AddQueryString("Fields", includeOverview ? "ProviderIds,Overview" : "ProviderIds");

request.AddQueryString("VirtualItem", "False");
request.AddQueryString("IsVirtualItem", "False");

AddHeaders(request, apiKey);

Expand All @@ -167,7 +165,7 @@ private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, s
request.AddQueryString("startIndex", startIndex.ToString());
request.AddQueryString("limit", count.ToString());

request.AddQueryString("VirtualItem", "False");
request.AddQueryString("IsVirtualItem", "False");

AddHeaders(request, apiKey);

Expand Down
17 changes: 17 additions & 0 deletions src/Ombi.Core/Authentication/OmbiUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Ombi.Api.Emby;
Expand Down Expand Up @@ -101,6 +102,22 @@ public async Task<bool> RequiresPassword(OmbiUser user)
return true;
}

public async Task<OmbiUser> GetOmbiUserFromPlexToken(string plexToken)
{
var plexAccount = await _plexApi.GetAccount(plexToken);

// Check for a ombi user
if (plexAccount?.user != null)
{
var potentialOmbiUser = await Users.FirstOrDefaultAsync(x =>
x.ProviderUserId == plexAccount.user.id);
return potentialOmbiUser;
}

return null;
}


/// <summary>
/// Sign the user into plex and make sure we can get the authentication token.
/// <remarks>We do not check if the user is in the owners "friends" since they must have a local user account to get this far</remarks>
Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public async Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
}

// Remove the ID since this is a new child
// This was a TVDBID for the request rules to run
tvBuilder.ChildRequest.Id = 0;
if (!tvBuilder.ChildRequest.SeasonRequests.Any())
{
Expand Down
7 changes: 4 additions & 3 deletions src/Ombi.Core/Helpers/TvShowRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<TvShowRequestBuilder> GetShowInfo(int id)
ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);
Results = await MovieDbApi.SearchTv(ShowInfo.name);
foreach (TvSearchResult result in Results) {
if (result.Name == ShowInfo.name)
if (result.Name.Equals(ShowInfo.name, StringComparison.InvariantCultureIgnoreCase))
{
var showIds = await MovieDbApi.GetTvExternals(result.Id);
ShowInfo.externals.imdb = showIds.imdb_id;
Expand All @@ -64,14 +64,15 @@ public TvShowRequestBuilder CreateChild(TvRequestViewModel model, string userId)
{
ChildRequest = new ChildRequests
{
Id = model.TvDbId,
Id = model.TvDbId, // This is set to 0 after the request rules have run, the request rules needs it to identify the request
RequestType = RequestType.TvShow,
RequestedDate = DateTime.UtcNow,
Approved = false,
RequestedUserId = userId,
SeasonRequests = new List<SeasonRequests>(),
Title = ShowInfo.name,
SeriesType = ShowInfo.genres.Any( s => s.Equals("Anime", StringComparison.OrdinalIgnoreCase)) ? SeriesType.Anime : SeriesType.Standard
ReleaseYear = FirstAir,
SeriesType = ShowInfo.genres.Any( s => s.Equals("Anime", StringComparison.InvariantCultureIgnoreCase)) ? SeriesType.Anime : SeriesType.Standard
};

return this;
Expand Down
82 changes: 82 additions & 0 deletions src/Ombi.Core/Rule/Rules/Request/ExistingPlexRequestRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;

namespace Ombi.Core.Rule.Rules.Request
{
public class ExistingPlexRequestRule : BaseRequestRule, IRules<BaseRequest>
{
public ExistingPlexRequestRule(IPlexContentRepository rv)
{
_plexContent = rv;
}

private readonly IPlexContentRepository _plexContent;

/// <summary>
/// We check if the request exists, if it does then we don't want to re-request it.
/// </summary>
/// <param name="obj">The object.</param>
/// <returns></returns>
public async Task<RuleResult> Execute(BaseRequest obj)
{
if (obj.RequestType == RequestType.TvShow)
{
var tvRequest = (ChildRequests) obj;

var tvContent = _plexContent.GetAll().Where(x => x.Type == PlexMediaTypeEntity.Show);
// We need to do a check on the TVDBId
var anyTvDbMatches = await tvContent.Include(x => x.Episodes).FirstOrDefaultAsync(x => x.HasTvDb && x.TvDbId.Equals(tvRequest.Id.ToString())); // the Id on the child is the tvdbid at this point
if (anyTvDbMatches == null)
{
// So we do not have a TVDB Id, that really sucks.
// Let's try and match on the title and year of the show
var titleAndYearMatch = await tvContent.Include(x=> x.Episodes).FirstOrDefaultAsync(x =>
x.Title.Equals(tvRequest.Title, StringComparison.InvariantCultureIgnoreCase)
&& x.ReleaseYear == tvRequest.ReleaseYear.Year.ToString());
if (titleAndYearMatch != null)
{
// We have a match! Suprise Motherfucker
return CheckExistingContent(tvRequest, titleAndYearMatch);
}

// We do not have this
return Success();
}
// looks like we have a match on the TVDbID
return CheckExistingContent(tvRequest, anyTvDbMatches);
}
return Success();
}


private RuleResult CheckExistingContent(ChildRequests child, PlexServerContent content)
{
foreach (var season in child.SeasonRequests)
{
var currentSeasonRequest =
content.Episodes.Where(x => x.SeasonNumber == season.SeasonNumber).ToList();
if (!currentSeasonRequest.Any())
{
continue;
}
foreach (var e in season.Episodes)
{
var hasEpisode = currentSeasonRequest.Any(x => x.EpisodeNumber == e.EpisodeNumber);
if (hasEpisode)
{
return Fail($"We already have episodes requested from series {child.Title}");
}
}
}

return Success();
}
}
}
57 changes: 57 additions & 0 deletions src/Ombi.Core/Rule/Rules/Request/ExistingTVRequestRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository.Requests;

namespace Ombi.Core.Rule.Rules.Request
{
public class ExistingTvRequestRule : BaseRequestRule, IRules<BaseRequest>
{
public ExistingTvRequestRule(ITvRequestRepository rv)
{
Tv = rv;
}

private ITvRequestRepository Tv { get; }

/// <summary>
/// We check if the request exists, if it does then we don't want to re-request it.
/// </summary>
/// <param name="obj">The object.</param>
/// <returns></returns>
public async Task<RuleResult> Execute(BaseRequest obj)
{
if (obj.RequestType == RequestType.TvShow)
{
var tv = (ChildRequests) obj;
var tvRequests = Tv.GetChild();
var currentRequest = await tvRequests.FirstOrDefaultAsync(x => x.ParentRequest.TvDbId == tv.Id); // the Id on the child is the tvdbid at this point
if (currentRequest == null)
{
return Success();
}
foreach (var season in tv.SeasonRequests)
{
var currentSeasonRequest =
currentRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber);
if (currentSeasonRequest == null)
{
continue;
}
foreach (var e in season.Episodes)
{
var hasEpisode = currentSeasonRequest.Episodes.Any(x => x.EpisodeNumber == e.EpisodeNumber);
if (hasEpisode)
{
return Fail($"We already have episodes requested from series {tv.Title}");
}
}
}
}
return Success();
}
}
}
18 changes: 17 additions & 1 deletion src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Models.Search;
Expand Down Expand Up @@ -104,6 +105,21 @@ public async Task<RuleResult> Execute(SearchViewModel obj)
{
search.FullyAvailable = true;
}
else
{
var airedButNotAvailable = search.SeasonRequests.Any(x =>
x.Episodes.Any(c => !c.Available && c.AirDate <= DateTime.Now.Date));
if (!airedButNotAvailable)
{
var unairedEpisodes = search.SeasonRequests.Any(x =>
x.Episodes.Any(c => !c.Available && c.AirDate > DateTime.Now.Date));
if (unairedEpisodes)
{
search.FullyAvailable = true;
}
}

}
}
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/Ombi.Core/Senders/MovieSender.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -101,13 +102,17 @@ private async Task<SenderResult> SendToRadarr(MovieRequests model, RadarrSetting
var profiles = await _userProfiles.GetAll().FirstOrDefaultAsync(x => x.UserId == model.RequestedUserId);
if (profiles != null)
{
if (profiles.SonarrRootPathAnime > 0)
{
rootFolderPath = await RadarrRootPath(profiles.SonarrRootPathAnime, settings);
if (profiles.RadarrRootPath > 0)
{
var tempPath = await RadarrRootPath(profiles.RadarrRootPath, settings);
if (tempPath.HasValue())
{
rootFolderPath = tempPath;
}
}
if (profiles.SonarrQualityProfileAnime > 0)
if (profiles.RadarrQualityProfile > 0)
{
qualityToUse = profiles.SonarrQualityProfileAnime;
qualityToUse = profiles.RadarrQualityProfile;
}
}

Expand Down Expand Up @@ -163,7 +168,7 @@ private async Task<string> RadarrRootPath(int overrideId, RadarrSettings setting
{
var paths = await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);
return selectedPath.path;
return selectedPath?.path ?? String.Empty;
}
}
}
2 changes: 1 addition & 1 deletion src/Ombi.Core/Senders/TvSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private static List<Season> GetSeasonsToCreate(ChildRequests model)
var sea = new Season
{
seasonNumber = i,
monitored = model.SeasonRequests.Any(x => x.SeasonNumber == index && x.SeasonNumber != 0)
monitored = false
};
seasonsToUpdate.Add(sea);
}
Expand Down
Loading

0 comments on commit 472ecdb

Please sign in to comment.