Skip to content

Commit

Permalink
Merge pull request #2142 from tidusjar/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tidusjar authored Apr 10, 2018
2 parents fde6763 + 7f12ab5 commit bb4ea79
Show file tree
Hide file tree
Showing 58 changed files with 2,919 additions and 633 deletions.
63 changes: 60 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
# Changelog

## (unreleased)

### **New Features**

- Added the ability to send newsletter out to users that are not in Ombi. [Jamie]

- Added the ability to turn off TV or Movies from the newsletter. [Jamie]

- Update about.component.html. [Jamie]

- Update about.component.html. [Jamie]

- Added random versioning prefix to the translations so the users don't have to clear the cache. [Jamie]

- Added more information to the about page. [Jamie]

- Changed let to const to adhere to linting. [Anojh]

- Update _Layout.cshtml. [goldenpipes]

- Update _Layout.cshtml. [goldenpipes]

- Changed the TV Request API. We now only require the TvDbId and the seasons and episodes that you want to request. This should make integration regarding TV a lot easier. [Jamie]

### **Fixes**

- Emby improvments on the way we sync/cache the data. [Jamie]

- Memory improvements. [Jamie]

- Made some improvements to the Sonarr Sync job #2127. [Jamie]

- Turn off Server GC to hopefully help with #2127. [Jamie Rees]

- Fixed #2109. [Jamie]

- Fixed #2101. [Jamie]

- Fixed #2105. [Jamie]

- Fixed some styling on the issues detail page. [Jamie]

- Fixed #2116. [Jamie]

- Limit the amount of FileSystemWatchers being spawned. [Jamie]

- Fixed the issue where Emby connect users could not log in #2115. [Jamie]

- Had to update some base styles since currently some styling does not look right... [Anojh]

- Adding wrappers and classes for LC and toggling active style for UI elements. [Anojh]

- Fixed a little bug in the newsletter. [Jamie]

- Fixed the issue where movies were not appearing in the newsletter for users with Emby #2111. [Jamie]


## v3.0.3111 (2018-03-27)

### **New Features**
Expand Down Expand Up @@ -732,7 +789,7 @@

- Switch to use a single HTTPClient rather than a new one every request !dev. [tidusjar]

