mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-17 21:26:22 -04:00
Compare commits
2 Commits
collection
...
v5.0.3.812
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d46bd2d8f | ||
|
|
017f272201 |
@@ -12,7 +12,7 @@ namespace NzbDrone.Common.Instrumentation
|
|||||||
{
|
{
|
||||||
public static class NzbDroneLogger
|
public static class NzbDroneLogger
|
||||||
{
|
{
|
||||||
private const string FILE_LOG_LAYOUT = @"${date:format=yyyy-MM-dd HH\:mm\:ss.fff}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}${exception:format=Data}${newline}}";
|
private const string FILE_LOG_LAYOUT = @"${date:format=yyyy-MM-dd HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}${exception:format=Data}${newline}}";
|
||||||
|
|
||||||
private static bool _isConfigured;
|
private static bool _isConfigured;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Languages;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Movies.Translations;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Movies
|
namespace NzbDrone.Core.Movies
|
||||||
{
|
{
|
||||||
@@ -45,37 +43,7 @@ namespace NzbDrone.Core.Movies
|
|||||||
|
|
||||||
public List<MovieMetadata> GetMoviesWithCollections()
|
public List<MovieMetadata> GetMoviesWithCollections()
|
||||||
{
|
{
|
||||||
var movieDictionary = new Dictionary<int, MovieMetadata>();
|
return Query(x => x.CollectionTmdbId > 0);
|
||||||
|
|
||||||
var builder = new SqlBuilder(_database.DatabaseType)
|
|
||||||
.LeftJoin<MovieMetadata, MovieTranslation>((mm, t) => mm.Id == t.MovieMetadataId)
|
|
||||||
.Where<MovieMetadata>(x => x.CollectionTmdbId > 0);
|
|
||||||
|
|
||||||
_ = _database.QueryJoined<MovieMetadata, MovieTranslation>(
|
|
||||||
builder,
|
|
||||||
(metadata, translation) =>
|
|
||||||
{
|
|
||||||
if (!movieDictionary.TryGetValue(metadata.Id, out var movieEntry))
|
|
||||||
{
|
|
||||||
movieEntry = metadata;
|
|
||||||
movieDictionary.Add(movieEntry.Id, movieEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (translation != null)
|
|
||||||
{
|
|
||||||
movieEntry.Translations.Add(translation);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Add a translation to avoid filename builder making another call thinking translations are not loaded
|
|
||||||
// Optimize this later by pulling translations with metadata always
|
|
||||||
movieEntry.Translations.Add(new MovieTranslation { Title = movieEntry.Title, Language = Language.English });
|
|
||||||
}
|
|
||||||
|
|
||||||
return movieEntry;
|
|
||||||
});
|
|
||||||
|
|
||||||
return movieDictionary.Values.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MovieMetadata> GetMoviesByCollectionTmdbId(int collectionId)
|
public List<MovieMetadata> GetMoviesByCollectionTmdbId(int collectionId)
|
||||||
|
|||||||
@@ -50,17 +50,17 @@ namespace NzbDrone.Core.Notifications.Notifiarr
|
|||||||
switch ((int)responseCode)
|
switch ((int)responseCode)
|
||||||
{
|
{
|
||||||
case 401:
|
case 401:
|
||||||
_logger.Error("HTTP 401 - API key is invalid");
|
_logger.Warn("HTTP 401 - API key is invalid");
|
||||||
throw new NotifiarrException("API key is invalid");
|
throw new NotifiarrException("API key is invalid");
|
||||||
case 400:
|
case 400:
|
||||||
// 400 responses shouldn't be treated as an actual error because it's a misconfiguration
|
// 400 responses shouldn't be treated as an actual error because it's a misconfiguration
|
||||||
// between Radarr and Notifiarr for a specific event, but shouldn't stop all events.
|
// between Radarr and Notifiarr for a specific event, but shouldn't stop all events.
|
||||||
_logger.Error("HTTP 400 - Unable to send notification. Ensure Radarr Integration is enabled & assigned a channel on Notifiarr");
|
_logger.Warn("HTTP 400 - Unable to send notification. Ensure Radarr Integration is enabled & assigned a channel on Notifiarr");
|
||||||
break;
|
break;
|
||||||
case 502:
|
case 502:
|
||||||
case 503:
|
case 503:
|
||||||
case 504:
|
case 504:
|
||||||
_logger.Error("Unable to send notification. Service Unavailable");
|
_logger.Warn("Unable to send notification. Service Unavailable");
|
||||||
throw new NotifiarrException("Unable to send notification. Service Unavailable", ex);
|
throw new NotifiarrException("Unable to send notification. Service Unavailable", ex);
|
||||||
case 520:
|
case 520:
|
||||||
case 521:
|
case 521:
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Datastore.Events;
|
using NzbDrone.Core.Datastore.Events;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Movies;
|
using NzbDrone.Core.Movies;
|
||||||
using NzbDrone.Core.Movies.Collections;
|
using NzbDrone.Core.Movies.Collections;
|
||||||
using NzbDrone.Core.Movies.Commands;
|
using NzbDrone.Core.Movies.Commands;
|
||||||
using NzbDrone.Core.Movies.Events;
|
using NzbDrone.Core.Movies.Events;
|
||||||
|
using NzbDrone.Core.Movies.Translations;
|
||||||
using NzbDrone.Core.Organizer;
|
using NzbDrone.Core.Organizer;
|
||||||
using NzbDrone.SignalR;
|
using NzbDrone.SignalR;
|
||||||
using Radarr.Http;
|
using Radarr.Http;
|
||||||
@@ -27,28 +29,31 @@ namespace Radarr.Api.V3.Collections
|
|||||||
private readonly IMovieCollectionService _collectionService;
|
private readonly IMovieCollectionService _collectionService;
|
||||||
private readonly IMovieService _movieService;
|
private readonly IMovieService _movieService;
|
||||||
private readonly IMovieMetadataService _movieMetadataService;
|
private readonly IMovieMetadataService _movieMetadataService;
|
||||||
|
private readonly IMovieTranslationService _movieTranslationService;
|
||||||
|
private readonly IConfigService _configService;
|
||||||
private readonly IBuildFileNames _fileNameBuilder;
|
private readonly IBuildFileNames _fileNameBuilder;
|
||||||
private readonly INamingConfigService _namingService;
|
private readonly INamingConfigService _namingService;
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
private readonly Logger _logger;
|
|
||||||
|
|
||||||
public CollectionController(IBroadcastSignalRMessage signalRBroadcaster,
|
public CollectionController(IBroadcastSignalRMessage signalRBroadcaster,
|
||||||
IMovieCollectionService collectionService,
|
IMovieCollectionService collectionService,
|
||||||
IMovieService movieService,
|
IMovieService movieService,
|
||||||
IMovieMetadataService movieMetadataService,
|
IMovieMetadataService movieMetadataService,
|
||||||
|
IMovieTranslationService movieTranslationService,
|
||||||
|
IConfigService configService,
|
||||||
IBuildFileNames fileNameBuilder,
|
IBuildFileNames fileNameBuilder,
|
||||||
INamingConfigService namingService,
|
INamingConfigService namingService,
|
||||||
IManageCommandQueue commandQueueManager,
|
IManageCommandQueue commandQueueManager)
|
||||||
Logger logger)
|
|
||||||
: base(signalRBroadcaster)
|
: base(signalRBroadcaster)
|
||||||
{
|
{
|
||||||
_collectionService = collectionService;
|
_collectionService = collectionService;
|
||||||
_movieService = movieService;
|
_movieService = movieService;
|
||||||
_movieMetadataService = movieMetadataService;
|
_movieMetadataService = movieMetadataService;
|
||||||
|
_movieTranslationService = movieTranslationService;
|
||||||
|
_configService = configService;
|
||||||
_fileNameBuilder = fileNameBuilder;
|
_fileNameBuilder = fileNameBuilder;
|
||||||
_namingService = namingService;
|
_namingService = namingService;
|
||||||
_commandQueueManager = commandQueueManager;
|
_commandQueueManager = commandQueueManager;
|
||||||
_logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override CollectionResource GetResourceById(int id)
|
protected override CollectionResource GetResourceById(int id)
|
||||||
@@ -75,8 +80,6 @@ namespace Radarr.Api.V3.Collections
|
|||||||
collectionResources = MapToResource(_collectionService.GetAllCollections()).ToList();
|
collectionResources = MapToResource(_collectionService.GetAllCollections()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Trace("Returning Collections");
|
|
||||||
|
|
||||||
return collectionResources;
|
return collectionResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,16 +143,27 @@ namespace Radarr.Api.V3.Collections
|
|||||||
{
|
{
|
||||||
// Avoid calling for naming spec on every movie in filenamebuilder
|
// Avoid calling for naming spec on every movie in filenamebuilder
|
||||||
var namingConfig = _namingService.GetConfig();
|
var namingConfig = _namingService.GetConfig();
|
||||||
var collectionMovies = _movieMetadataService.GetMoviesWithCollections();
|
|
||||||
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
|
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
|
||||||
|
var configLanguage = (Language)_configService.MovieInfoLanguage;
|
||||||
|
|
||||||
|
var allCollectionMovies = _movieMetadataService.GetMoviesWithCollections()
|
||||||
|
.GroupBy(x => x.CollectionTmdbId)
|
||||||
|
.ToDictionary(x => x.Key, x => (IEnumerable<MovieMetadata>)x);
|
||||||
|
|
||||||
|
var translations = _movieTranslationService.GetAllTranslationsForLanguage(configLanguage);
|
||||||
|
var tdict = translations.ToDictionary(x => x.MovieMetadataId);
|
||||||
|
|
||||||
foreach (var collection in collections)
|
foreach (var collection in collections)
|
||||||
{
|
{
|
||||||
var resource = collection.ToResource();
|
var resource = collection.ToResource();
|
||||||
|
|
||||||
foreach (var movie in collectionMovies.Where(m => m.CollectionTmdbId == collection.TmdbId))
|
allCollectionMovies.TryGetValue(collection.TmdbId, out var collectionMovies);
|
||||||
|
|
||||||
|
foreach (var movie in collectionMovies)
|
||||||
{
|
{
|
||||||
var movieResource = movie.ToResource();
|
var translation = GetTranslationFromDict(tdict, movie, configLanguage);
|
||||||
|
|
||||||
|
var movieResource = movie.ToResource(translation);
|
||||||
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig);
|
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig);
|
||||||
|
|
||||||
if (!existingMoviesTmdbIds.Contains(movie.TmdbId))
|
if (!existingMoviesTmdbIds.Contains(movie.TmdbId))
|
||||||
@@ -169,10 +183,14 @@ namespace Radarr.Api.V3.Collections
|
|||||||
var resource = collection.ToResource();
|
var resource = collection.ToResource();
|
||||||
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
|
var existingMoviesTmdbIds = _movieService.AllMovieWithCollectionsTmdbIds();
|
||||||
var namingConfig = _namingService.GetConfig();
|
var namingConfig = _namingService.GetConfig();
|
||||||
|
var configLanguage = (Language)_configService.MovieInfoLanguage;
|
||||||
|
|
||||||
foreach (var movie in _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId))
|
foreach (var movie in _movieMetadataService.GetMoviesByCollectionTmdbId(collection.TmdbId))
|
||||||
{
|
{
|
||||||
var movieResource = movie.ToResource();
|
var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.Id);
|
||||||
|
var translation = GetMovieTranslation(translations, movie, configLanguage);
|
||||||
|
|
||||||
|
var movieResource = movie.ToResource(translation);
|
||||||
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig);
|
movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig);
|
||||||
|
|
||||||
if (!existingMoviesTmdbIds.Contains(movie.TmdbId))
|
if (!existingMoviesTmdbIds.Contains(movie.TmdbId))
|
||||||
@@ -186,6 +204,54 @@ namespace Radarr.Api.V3.Collections
|
|||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MovieTranslation GetMovieTranslation(List<MovieTranslation> translations, MovieMetadata movieMetadata, Language configLanguage)
|
||||||
|
{
|
||||||
|
if (configLanguage == Language.Original)
|
||||||
|
{
|
||||||
|
return new MovieTranslation
|
||||||
|
{
|
||||||
|
Title = movieMetadata.OriginalTitle,
|
||||||
|
Overview = movieMetadata.Overview
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var translation = translations.FirstOrDefault(t => t.Language == configLanguage && t.MovieMetadataId == movieMetadata.Id);
|
||||||
|
|
||||||
|
if (translation == null)
|
||||||
|
{
|
||||||
|
translation = new MovieTranslation
|
||||||
|
{
|
||||||
|
Title = movieMetadata.Title,
|
||||||
|
Language = Language.English
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MovieTranslation GetTranslationFromDict(Dictionary<int, MovieTranslation> translations, MovieMetadata movieMetadata, Language configLanguage)
|
||||||
|
{
|
||||||
|
if (configLanguage == Language.Original)
|
||||||
|
{
|
||||||
|
return new MovieTranslation
|
||||||
|
{
|
||||||
|
Title = movieMetadata.OriginalTitle,
|
||||||
|
Overview = movieMetadata.Overview
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!translations.TryGetValue(movieMetadata.Id, out var translation))
|
||||||
|
{
|
||||||
|
translation = new MovieTranslation
|
||||||
|
{
|
||||||
|
Title = movieMetadata.Title,
|
||||||
|
Language = Language.English
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return translation;
|
||||||
|
}
|
||||||
|
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public void Handle(CollectionAddedEvent message)
|
public void Handle(CollectionAddedEvent message)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NzbDrone.Core.MediaCover;
|
using NzbDrone.Core.MediaCover;
|
||||||
using NzbDrone.Core.Movies;
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Movies.Translations;
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Collections
|
namespace Radarr.Api.V3.Collections
|
||||||
{
|
{
|
||||||
@@ -22,18 +23,21 @@ namespace Radarr.Api.V3.Collections
|
|||||||
|
|
||||||
public static class CollectionMovieResourceMapper
|
public static class CollectionMovieResourceMapper
|
||||||
{
|
{
|
||||||
public static CollectionMovieResource ToResource(this MovieMetadata model)
|
public static CollectionMovieResource ToResource(this MovieMetadata model, MovieTranslation movieTranslation = null)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var translatedTitle = movieTranslation?.Title ?? model.Title;
|
||||||
|
var translatedOverview = movieTranslation?.Overview ?? model.Overview;
|
||||||
|
|
||||||
return new CollectionMovieResource
|
return new CollectionMovieResource
|
||||||
{
|
{
|
||||||
TmdbId = model.TmdbId,
|
TmdbId = model.TmdbId,
|
||||||
Title = model.Title,
|
Title = translatedTitle,
|
||||||
Overview = model.Overview,
|
Overview = translatedOverview,
|
||||||
SortTitle = model.SortTitle,
|
SortTitle = model.SortTitle,
|
||||||
Images = model.Images,
|
Images = model.Images,
|
||||||
ImdbId = model.ImdbId,
|
ImdbId = model.ImdbId,
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace Radarr.Api.V3.ImportLists
|
|||||||
private readonly IImportExclusionsService _importExclusionService;
|
private readonly IImportExclusionsService _importExclusionService;
|
||||||
private readonly INamingConfigService _namingService;
|
private readonly INamingConfigService _namingService;
|
||||||
private readonly IMovieTranslationService _movieTranslationService;
|
private readonly IMovieTranslationService _movieTranslationService;
|
||||||
private readonly IMapCoversToLocal _coverMapper;
|
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
|
|
||||||
public ImportListMoviesController(IMovieService movieService,
|
public ImportListMoviesController(IMovieService movieService,
|
||||||
@@ -40,7 +39,6 @@ namespace Radarr.Api.V3.ImportLists
|
|||||||
IImportExclusionsService importExclusionsService,
|
IImportExclusionsService importExclusionsService,
|
||||||
INamingConfigService namingService,
|
INamingConfigService namingService,
|
||||||
IMovieTranslationService movieTranslationService,
|
IMovieTranslationService movieTranslationService,
|
||||||
IMapCoversToLocal coverMapper,
|
|
||||||
IConfigService configService)
|
IConfigService configService)
|
||||||
{
|
{
|
||||||
_movieService = movieService;
|
_movieService = movieService;
|
||||||
@@ -52,7 +50,6 @@ namespace Radarr.Api.V3.ImportLists
|
|||||||
_importExclusionService = importExclusionsService;
|
_importExclusionService = importExclusionsService;
|
||||||
_namingService = namingService;
|
_namingService = namingService;
|
||||||
_movieTranslationService = movieTranslationService;
|
_movieTranslationService = movieTranslationService;
|
||||||
_coverMapper = coverMapper;
|
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +115,6 @@ namespace Radarr.Api.V3.ImportLists
|
|||||||
foreach (var currentMovie in movies)
|
foreach (var currentMovie in movies)
|
||||||
{
|
{
|
||||||
var resource = currentMovie.ToResource();
|
var resource = currentMovie.ToResource();
|
||||||
_coverMapper.ConvertToLocalUrls(0, resource.Images);
|
|
||||||
|
|
||||||
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
|
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
|
||||||
if (poster != null)
|
if (poster != null)
|
||||||
@@ -148,7 +144,6 @@ namespace Radarr.Api.V3.ImportLists
|
|||||||
foreach (var currentMovie in movies)
|
foreach (var currentMovie in movies)
|
||||||
{
|
{
|
||||||
var resource = currentMovie.ToResource();
|
var resource = currentMovie.ToResource();
|
||||||
_coverMapper.ConvertToLocalUrls(0, resource.Images);
|
|
||||||
|
|
||||||
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
|
var poster = currentMovie.MovieMetadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
|
||||||
if (poster != null)
|
if (poster != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user