mirror of https://github.com/Radarr/Radarr
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NzbDrone.Core.Languages;
|
|
using NzbDrone.Core.MediaFiles.MovieImport.Manual;
|
|
using NzbDrone.Core.Qualities;
|
|
using Radarr.Api.V3.Movies;
|
|
using Radarr.Http;
|
|
|
|
namespace Radarr.Api.V3.ManualImport
|
|
{
|
|
[V3ApiController]
|
|
public class ManualImportController : Controller
|
|
{
|
|
private readonly IManualImportService _manualImportService;
|
|
|
|
public ManualImportController(IManualImportService manualImportService)
|
|
{
|
|
_manualImportService = manualImportService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<ManualImportResource> GetMediaFiles(string folder, string downloadId, int? movieId, bool filterExistingFiles = true)
|
|
{
|
|
return _manualImportService.GetMediaFiles(folder, downloadId, movieId, filterExistingFiles).ToResource().Select(AddQualityWeight).ToList();
|
|
}
|
|
|
|
[HttpPost]
|
|
public object ReprocessItems([FromBody] List<ManualImportReprocessResource> items)
|
|
{
|
|
foreach (var item in items)
|
|
{
|
|
var processedItem = _manualImportService.ReprocessItem(item.Path, item.DownloadId, item.MovieId, item.Quality, item.Languages);
|
|
|
|
item.Movie = processedItem.Movie.ToResource(0);
|
|
item.Rejections = processedItem.Rejections;
|
|
if (item.Languages.Single() == Language.Unknown)
|
|
{
|
|
item.Languages = processedItem.Languages;
|
|
}
|
|
|
|
if (item.Quality?.Quality == Quality.Unknown)
|
|
{
|
|
item.Quality = processedItem.Quality;
|
|
}
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
private ManualImportResource AddQualityWeight(ManualImportResource item)
|
|
{
|
|
if (item.Quality != null)
|
|
{
|
|
item.QualityWeight = Quality.DefaultQualityDefinitions.Single(q => q.Quality == item.Quality.Quality).Weight;
|
|
item.QualityWeight += item.Quality.Revision.Real * 10;
|
|
item.QualityWeight += item.Quality.Revision.Version;
|
|
}
|
|
|
|
return item;
|
|
}
|
|
}
|
|
}
|