mirror of https://github.com/lidarr/Lidarr
Add encoding detector support for the cue sheet parser.
Use ID overrides when manually import items from a cue sheet. (cherry picked from commit 21a2314a19b8aed71f86885cb13d9583ca346023)
This commit is contained in:
parent
88abe75927
commit
853fdf7ff2
|
@ -29,6 +29,7 @@
|
|||
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
|
||||
<PackageReference Include="Equ" Version="2.3.0" />
|
||||
<PackageReference Include="MonoTorrent" Version="2.0.7" />
|
||||
<PackageReference Include="UTF.Unknown" Version="2.5.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NzbDrone.Common\Lidarr.Common.csproj" />
|
||||
|
|
|
@ -3,12 +3,13 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using UtfUnknown;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
|
@ -22,13 +23,14 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
public interface ICueSheetService
|
||||
{
|
||||
List<ImportDecision<LocalTrack>> GetImportDecisions(ref List<IFileInfo> mediaFileList, ImportDecisionMakerInfo itemInfo, ImportDecisionMakerConfig config);
|
||||
List<ImportDecision<LocalTrack>> GetImportDecisions(ref List<IFileInfo> mediaFileList, IdentificationOverrides idOverrides, ImportDecisionMakerInfo itemInfo, ImportDecisionMakerConfig config);
|
||||
}
|
||||
|
||||
public class CueSheetService : ICueSheetService
|
||||
{
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IMakeImportDecision _importDecisionMaker;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private static string _FileKey = "FILE";
|
||||
private static string _TrackKey = "TRACK";
|
||||
|
@ -40,13 +42,15 @@ namespace NzbDrone.Core.MediaFiles
|
|||
private static string _TitleKey = "TITLE";
|
||||
|
||||
public CueSheetService(IParsingService parsingService,
|
||||
IMakeImportDecision importDecisionMaker)
|
||||
IMakeImportDecision importDecisionMaker,
|
||||
Logger logger)
|
||||
{
|
||||
_parsingService = parsingService;
|
||||
_importDecisionMaker = importDecisionMaker;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<ImportDecision<LocalTrack>> GetImportDecisions(ref List<IFileInfo> mediaFileList, ImportDecisionMakerInfo itemInfo, ImportDecisionMakerConfig config)
|
||||
public List<ImportDecision<LocalTrack>> GetImportDecisions(ref List<IFileInfo> mediaFileList, IdentificationOverrides idOverrides, ImportDecisionMakerInfo itemInfo, ImportDecisionMakerConfig config)
|
||||
{
|
||||
var decisions = new List<ImportDecision<LocalTrack>>();
|
||||
var cueFiles = mediaFileList.Where(x => x.Extension.Equals(".cue")).ToList();
|
||||
|
@ -60,6 +64,10 @@ namespace NzbDrone.Core.MediaFiles
|
|||
foreach (var cueFile in cueFiles)
|
||||
{
|
||||
var cueSheetInfo = GetCueSheetInfo(cueFile, mediaFileList);
|
||||
if (idOverrides != null)
|
||||
{
|
||||
cueSheetInfo.IdOverrides = idOverrides;
|
||||
}
|
||||
|
||||
var addedCueSheetInfo = cueSheetInfos.Find(existingCueSheetInfo => existingCueSheetInfo.CueSheet.DiscID == cueSheetInfo.CueSheet.DiscID);
|
||||
if (addedCueSheetInfo == null)
|
||||
|
@ -161,7 +169,10 @@ namespace NzbDrone.Core.MediaFiles
|
|||
using (var fs = fileInfo.OpenRead())
|
||||
{
|
||||
var bytes = new byte[fileInfo.Length];
|
||||
var encoding = new UTF8Encoding(true);
|
||||
var result = CharsetDetector.DetectFromFile(fileInfo.FullName); // or pass FileInfo
|
||||
var encoding = result.Detected.Encoding;
|
||||
_logger.Debug("Detected encoding {0} for {1}", encoding.WebName, fileInfo.FullName);
|
||||
|
||||
string content;
|
||||
while (fs.Read(bytes, 0, bytes.Length) > 0)
|
||||
{
|
||||
|
@ -369,6 +380,8 @@ namespace NzbDrone.Core.MediaFiles
|
|||
return cueSheetInfo;
|
||||
}
|
||||
|
||||
cueSheetInfo.IdOverrides.Artist = artistFromCue;
|
||||
|
||||
var parsedAlbumInfo = new ParsedAlbumInfo
|
||||
{
|
||||
AlbumTitle = cueSheet.Title,
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
var decisions = new List<ImportDecision<LocalTrack>>();
|
||||
|
||||
decisions.AddRange(_cueSheetService.GetImportDecisions(ref mediaFileList, itemInfo, config));
|
||||
decisions.AddRange(_cueSheetService.GetImportDecisions(ref mediaFileList, null, itemInfo, config));
|
||||
decisions.AddRange(_importDecisionMaker.GetImportDecisions(mediaFileList, null, itemInfo, config));
|
||||
|
||||
decisionsStopwatch.Stop();
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
|
|||
AddNewArtists = false
|
||||
};
|
||||
|
||||
var decisions = _cueSheetService.GetImportDecisions(ref audioFiles, itemInfo, config);
|
||||
var decisions = _cueSheetService.GetImportDecisions(ref audioFiles, null, itemInfo, config);
|
||||
if (!audioFiles.Empty())
|
||||
{
|
||||
decisions.AddRange(_importDecisionMaker.GetImportDecisions(audioFiles, idOverrides, itemInfo, config));
|
||||
|
@ -251,7 +251,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
|
|||
AlbumRelease = group.First().Release
|
||||
};
|
||||
|
||||
var decisions = _cueSheetService.GetImportDecisions(ref audioFiles, itemInfo, config);
|
||||
var decisions = _cueSheetService.GetImportDecisions(ref audioFiles, idOverride, itemInfo, config);
|
||||
if (audioFiles.Count > 0)
|
||||
{
|
||||
decisions.AddRange(_importDecisionMaker.GetImportDecisions(audioFiles, idOverride, itemInfo, config));
|
||||
|
|
Loading…
Reference in New Issue