Skip to content

Commit

Permalink
Merge pull request Ombi-app#2277 from tidusjar/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tidusjar authored May 26, 2018
2 parents 2b81471 + f60fbcc commit cf4d0ac
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 32 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## (unreleased)

### **New Features**

- Added a default set of root folders and qualities for Anime in Sonarr. [Jamie Rees]

### **Fixes**

- Fixed #2243 The refresh metadata was being run everytime we launched Ombi... [Jamie]

- Fixed a issue where the Plex Content Sync wouldn't pick up new shows #2276 #2244 #2261. [Jamie]

- Sort TvRequests by latest request. [Joe Harvey]

- Fixed build. [Jamie Rees]

- Fix newsletter card background overflow when only one item is available. [Anojh]

- Fix #1745. [Anojh]


## v3.0.3330 (2018-05-17)

### **New Features**
Expand Down
8 changes: 6 additions & 2 deletions src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public async Task<IEnumerable<TvRequests>> GetRequests(int count, int position)
.Include(x => x.ChildRequests)
.ThenInclude(x => x.SeasonRequests)
.ThenInclude(x => x.Episodes)
.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
.OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
.Skip(position).Take(count).ToListAsync();

// Filter out children

Expand All @@ -154,7 +155,8 @@ public async Task<IEnumerable<TvRequests>> GetRequests(int count, int position)
.Include(x => x.ChildRequests)
.ThenInclude(x => x.SeasonRequests)
.ThenInclude(x => x.Episodes)
.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
.OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
.Skip(position).Take(count).ToListAsync();
}

allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
Expand All @@ -172,6 +174,7 @@ public async Task<IEnumerable<TreeNode<TvRequests, List<ChildRequests>>>> GetReq
.Include(x => x.ChildRequests)
.ThenInclude(x => x.SeasonRequests)
.ThenInclude(x => x.Episodes)
.OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
.Skip(position).Take(count).ToListAsync();

FilterChildren(allRequests, shouldHide);
Expand All @@ -182,6 +185,7 @@ public async Task<IEnumerable<TreeNode<TvRequests, List<ChildRequests>>>> GetReq
.Include(x => x.ChildRequests)
.ThenInclude(x => x.SeasonRequests)
.ThenInclude(x => x.Episodes)
.OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
.Skip(position).Take(count).ToListAsync();
}

Expand Down
30 changes: 22 additions & 8 deletions src/Ombi.Core/Senders/TvSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,31 @@ public async Task<NewSeries> SendToSonarr(ChildRequests model)
return null;
}

int.TryParse(s.QualityProfile, out var qualityToUse);
int qualityToUse;
string rootFolderPath;

if (model.SeriesType == SeriesType.Anime)
{
// Get the root path from the rootfolder selected.
// For some reason, if we haven't got one use the first root folder in Sonarr
// TODO make this overrideable via the UI
rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder ?? int.Parse(s.RootPathAnime), s);
int.TryParse(s.QualityProfileAnime, out qualityToUse);
}
else
{
int.TryParse(s.QualityProfile, out qualityToUse);
// Get the root path from the rootfolder selected.
// For some reason, if we haven't got one use the first root folder in Sonarr
// TODO make this overrideable via the UI
rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder ?? int.Parse(s.RootPath), s);
}

if (model.ParentRequest.QualityOverride.HasValue)
{
qualityToUse = model.ParentRequest.QualityOverride.Value;
}

// Get the root path from the rootfolder selected.
// For some reason, if we haven't got one use the first root folder in Sonarr
// TODO make this overrideable via the UI
var rootFolderPath = await GetSonarrRootPath(model.ParentRequest.RootFolder ?? int.Parse(s.RootPath), s);

try
{
// Does the series actually exist?
Expand Down Expand Up @@ -160,13 +174,13 @@ public async Task<NewSeries> SendToSonarr(ChildRequests model)
// Montitor the correct seasons,
// If we have that season in the model then it's monitored!
var seasonsToAdd = new List<Season>();
for (var i = 1; i < model.ParentRequest.TotalSeasons + 1; i++)
for (var i = 0; i < model.ParentRequest.TotalSeasons + 1; i++)
{
var index = i;
var season = new Season
{
seasonNumber = i,
monitored = model.SeasonRequests.Any(x => x.SeasonNumber == index)
monitored = model.SeasonRequests.Any(x => x.SeasonNumber == index && x.SeasonNumber != 0)
};
seasonsToAdd.Add(season);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Ombi.Schedule/JobSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public void Setup()
RecurringJob.AddOrUpdate(() => _embyUserImporter.Start(), JobSettingsHelper.UserImporter(s));
RecurringJob.AddOrUpdate(() => _plexUserImporter.Start(), JobSettingsHelper.UserImporter(s));
RecurringJob.AddOrUpdate(() => _newsletter.Start(), JobSettingsHelper.Newsletter(s));

BackgroundJob.Enqueue(() => _refreshMetadata.Start());
}


Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Schedule/Jobs/Ombi/HtmlTemplateGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class HtmlTemplateGenerator
protected virtual void AddBackgroundInsideTable(StringBuilder sb, string url)
{
sb.Append("<td align=\"center\" valign=\"top\" class=\"media-card\" style=\"font-family: 'Open Sans', Helvetica, Arial, sans-serif; font-size: 12px; vertical-align: top; padding: 3px; width: 502px; min-width: 500px; max-width: 500px; height: 235px; \">");
sb.AppendFormat("<table class=\"card-bg\" style=\"background-image: url({0}); border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background-color: #1f1f1f; background-position: center; background-size: cover; background-repeat: no-repeat; background-clip: padding-box; border: 2px solid rgba(255,118,27,.4); height: 248px; max-height: 500px; \">", url);
sb.AppendFormat("<table class=\"card-bg\" style=\"background-image: url({0}); border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 500px; background-color: #1f1f1f; background-position: center; background-size: cover; background-repeat: no-repeat; background-clip: padding-box; border: 2px solid rgba(255,118,27,.4); height: 248px; max-height: 500px; \">", url);
sb.Append("<tr>");
sb.Append("<td>");
sb.Append("<table class=\"bg-tint\" style=\"background-color: rgba(0, 0, 0, .6); position: absolute; width: 490px; height: 239px; \">");
Expand Down
60 changes: 44 additions & 16 deletions src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private async Task<IEnumerable<int>> StartTheCache(PlexSettings plexSettings, bo
{
try
{
Logger.LogInformation("Starting to cache the content on server {0}", servers.Name);
Logger.LogInformation("Starting to cache the content on server {0}", servers.Name);

if (recentlyAddedSearch)
{
Expand Down Expand Up @@ -162,8 +162,10 @@ private async Task<IEnumerable<int>> ProcessServer(PlexServers servers, bool rec
if (content.viewGroup.Equals(PlexMediaType.Episode.ToString(), StringComparison.CurrentCultureIgnoreCase))
{
Logger.LogInformation("Found some episodes, this must be a recently added sync");
var count = 0;
foreach (var epInfo in content.Metadata)
{
count++;
var grandParentKey = epInfo.grandparentRatingKey;
// Lookup the rating key
var showMetadata = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri, grandParentKey);
Expand All @@ -174,18 +176,59 @@ private async Task<IEnumerable<int>> ProcessServer(PlexServers servers, bool rec
}

await ProcessTvShow(servers, show, contentToAdd, recentlyAddedSearch, processedContent);
if (contentToAdd.Any())
{
await Repo.AddRange(contentToAdd, false);
if (recentlyAddedSearch)
{
foreach (var plexServerContent in contentToAdd)
{
processedContent.Add(plexServerContent.Id);
}
}
contentToAdd.Clear();
}
if (count > 200)
{
await Repo.SaveChangesAsync();

}
}

// Save just to make sure we don't leave anything hanging
await Repo.SaveChangesAsync();

await EpisodeSync.ProcessEpsiodes(content.Metadata, allEps);
}
if (content.viewGroup.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase))
{
// Process Shows
Logger.LogInformation("Processing TV Shows");
var count = 0;
foreach (var show in content.Metadata ?? new Metadata[] { })
{
count++;
await ProcessTvShow(servers, show, contentToAdd, recentlyAddedSearch, processedContent);

if (contentToAdd.Any())
{
await Repo.AddRange(contentToAdd, false);
if (recentlyAddedSearch)
{
foreach (var plexServerContent in contentToAdd)
{
processedContent.Add(plexServerContent.Id);
}
}
contentToAdd.Clear();
}
if (count > 200)
{
await Repo.SaveChangesAsync();
}
}

await Repo.SaveChangesAsync();
}
if (content.viewGroup.Equals(PlexMediaType.Movie.ToString(), StringComparison.CurrentCultureIgnoreCase))
{
Expand Down Expand Up @@ -464,21 +507,6 @@ private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet<Ple
show.title);
}
}

if (contentToAdd.Count > 500 || recentlyAdded)
{
await Repo.AddRange(contentToAdd);
foreach (var plexServerContent in contentToAdd)
{
contentProcessed.Add(plexServerContent.Id);
}
contentToAdd.Clear();
}

if (contentToAdd.Any())
{
await Repo.AddRange(contentToAdd);
}
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Ombi.Settings/Settings/Models/External/SonarrSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class SonarrSettings : ExternalSettings
/// The root path.
/// </value>
public string RootPath { get; set; }


public string QualityProfileAnime { get; set; }
public string RootPathAnime { get; set; }
public bool AddOnly { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Ombi.Store/Repository/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IRepository<T> : IDisposable where T : Entity
Task<T> Find(object key);
IQueryable<T> GetAll();
Task<T> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate);
Task AddRange(IEnumerable<T> content);
Task AddRange(IEnumerable<T> content, bool save = true);
Task<T> Add(T content);
Task DeleteRange(IEnumerable<T> req);
Task Delete(T request);
Expand Down
7 changes: 5 additions & 2 deletions src/Ombi.Store/Repository/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ public async Task<T> FirstOrDefaultAsync(Expression<Func<T,bool>> predicate)
return await _db.FirstOrDefaultAsync(predicate);
}

public async Task AddRange(IEnumerable<T> content)
public async Task AddRange(IEnumerable<T> content, bool save = true)
{
_db.AddRange(content);
await _ctx.SaveChangesAsync();
if (save)
{
await _ctx.SaveChangesAsync();
}
}

public async Task<T> Add(T content)
Expand Down
2 changes: 2 additions & 0 deletions src/Ombi/ClientApp/app/interfaces/ISettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export interface ISonarrSettings extends IExternalSettings {
apiKey: string;
enabled: boolean;
qualityProfile: string;
qualityProfileAnime: string;
seasonFolders: boolean;
rootPath: string;
rootPathAnime: string;
fullRootPath: string;
addOnly: boolean;
}
Expand Down
17 changes: 17 additions & 0 deletions src/Ombi/ClientApp/app/settings/sonarr/sonarr.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
<small *ngIf="form.get('qualityProfile').hasError('required')" class="error-text">A Default Quality Profile is required</small>

</div>
<div class="form-group">
<label for="select" class="control-label">Quality Profiles (Anime)</label>
<div id="qualityProfileAnime">
<select class="form-control form-control-custom" id="qualityProfileAnime" formControlName="qualityProfileAnime">
<option *ngFor="let quality of qualities" value="{{quality.id}}" >{{quality.name}}</option>
</select>
</div>
</div>

<div class="form-group">
<div>
Expand All @@ -85,6 +93,15 @@
<small *ngIf="form.get('rootPath').hasError('required')" class="error-text">A Default Root Path is required</small>

</div>
<div class="form-group">
<label for="rootFoldersAnime" class="control-label">Default Root Folders (Anime)</label>
<div id="rootFoldersAnime">
<select class="form-control form-control-custom" formControlName="rootPathAnime">
<option *ngFor="let folder of rootFoldersAnime" value="{{folder.id}}">{{folder.path}}</option>
</select>
</div>

</div>


<div class="form-group">
Expand Down
6 changes: 6 additions & 0 deletions src/Ombi/ClientApp/app/settings/sonarr/sonarr.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { SettingsService } from "../../services";
export class SonarrComponent implements OnInit {

public qualities: ISonarrProfile[];
public qualitiesAnime: ISonarrProfile[];
public rootFolders: ISonarrRootFolder[];
public rootFoldersAnime: ISonarrRootFolder[];
public selectedRootFolder: ISonarrRootFolder;
public selectedQuality: ISonarrProfile;
public profilesRunning: boolean;
Expand All @@ -37,6 +39,8 @@ export class SonarrComponent implements OnInit {
apiKey: [x.apiKey, [Validators.required]],
qualityProfile: [x.qualityProfile, [Validators.required]],
rootPath: [x.rootPath, [Validators.required]],
qualityProfileAnime: [x.qualityProfileAnime],
rootPathAnime: [x.rootPathAnime],
ssl: [x.ssl],
subDir: [x.subDir],
ip: [x.ip, [Validators.required]],
Expand Down Expand Up @@ -64,6 +68,7 @@ export class SonarrComponent implements OnInit {
.subscribe(x => {
this.qualities = x;
this.qualities.unshift({ name: "Please Select", id: -1 });
this.qualitiesAnime = x;

this.profilesRunning = false;
this.notificationService.success("Successfully retrieved the Quality Profiles");
Expand All @@ -76,6 +81,7 @@ export class SonarrComponent implements OnInit {
.subscribe(x => {
this.rootFolders = x;
this.rootFolders.unshift({ path: "Please Select", id: -1 });
this.rootFoldersAnime = x;

this.rootFoldersRunning = false;
this.notificationService.success("Successfully retrieved the Root Folders");
Expand Down

0 comments on commit cf4d0ac

Please sign in to comment.