mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
cleaned up parsing logic and structure.
This commit is contained in:
parent
cd2761d07d
commit
6e88f55a54
120 changed files with 2149 additions and 3064 deletions
61
NzbDrone.Core/Update/UpdatePackageProvider.cs
Normal file
61
NzbDrone.Core/Update/UpdatePackageProvider.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public interface IUpdatePackageProvider
|
||||
{
|
||||
IEnumerable<UpdatePackage> GetAvailablePackages();
|
||||
UpdatePackage GetLatestUpdate();
|
||||
}
|
||||
|
||||
public class UpdatePackageProvider : IUpdatePackageProvider
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
|
||||
|
||||
public UpdatePackageProvider(IConfigService configService, IHttpProvider httpProvider, Logger logger)
|
||||
{
|
||||
_configService = configService;
|
||||
_httpProvider = httpProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<UpdatePackage> GetAvailablePackages()
|
||||
{
|
||||
var updateList = new List<UpdatePackage>();
|
||||
var updateUrl = _configService.UpdateUrl;
|
||||
|
||||
_logger.Debug("Getting a list of updates from {0}", updateUrl);
|
||||
|
||||
var rawUpdateList = _httpProvider.DownloadString(updateUrl);
|
||||
var matches = ParseRegex.Matches(rawUpdateList);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
var updatePackage = new UpdatePackage();
|
||||
updatePackage.FileName = match.Groups["filename"].Value;
|
||||
updatePackage.Url = updateUrl + updatePackage.FileName;
|
||||
updatePackage.Version = new Version(match.Groups["version"].Value);
|
||||
updateList.Add(updatePackage);
|
||||
}
|
||||
|
||||
_logger.Debug("Found {0} update packages", updateUrl.Length);
|
||||
|
||||
return updateList;
|
||||
}
|
||||
|
||||
public UpdatePackage GetLatestUpdate()
|
||||
{
|
||||
return GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue