mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 04:59:35 -07:00
Fix Headphones Download Auth, Add Special Parsing (#152)
* Add Secondary Backup Parsing Method if Regex Fails * Add BasicAuth info to release for nzb download handling
This commit is contained in:
parent
ba3d6362af
commit
ded7574227
11 changed files with 147 additions and 7 deletions
|
@ -24,7 +24,9 @@ namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests
|
||||||
Name = "Headphones VIP",
|
Name = "Headphones VIP",
|
||||||
Settings = new HeadphonesSettings()
|
Settings = new HeadphonesSettings()
|
||||||
{
|
{
|
||||||
Categories = new int[] { 3000 }
|
Categories = new int[] { 3000 },
|
||||||
|
Username = "user",
|
||||||
|
Password = "pass"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,6 +55,7 @@ namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests
|
||||||
releaseInfo.Title.Should().Be("Lady Gaga Born This Way 2CD FLAC 2011 WRE");
|
releaseInfo.Title.Should().Be("Lady Gaga Born This Way 2CD FLAC 2011 WRE");
|
||||||
releaseInfo.DownloadProtocol.Should().Be(DownloadProtocol.Usenet);
|
releaseInfo.DownloadProtocol.Should().Be(DownloadProtocol.Usenet);
|
||||||
releaseInfo.DownloadUrl.Should().Be("https://indexer.codeshy.com/api?t=g&guid=123456&apikey=123456789");
|
releaseInfo.DownloadUrl.Should().Be("https://indexer.codeshy.com/api?t=g&guid=123456&apikey=123456789");
|
||||||
|
releaseInfo.BasicAuthString.Should().Be("dXNlcjpwYXNz");
|
||||||
releaseInfo.Indexer.Should().Be(Subject.Definition.Name);
|
releaseInfo.Indexer.Should().Be(Subject.Definition.Name);
|
||||||
releaseInfo.PublishDate.Should().Be(DateTime.Parse("2013/06/02 08:58:54"));
|
releaseInfo.PublishDate.Should().Be(DateTime.Parse("2013/06/02 08:58:54"));
|
||||||
releaseInfo.Size.Should().Be(917347414);
|
releaseInfo.Size.Should().Be(917347414);
|
||||||
|
|
|
@ -62,6 +62,12 @@ namespace NzbDrone.Core.DecisionEngine
|
||||||
{
|
{
|
||||||
var parsedAlbumInfo = Parser.Parser.ParseAlbumTitle(report.Title);
|
var parsedAlbumInfo = Parser.Parser.ParseAlbumTitle(report.Title);
|
||||||
|
|
||||||
|
if (parsedAlbumInfo == null && searchCriteria != null)
|
||||||
|
{
|
||||||
|
parsedAlbumInfo = Parser.Parser.ParseAlbumTitleWithSearchCriteria(report.Title,
|
||||||
|
searchCriteria.Artist, searchCriteria.Albums);
|
||||||
|
}
|
||||||
|
|
||||||
if (parsedAlbumInfo != null)
|
if (parsedAlbumInfo != null)
|
||||||
{
|
{
|
||||||
// TODO: Artist Data Augment without calling to parse title again
|
// TODO: Artist Data Augment without calling to parse title again
|
||||||
|
|
|
@ -6,6 +6,7 @@ using NzbDrone.Common.Cache;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.History;
|
using NzbDrone.Core.History;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.TrackedDownloads
|
namespace NzbDrone.Core.Download.TrackedDownloads
|
||||||
|
@ -116,11 +117,31 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
||||||
{
|
{
|
||||||
// Try parsing the original source title and if that fails, try parsing it as a special
|
// Try parsing the original source title and if that fails, try parsing it as a special
|
||||||
// TODO: Pass the TVDB ID and TVRage IDs in as well so we have a better chance for finding the item
|
// TODO: Pass the TVDB ID and TVRage IDs in as well so we have a better chance for finding the item
|
||||||
|
var historyArtist = firstHistoryItem.Artist;
|
||||||
|
var historyAlbums = new List<Album> { firstHistoryItem.Album };
|
||||||
|
|
||||||
parsedAlbumInfo = Parser.Parser.ParseAlbumTitle(firstHistoryItem.SourceTitle);
|
parsedAlbumInfo = Parser.Parser.ParseAlbumTitle(firstHistoryItem.SourceTitle);
|
||||||
|
|
||||||
if (parsedAlbumInfo != null)
|
if (parsedAlbumInfo != null)
|
||||||
{
|
{
|
||||||
trackedDownload.RemoteAlbum = _parsingService.Map(parsedAlbumInfo, firstHistoryItem.ArtistId, historyItems.Where(v => v.EventType == HistoryEventType.Grabbed).Select(h => h.AlbumId).Distinct());
|
trackedDownload.RemoteAlbum = _parsingService.Map(parsedAlbumInfo,
|
||||||
|
firstHistoryItem.ArtistId,
|
||||||
|
historyItems.Where(v => v.EventType == HistoryEventType.Grabbed).Select(h => h.AlbumId)
|
||||||
|
.Distinct());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parsedAlbumInfo =
|
||||||
|
Parser.Parser.ParseAlbumTitleWithSearchCriteria(firstHistoryItem.SourceTitle,
|
||||||
|
historyArtist, historyAlbums);
|
||||||
|
|
||||||
|
if (parsedAlbumInfo != null)
|
||||||
|
{
|
||||||
|
trackedDownload.RemoteAlbum = _parsingService.Map(parsedAlbumInfo,
|
||||||
|
firstHistoryItem.ArtistId,
|
||||||
|
historyItems.Where(v => v.EventType == HistoryEventType.Grabbed).Select(h => h.AlbumId)
|
||||||
|
.Distinct());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.ThingiProvider;
|
using NzbDrone.Core.ThingiProvider;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.RemotePathMappings;
|
using NzbDrone.Core.RemotePathMappings;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download
|
namespace NzbDrone.Core.Download
|
||||||
|
@ -43,7 +44,15 @@ namespace NzbDrone.Core.Download
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nzbData = _httpClient.Get(new HttpRequest(url)).ResponseData;
|
var nzbDataRequest = new HttpRequest(url);
|
||||||
|
|
||||||
|
// TODO: Look into moving download request handling to indexer
|
||||||
|
if (remoteAlbum.Release.BasicAuthString.IsNotNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
nzbDataRequest.Headers.Set("Authorization", "Basic " + remoteAlbum.Release.BasicAuthString);
|
||||||
|
}
|
||||||
|
|
||||||
|
nzbData = _httpClient.Get(nzbDataRequest).ResponseData;
|
||||||
|
|
||||||
_logger.Debug("Downloaded nzb for release '{0}' finished ({1} bytes from {2})", remoteAlbum.Release.Title, nzbData.Length, url);
|
_logger.Debug("Downloaded nzb for release '{0}' finished ({1} bytes from {2})", remoteAlbum.Release.Title, nzbData.Length, url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,9 @@ namespace NzbDrone.Core.History
|
||||||
|
|
||||||
public List<History> FindByDownloadId(string downloadId)
|
public List<History> FindByDownloadId(string downloadId)
|
||||||
{
|
{
|
||||||
return Query.Where(h => h.DownloadId == downloadId);
|
return Query.Join<History, Artist>(JoinType.Left, h => h.Artist, (h, a) => h.ArtistId == a.Id)
|
||||||
|
.Join<History, Album>(JoinType.Left, h => h.Album, (h, r) => h.AlbumId == r.Id)
|
||||||
|
.Where(h => h.DownloadId == downloadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<History> GetByArtist(int artistId, HistoryEventType? eventType)
|
public List<History> GetByArtist(int artistId, HistoryEventType? eventType)
|
||||||
|
|
|
@ -32,7 +32,10 @@ namespace NzbDrone.Core.Indexers.Headphones
|
||||||
|
|
||||||
public override IParseIndexerResponse GetParser()
|
public override IParseIndexerResponse GetParser()
|
||||||
{
|
{
|
||||||
return new NewznabRssParser();
|
return new HeadphonesRssParser
|
||||||
|
{
|
||||||
|
Settings = Settings
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Headphones(IHeadphonesCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
public Headphones(IHeadphonesCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
||||||
|
|
23
src/NzbDrone.Core/Indexers/Headphones/HeadphonesRssParser.cs
Normal file
23
src/NzbDrone.Core/Indexers/Headphones/HeadphonesRssParser.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using NzbDrone.Core.Indexers.Newznab;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Indexers.Headphones
|
||||||
|
{
|
||||||
|
public class HeadphonesRssParser : NewznabRssParser
|
||||||
|
{
|
||||||
|
public const string ns = "{http://www.newznab.com/DTD/2010/feeds/attributes/}";
|
||||||
|
public HeadphonesSettings Settings { get; set; }
|
||||||
|
|
||||||
|
public HeadphonesRssParser()
|
||||||
|
{
|
||||||
|
PreferredEnclosureMimeTypes = UsenetEnclosureMimeTypes;
|
||||||
|
UseEnclosureUrl = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GetBasicAuth()
|
||||||
|
{
|
||||||
|
return Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{Settings.Username}:{Settings.Password}")); ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -156,6 +156,7 @@ namespace NzbDrone.Core.Indexers
|
||||||
releaseInfo.Title = GetTitle(item);
|
releaseInfo.Title = GetTitle(item);
|
||||||
releaseInfo.PublishDate = GetPublishDate(item);
|
releaseInfo.PublishDate = GetPublishDate(item);
|
||||||
releaseInfo.DownloadUrl = GetDownloadUrl(item);
|
releaseInfo.DownloadUrl = GetDownloadUrl(item);
|
||||||
|
releaseInfo.BasicAuthString = GetBasicAuth();
|
||||||
releaseInfo.InfoUrl = GetInfoUrl(item);
|
releaseInfo.InfoUrl = GetInfoUrl(item);
|
||||||
releaseInfo.CommentUrl = GetCommentUrl(item);
|
releaseInfo.CommentUrl = GetCommentUrl(item);
|
||||||
|
|
||||||
|
@ -198,6 +199,11 @@ namespace NzbDrone.Core.Indexers
|
||||||
return XElementExtensions.ParseDate(dateString);
|
return XElementExtensions.ParseDate(dateString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual string GetBasicAuth()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual string GetDownloadUrl(XElement item)
|
protected virtual string GetDownloadUrl(XElement item)
|
||||||
{
|
{
|
||||||
if (UseEnclosureUrl)
|
if (UseEnclosureUrl)
|
||||||
|
|
|
@ -526,6 +526,7 @@
|
||||||
<Compile Include="Indexers\Headphones\HeadphonesCapabilitiesProvider.cs" />
|
<Compile Include="Indexers\Headphones\HeadphonesCapabilitiesProvider.cs" />
|
||||||
<Compile Include="Indexers\Headphones\HeadphonesCapabilities.cs" />
|
<Compile Include="Indexers\Headphones\HeadphonesCapabilities.cs" />
|
||||||
<Compile Include="Indexers\Headphones\HeadphonesRequestGenerator.cs" />
|
<Compile Include="Indexers\Headphones\HeadphonesRequestGenerator.cs" />
|
||||||
|
<Compile Include="Indexers\Headphones\HeadphonesRssParser.cs" />
|
||||||
<Compile Include="Indexers\IIndexerSettings.cs" />
|
<Compile Include="Indexers\IIndexerSettings.cs" />
|
||||||
<Compile Include="Indexers\IndexerDefaults.cs" />
|
<Compile Include="Indexers\IndexerDefaults.cs" />
|
||||||
<Compile Include="Indexers\ITorrentIndexerSettings.cs" />
|
<Compile Include="Indexers\ITorrentIndexerSettings.cs" />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ namespace NzbDrone.Core.Parser.Model
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public long Size { get; set; }
|
public long Size { get; set; }
|
||||||
public string DownloadUrl { get; set; }
|
public string DownloadUrl { get; set; }
|
||||||
|
public string BasicAuthString { get; set; }
|
||||||
public string InfoUrl { get; set; }
|
public string InfoUrl { get; set; }
|
||||||
public string CommentUrl { get; set; }
|
public string CommentUrl { get; set; }
|
||||||
public int IndexerId { get; set; }
|
public int IndexerId { get; set; }
|
||||||
|
@ -87,4 +88,4 @@ namespace NzbDrone.Core.Parser.Model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ using NLog;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
using NzbDrone.Core.MediaFiles.MediaInfo;
|
using NzbDrone.Core.MediaFiles.MediaInfo;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.Languages;
|
using NzbDrone.Core.Languages;
|
||||||
using TagLib;
|
using TagLib;
|
||||||
|
@ -319,6 +320,70 @@ namespace NzbDrone.Core.Parser
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ParsedAlbumInfo ParseAlbumTitleWithSearchCriteria(string title, Artist artist, List<Album> album)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!ValidateBeforeParsing(title)) return null;
|
||||||
|
|
||||||
|
Logger.Debug("Parsing string '{0}'", title);
|
||||||
|
|
||||||
|
if (ReversedTitleRegex.IsMatch(title))
|
||||||
|
{
|
||||||
|
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
|
||||||
|
Array.Reverse(titleWithoutExtension);
|
||||||
|
|
||||||
|
title = new string (titleWithoutExtension) + title.Substring(titleWithoutExtension.Length);
|
||||||
|
|
||||||
|
Logger.Debug("Reversed name detected. Converted to '{0}'", title);
|
||||||
|
}
|
||||||
|
|
||||||
|
var releaseTitle = RemoveFileExtension(title);
|
||||||
|
|
||||||
|
var simpleTitle = SimpleTitleRegex.Replace(releaseTitle, string.Empty);
|
||||||
|
|
||||||
|
simpleTitle = WebsitePrefixRegex.Replace(simpleTitle, string.Empty);
|
||||||
|
|
||||||
|
simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty);
|
||||||
|
|
||||||
|
var result = new ParsedAlbumInfo();
|
||||||
|
|
||||||
|
if (simpleTitle.ToLowerInvariant().Contains(artist.Name.ToLowerInvariant()))
|
||||||
|
{
|
||||||
|
result.ArtistName = artist.Name;
|
||||||
|
var artistRegex = new Regex(Regex.Escape(artist.Name.ToLowerInvariant()));
|
||||||
|
var albumReleaseString = artistRegex.Replace(simpleTitle.ToLowerInvariant(), string.Empty, 1);
|
||||||
|
|
||||||
|
var selectedAlbum = album.FirstOrDefault(s => albumReleaseString.Contains(s.Title.ToLowerInvariant()));
|
||||||
|
|
||||||
|
if (selectedAlbum != null)
|
||||||
|
{
|
||||||
|
result.AlbumTitle = selectedAlbum.Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Language = LanguageParser.ParseLanguage(releaseTitle);
|
||||||
|
Logger.Debug("Language parsed: {0}", result.Language);
|
||||||
|
|
||||||
|
result.Quality = QualityParser.ParseQuality(title, null, 0);
|
||||||
|
Logger.Debug("Quality parsed: {0}", result.Quality);
|
||||||
|
|
||||||
|
result.ReleaseGroup = ParseReleaseGroup(releaseTitle);
|
||||||
|
|
||||||
|
Logger.Debug("Release Group parsed: {0}", result.ReleaseGroup);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (!title.ToLower().Contains("password") && !title.ToLower().Contains("yenc"))
|
||||||
|
Logger.Error(e, "An error has occurred while trying to parse {0}", title);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Debug("Unable to parse {0}", title);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static ParsedAlbumInfo ParseAlbumTitle(string title)
|
public static ParsedAlbumInfo ParseAlbumTitle(string title)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue