mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-19 21:46:43 -04:00
Add v5 rename endpoints
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using Sonarr.Http;
|
||||||
|
using Sonarr.Http.REST;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V3.Episodes
|
||||||
|
{
|
||||||
|
[V3ApiController("rename")]
|
||||||
|
public class RenameEpisodeController : Controller
|
||||||
|
{
|
||||||
|
private readonly IRenameEpisodeFileService _renameEpisodeFileService;
|
||||||
|
|
||||||
|
public RenameEpisodeController(IRenameEpisodeFileService renameEpisodeFileService)
|
||||||
|
{
|
||||||
|
_renameEpisodeFileService = renameEpisodeFileService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public List<RenameEpisodeResource> GetEpisodes(int seriesId, int? seasonNumber)
|
||||||
|
{
|
||||||
|
if (seasonNumber.HasValue)
|
||||||
|
{
|
||||||
|
return _renameEpisodeFileService.GetRenamePreviews(seriesId, seasonNumber.Value).ToResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _renameEpisodeFileService.GetRenamePreviews(seriesId).ToResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("bulk")]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public List<RenameEpisodeResource> GetEpisodes([FromQuery] List<int> seriesIds)
|
||||||
|
{
|
||||||
|
if (seriesIds is { Count: 0 })
|
||||||
|
{
|
||||||
|
throw new BadRequestException("seriesIds must be provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seriesIds.Any(seriesId => seriesId <= 0))
|
||||||
|
{
|
||||||
|
throw new BadRequestException("seriesIds must be positive integers");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _renameEpisodeFileService.GetRenamePreviews(seriesIds).ToResource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Sonarr.Http.REST;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V3.Episodes
|
||||||
|
{
|
||||||
|
public class RenameEpisodeResource : RestResource
|
||||||
|
{
|
||||||
|
public int SeriesId { get; set; }
|
||||||
|
public int SeasonNumber { get; set; }
|
||||||
|
public List<int> EpisodeNumbers { get; set; }
|
||||||
|
public int EpisodeFileId { get; set; }
|
||||||
|
public string ExistingPath { get; set; }
|
||||||
|
public string NewPath { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RenameEpisodeResourceMapper
|
||||||
|
{
|
||||||
|
public static RenameEpisodeResource ToResource(this NzbDrone.Core.MediaFiles.RenameEpisodeFilePreview model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RenameEpisodeResource
|
||||||
|
{
|
||||||
|
Id = model.EpisodeFileId,
|
||||||
|
SeriesId = model.SeriesId,
|
||||||
|
SeasonNumber = model.SeasonNumber,
|
||||||
|
EpisodeNumbers = model.EpisodeNumbers.ToList(),
|
||||||
|
EpisodeFileId = model.EpisodeFileId,
|
||||||
|
ExistingPath = model.ExistingPath,
|
||||||
|
NewPath = model.NewPath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RenameEpisodeResource> ToResource(this IEnumerable<NzbDrone.Core.MediaFiles.RenameEpisodeFilePreview> models)
|
||||||
|
{
|
||||||
|
return models.Select(ToResource).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user