- Fix non-admin rights (#1820) [Rob Gökemeijer]
- Fix non-admin rights (#1820) [Rob Gökemeijer]

- Fix duplicated "Requests" element ID on new Issues link (#1817) [Shoghi Cervantes]

Expand Down Expand Up @@ -2582,7 +2639,7 @@

- WIP hide tv request options based on admin settings. [Matt McHughes]

- Set meta charset to be utf-8. [Madeleine Schönemann]
- Set meta charset to be utf-8. [Madeleine Schönemann]

- F#552: updated labels text. [Jim MacKenize]

Expand Down Expand Up @@ -2939,7 +2996,7 @@

- Fixed issues from the merge. [tidusjar]

- Stupid &$(*£ merge. [tidusjar]
- Stupid &$(*£ merge. [tidusjar]

- Angular. [tidusjar]

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 3.0.{build}
configuration: Release
os: Visual Studio 2017
environment:
nodejs_version: "7.8.0"
nodejs_version: "Current"

install:
# Get the latest stable version of Node.js or io.js
Expand Down
10 changes: 8 additions & 2 deletions src/Ombi.Api.Emby/EmbyApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ public async Task<EmbyConnectUser> LoginConnectUser(string username, string pass

request.AddJsonBody(body);

request.AddHeader("Accept", "application/json");
request.AddContentHeader("Content-Type", "application/json");
AddEmbyHeaders(request);

var obj = await Api.Request<EmbyConnectUser>(request);
return obj;
}

private static void AddEmbyHeaders(Request request)
{
request.AddHeader("Accept", "application/json");
request.AddHeader("X-Application", $"Ombi/{AssemblyHelper.GetRuntimeVersion()}");
request.AddContentHeader("Content-Type", "application/json");
}

public async Task<EmbyItemContainer<MovieInformation>> GetCollection(string mediaId, string apiKey, string userId, string baseUrl)
{
var request = new Request($"emby/users/{userId}/items?parentId={mediaId}", baseUrl, HttpMethod.Get);
Expand Down
4 changes: 2 additions & 2 deletions src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Setup()
[Test]
public async Task Movie_ShouldBe_Available_WhenFoundInEmby()
{
ContextMock.Setup(x => x.Get(It.IsAny<string>())).ReturnsAsync(new EmbyContent
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).ReturnsAsync(new EmbyContent
{
ProviderId = "123"
});
Expand All @@ -39,7 +39,7 @@ public async Task Movie_ShouldBe_Available_WhenFoundInEmby()
[Test]
public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInEmby()
{
ContextMock.Setup(x => x.Get(It.IsAny<string>())).Returns(Task.FromResult(default(EmbyContent)));
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).Returns(Task.FromResult(default(EmbyContent)));
var search = new SearchMovieViewModel();
var result = await Rule.Execute(search);

Expand Down
3 changes: 2 additions & 1 deletion src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Store.Entities.Requests;

Expand All @@ -9,7 +10,7 @@ public interface ITvRequestEngine : IRequestEngine<TvRequests>
{

Task RemoveTvRequest(int requestId);
Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv);
Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv);
Task<RequestEngineResult> DenyChildRequest(int requestId);
Task<IEnumerable<TvRequests>> SearchTvRequest(string search);
Task<IEnumerable<TreeNode<TvRequests, List<ChildRequests>>>> SearchTvRequestTree(string search);
Expand Down
8 changes: 6 additions & 2 deletions src/Ombi.Core/Engine/RecentlyAddedEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ private static void TransformEmbyMovies(IQueryable<EmbyContent> embyMovies, Hash
model.Add(new RecentlyAddedMovieModel
{
Id = emby.Id,
ImdbId = emby.ProviderId,
ImdbId = emby.ImdbId,
TheMovieDbId = emby.TheMovieDbId,
TvDbId = emby.TvDbId,
AddedAt = emby.AddedAt,
Title = emby.Title,
});
Expand Down Expand Up @@ -211,7 +213,9 @@ private static void TransformEmbyShows(IQueryable<EmbyContent> embyShows, HashSe
model.Add(new RecentlyAddedTvModel
{
Id = emby.Id,
ImdbId = emby.ProviderId,
ImdbId = emby.ImdbId,
TvDbId = emby.TvDbId,
TheMovieDbId = emby.TheMovieDbId,
AddedAt = emby.AddedAt,
Title = emby.Title,
EpisodeNumber = episode.EpisodeNumber,
Expand Down
10 changes: 5 additions & 5 deletions src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPr
private IAuditRepository Audit { get; }
private readonly IRepository<RequestLog> _requestLog;

public async Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv)
public async Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
{
var user = await GetUser();

var tvBuilder = new TvShowRequestBuilder(TvApi);
(await tvBuilder
.GetShowInfo(tv.Id))
.GetShowInfo(tv.TvDbId))
.CreateTvList(tv)
.CreateChild(tv, user.Id);

Expand Down Expand Up @@ -78,9 +78,9 @@ public async Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv)
}
}

await Audit.Record(AuditType.Added, AuditArea.TvRequest, $"Added Request {tv.Title}", Username);
await Audit.Record(AuditType.Added, AuditArea.TvRequest, $"Added Request {tvBuilder.ChildRequest.Title}", Username);

var existingRequest = await TvRepository.Get().FirstOrDefaultAsync(x => x.TvDbId == tv.Id);
var existingRequest = await TvRepository.Get().FirstOrDefaultAsync(x => x.TvDbId == tv.TvDbId);
if (existingRequest != null)
{
// Remove requests we already have, we just want new ones
Expand Down Expand Up @@ -127,7 +127,7 @@ public async Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv)
var newRequest = tvBuilder.CreateNewRequest(tv);
return await AddRequest(newRequest.NewRequest);
}

public async Task<IEnumerable<TvRequests>> GetRequests(int count, int position)
{
var shouldHide = await HideFromOtherUsers();
Expand Down
80 changes: 57 additions & 23 deletions src/Ombi.Core/Helpers/TvShowRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Ombi.Api.TvMaze;
using Ombi.Api.TvMaze.Models;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Helpers;
using Ombi.Store.Entities;
Expand All @@ -23,7 +24,7 @@ public TvShowRequestBuilder(ITvMazeApi tvApi)
private ITvMazeApi TvApi { get; }

public ChildRequests ChildRequest { get; set; }
public List<SeasonRequests> TvRequests { get; protected set; }
public List<SeasonsViewModel> TvRequests { get; protected set; }
public string PosterPath { get; protected set; }
public DateTime FirstAir { get; protected set; }
public TvRequests NewRequest { get; protected set; }
Expand All @@ -33,7 +34,7 @@ public async Task<TvShowRequestBuilder> GetShowInfo(int id)
{
ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);

DateTime.TryParse(ShowInfo.premiered, out DateTime dt);
DateTime.TryParse(ShowInfo.premiered, out var dt);

FirstAir = dt;

Expand All @@ -43,49 +44,40 @@ public async Task<TvShowRequestBuilder> GetShowInfo(int id)
return this;
}

public TvShowRequestBuilder CreateChild(SearchTvShowViewModel model, string userId)
public TvShowRequestBuilder CreateChild(TvRequestViewModel model, string userId)
{
ChildRequest = new ChildRequests
{
Id = model.Id,
Id = model.TvDbId,
RequestType = RequestType.TvShow,
RequestedDate = DateTime.UtcNow,
Approved = false,
RequestedUserId = userId,
SeasonRequests = new List<SeasonRequests>(),
Title = model.Title,
Title = ShowInfo.name,
SeriesType = ShowInfo.type.Equals("Animation", StringComparison.CurrentCultureIgnoreCase) ? SeriesType.Anime : SeriesType.Standard
};

return this;
}

public TvShowRequestBuilder CreateTvList(SearchTvShowViewModel tv)
public TvShowRequestBuilder CreateTvList(TvRequestViewModel tv)
{
TvRequests = new List<SeasonRequests>();
TvRequests = new List<SeasonsViewModel>();
// Only have the TV requests we actually requested and not everything
foreach (var season in tv.SeasonRequests)
foreach (var season in tv.Seasons)
{
for (int i = season.Episodes.Count - 1; i >= 0; i--)
{
if (!season.Episodes[i].Requested)
{
season.Episodes.RemoveAt(i); // Remove the episode since it's not requested
}
}

if (season.Episodes.Any())
{
TvRequests.Add(season);
}
}

return this;

}


public async Task<TvShowRequestBuilder> BuildEpisodes(SearchTvShowViewModel tv)
public async Task<TvShowRequestBuilder> BuildEpisodes(TvRequestViewModel tv)
{
if (tv.RequestAll)
{
Expand Down Expand Up @@ -173,26 +165,68 @@ public async Task<TvShowRequestBuilder> BuildEpisodes(SearchTvShowViewModel tv)
else
{
// It's a custom request
ChildRequest.SeasonRequests = TvRequests;
var seasonRequests = new List<SeasonRequests>();
var episodes = await TvApi.EpisodeLookup(ShowInfo.id);
foreach (var ep in episodes)
{
var existingSeasonRequest = seasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season);
if (existingSeasonRequest != null)
{
var requestedSeason = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season);
var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.number) ?? false;
if (requestedSeason != null && requestedEpisode)
{
// We already have this, let's just add the episodes to it
existingSeasonRequest.Episodes.Add(new EpisodeRequests
{
EpisodeNumber = ep.number,
AirDate = FormatDate(ep.airdate),
Title = ep.name,
Url = ep.url,
});
}
}
else
{
var newRequest = new SeasonRequests {SeasonNumber = ep.season};
var requestedSeason = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season);
var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.number) ?? false;
if (requestedSeason != null && requestedEpisode)
{
newRequest.Episodes.Add(new EpisodeRequests
{
EpisodeNumber = ep.number,
AirDate = FormatDate(ep.airdate),
Title = ep.name,
Url = ep.url,
});
seasonRequests.Add(newRequest);
}
}
}

foreach (var s in seasonRequests)
{
ChildRequest.SeasonRequests.Add(s);
}
}
return this;
}


public TvShowRequestBuilder CreateNewRequest(SearchTvShowViewModel tv)
public TvShowRequestBuilder CreateNewRequest(TvRequestViewModel tv)
{
NewRequest = new TvRequests
{
Id = tv.Id,
Overview = ShowInfo.summary.RemoveHtml(),
PosterPath = PosterPath,
Title = ShowInfo.name,
ReleaseDate = FirstAir,
Status = ShowInfo.status,
ImdbId = ShowInfo.externals?.imdb ?? string.Empty,
TvDbId = tv.Id,
TvDbId = tv.TvDbId,
ChildRequests = new List<ChildRequests>(),
TotalSeasons = tv.SeasonRequests.Count()
TotalSeasons = tv.Seasons.Count()
};
NewRequest.ChildRequests.Add(ChildRequest);

Expand Down
25 changes: 25 additions & 0 deletions src/Ombi.Core/Models/Requests/TvRequestViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace Ombi.Core.Models.Requests
{
public class TvRequestViewModel
{
public bool RequestAll { get; set; }
public bool LatestSeason { get; set; }
public bool FirstSeason { get; set; }
public int TvDbId { get; set; }
public List<SeasonsViewModel> Seasons { get; set; } = new List<SeasonsViewModel>();
}

public class SeasonsViewModel
{
public int SeasonNumber { get; set; }
public List<EpisodesViewModel> Episodes { get; set; } = new List<EpisodesViewModel>();
}

public class EpisodesViewModel
{
public int EpisodeNumber { get; set; }
}

}
Loading

0 comments on commit bb4ea79

Please sign in to comment.