2017-10-31 01:28:29 +00:00
|
|
|
using Lidarr.Api.V1.Albums;
|
|
|
|
using Lidarr.Api.V1.Artist;
|
2017-09-04 02:20:56 +00:00
|
|
|
using Lidarr.Http;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1.Parse
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
public class ParseModule : LidarrRestModule<ParseResource>
|
|
|
|
{
|
|
|
|
private readonly IParsingService _parsingService;
|
|
|
|
|
|
|
|
public ParseModule(IParsingService parsingService)
|
|
|
|
{
|
|
|
|
_parsingService = parsingService;
|
|
|
|
|
|
|
|
GetResourceSingle = Parse;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ParseResource Parse()
|
|
|
|
{
|
|
|
|
var title = Request.Query.Title.Value as string;
|
2019-03-10 02:19:10 +00:00
|
|
|
var parsedAlbumInfo = Parser.ParseAlbumTitle(title);
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2019-03-10 02:19:10 +00:00
|
|
|
if (parsedAlbumInfo == null)
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-03-10 02:19:10 +00:00
|
|
|
var remoteAlbum = _parsingService.Map(parsedAlbumInfo);
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2019-03-10 02:19:10 +00:00
|
|
|
if (remoteAlbum != null)
|
|
|
|
{
|
|
|
|
return new ParseResource
|
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
ParsedAlbumInfo = remoteAlbum.ParsedAlbumInfo,
|
|
|
|
Artist = remoteAlbum.Artist.ToResource(),
|
|
|
|
Albums = remoteAlbum.Albums.ToResource()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new ParseResource
|
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
ParsedAlbumInfo = parsedAlbumInfo
|
|
|
|
};
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|