Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from mark-monteiro/integrate-stylecop
Browse files Browse the repository at this point in the history
First Pass At StyleCop Integration
  • Loading branch information
Bond-009 authored Mar 10, 2020
2 parents 80a2f14 + 34fd8c5 commit 116d2ee
Show file tree
Hide file tree
Showing 32 changed files with 650 additions and 594 deletions.
27 changes: 14 additions & 13 deletions Emby.AutoOrganize/Api/FileOrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ namespace Emby.AutoOrganize.Api
public class GetFileOrganizationActivity : IReturn<QueryResult<FileOrganizationResult>>
{
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// Gets or sets a value indicating the number of items to skip over in the query. Use to specify a page
/// number.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }

/// <summary>
/// The maximum number of items to return
/// Gets or sets the maximum number of items to return. Use to specify a page size.
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
}

Expand Down Expand Up @@ -119,19 +118,18 @@ public class OrganizeMovie
}

[Route("/Library/FileOrganizations/SmartMatches", "GET", Summary = "Gets smart match entries")]
public class GetSmartMatchInfos : IReturn<QueryResult<SmartMatchInfo>>
public class GetSmartMatchInfos : IReturn<QueryResult<SmartMatchResult>>
{
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// Gets or sets a value indicating the number of items to skips over in the query. Use to specify a page
/// number.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }

/// <summary>
/// The maximum number of items to return
/// Gets or sets the maximum number of items to return. Use to specify a page size.
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
}
Expand All @@ -148,13 +146,17 @@ public class FileOrganizationService : IService, IRequiresRequest
{
private readonly IHttpResultFactory _resultFactory;

public IRequest Request { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="FileOrganizationService"/> class.
/// </summary>
/// <param name="resultFactory">HTTP result factory to use for making requests.</param>
public FileOrganizationService(IHttpResultFactory resultFactory)
{
_resultFactory = resultFactory;
}

public IRequest Request { get; set; }

private IFileOrganizationService InternalFileOrganizationService
{
get { return PluginEntryPoint.Current.FileOrganizationService; }
Expand Down Expand Up @@ -194,7 +196,6 @@ public void Delete(ClearOrganizationCompletedLog request)
Task.WaitAll(task);
}


public void Post(PerformOrganization request)
{
// Don't await this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using System.IO;
using MediaBrowser.Model.Drawing;

namespace Emby.AutoOrganize
{
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
/// <summary>
/// The auto-organize plugin.
/// </summary>
public class AutoOrganizePlugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
public Plugin(IApplicationPaths appPaths, IXmlSerializer xmlSerializer)
/// <summary>
/// Initializes a new instance of the <see cref="AutoOrganizePlugin"/> class.
/// </summary>
/// <param name="appPaths">The application paths.</param>
/// <param name="xmlSerializer">The XML serializer.</param>
public AutoOrganizePlugin(IApplicationPaths appPaths, IXmlSerializer xmlSerializer)
: base(appPaths, xmlSerializer)
{
}

public override string Name => "Auto Organize";


public override string Description
=> "Automatically organize new media";
/// <inheritdoc/>
public override Guid Id => new Guid("70b7b43b-471b-4159-b4be-56750c795499");

public PluginConfiguration PluginConfiguration => Configuration;
/// <inheritdoc/>
public override string Name => "Auto Organize";

private Guid _id = new Guid("70b7b43b-471b-4159-b4be-56750c795499");
public override Guid Id
{
get { return _id; }
}
/// <inheritdoc/>
public override string Description => "Automatically organize new media";

/// <inheritdoc/>
public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
Expand Down
3 changes: 3 additions & 0 deletions Emby.AutoOrganize/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Emby.AutoOrganize.Configuration
{
/// <summary>
/// Configuration for <see cref="Emby.AutoOrganize.AutoOrganizePlugin"/>.
/// </summary>
public class PluginConfiguration : BasePluginConfiguration
{
}
Expand Down
96 changes: 38 additions & 58 deletions Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public EpisodeFileOrganizer(
}

private NamingOptions _namingOptions;

private NamingOptions GetNamingOptionsInternal()
{
if (_namingOptions == null)
Expand Down Expand Up @@ -132,13 +133,11 @@ public async Task<FileOrganizationResult> OrganizeEpisodeFile(
{
if (episodeInfo.IsByDate)
{
_logger.LogDebug("Extracted information from {0}. Series name {1}, Date {2}",
path, seriesName, premiereDate.Value);
_logger.LogDebug("Extracted information from {0}. Series name {1}, Date {2}", path, seriesName, premiereDate.Value);
}
else
{
_logger.LogDebug("Extracted information from {0}. Series name {1}, Season {2}, Episode {3}",
path, seriesName, seasonNumber, episodeNumber);
_logger.LogDebug("Extracted information from {0}. Series name {1}, Season {2}, Episode {3}", path, seriesName, seasonNumber, episodeNumber);
}

// We detected an airdate or (an season number and an episode number)
Expand All @@ -150,7 +149,8 @@ public async Task<FileOrganizationResult> OrganizeEpisodeFile(

result.ExtractedEndingEpisodeNumber = endingEpisodeNumber;

await OrganizeEpisode(path,
await OrganizeEpisode(
path,
seriesName,
seriesYear,
seasonNumber,
Expand Down Expand Up @@ -188,7 +188,6 @@ await OrganizeEpisode(path,
// Don't keep saving the same result over and over if nothing has changed
return previousResult;
}

}
catch (OrganizationException ex)
{
Expand Down Expand Up @@ -217,21 +216,14 @@ private async Task<Series> AutoDetectSeries(
{
RemoteSearchResult finalResult = null;

#region Search One

var seriesInfo = new SeriesInfo
{
Name = seriesName,
Year = seriesYear
};

// Perform remote search
var seriesInfo = new SeriesInfo { Name = seriesName, Year = seriesYear };
var searchQuery = new RemoteSearchQuery<SeriesInfo> { SearchInfo = seriesInfo };
var searchResults = await _providerManager.GetRemoteSearchResults<Series, SeriesInfo>(searchQuery, cancellationToken).ConfigureAwait(false);

#endregion

// Group series by name and year (if 2 series with the exact same name, the same year ...)
var groupedResult = searchResults.GroupBy(p => new { p.Name, p.ProductionYear },
var groupedResult = searchResults.GroupBy(
p => new { p.Name, p.ProductionYear },
p => p,
(key, g) => new { Key = key, Result = g.ToList() }).ToList();

Expand Down Expand Up @@ -276,9 +268,8 @@ private async Task<Series> CreateNewSeries(
{
Series series;

// Ensure that we don't create the same series multiple time
// We create series one at a time
var seriesCreationLock = new Object();
// Ensure that we don't create the same series multiple times; create one at a time
var seriesCreationLock = new object();
lock (seriesCreationLock)
{
series = GetMatchingSeries(request.NewSeriesName, request.NewSeriesYear, request.TargetFolder, null);
Expand Down Expand Up @@ -337,10 +328,11 @@ public async Task<FileOrganizationResult> OrganizeWithCorrection(
series = (Series)_libraryManager.GetItemById(request.SeriesId);
}

// We manually set the media as Series
// We manually set the media as Series
result.Type = CurrentFileOrganizerType;

await OrganizeEpisode(result.OriginalPath,
await OrganizeEpisode(
result.OriginalPath,
series,
request.SeasonNumber,
request.EpisodeNumber,
Expand All @@ -362,7 +354,8 @@ await OrganizeEpisode(result.OriginalPath,
return result;
}

private Task OrganizeEpisode(string sourcePath,
private Task OrganizeEpisode(
string sourcePath,
string seriesName,
int? seriesYear,
int? seasonNumber,
Expand All @@ -374,7 +367,7 @@ private Task OrganizeEpisode(string sourcePath,
FileOrganizationResult result,
CancellationToken cancellationToken)
{
var series = GetMatchingSeries(seriesName, seriesYear, "", result);
var series = GetMatchingSeries(seriesName, seriesYear, string.Empty, result);

if (series == null)
{
Expand All @@ -390,7 +383,8 @@ private Task OrganizeEpisode(string sourcePath,
}
}

return OrganizeEpisode(sourcePath,
return OrganizeEpisode(
sourcePath,
series,
seasonNumber,
episodeNumber,
Expand All @@ -403,20 +397,10 @@ private Task OrganizeEpisode(string sourcePath,
}

/// <summary>
/// Organize part responsible of Season AND Episode recognition
/// Organize part responsible of Season AND Episode recognition.
/// </summary>
/// <param name="sourcePath"></param>
/// <param name="series"></param>
/// <param name="seasonNumber"></param>
/// <param name="episodeNumber"></param>
/// <param name="endingEpiosdeNumber"></param>
/// <param name="premiereDate"></param>
/// <param name="options"></param>
/// <param name="rememberCorrection"></param>
/// <param name="result"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task OrganizeEpisode(string sourcePath,
private async Task OrganizeEpisode(
string sourcePath,
Series series,
int? seasonNumber,
int? episodeNumber,
Expand Down Expand Up @@ -639,8 +623,7 @@ private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targ
directory = Path.GetDirectoryName(file);
var filename = Path.GetFileName(file);

filename = filename.Replace(originalFilenameWithoutExtension, targetFilenameWithoutExtension,
StringComparison.OrdinalIgnoreCase);
filename = filename.Replace(originalFilenameWithoutExtension, targetFilenameWithoutExtension, StringComparison.OrdinalIgnoreCase);

var destination = Path.Combine(directory, filename);

Expand All @@ -649,7 +632,8 @@ private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targ
}
}

private List<string> GetOtherDuplicatePaths(string targetPath,
private List<string> GetOtherDuplicatePaths(
string targetPath,
Series series,
Episode episode)
{
Expand All @@ -673,7 +657,6 @@ private List<string> GetOtherDuplicatePaths(string targetPath,
i.IndexNumber.HasValue &&
i.IndexNumber.Value == episode.IndexNumber)
{

if (episode.IndexNumberEnd.HasValue || i.IndexNumberEnd.HasValue)
{
return episode.IndexNumberEnd.HasValue && i.IndexNumberEnd.HasValue &&
Expand Down Expand Up @@ -764,7 +747,8 @@ private void PerformFileSorting(TvFileOrganizationOptions options, FileOrganizat
}
}

private async Task<Episode> GetMatchingEpisode(Series series,
private async Task<Episode> GetMatchingEpisode(
Series series,
int? seasonNumber,
int? episodeNumber,
int? endingEpiosdeNumber,
Expand Down Expand Up @@ -817,10 +801,10 @@ private Season GetMatchingSeason(Series series, Episode episode, TvFileOrganizat
}
}

// If the season path is missing, compute it and create the directory on the filesystem
if (string.IsNullOrEmpty(season.Path))
{
season.Path = GetSeasonFolderPath(series, episode.ParentIndexNumber.Value, options);
// Create the folder
Directory.CreateDirectory(season.Path);
}

Expand Down Expand Up @@ -860,7 +844,6 @@ private Series GetMatchingSeries(string seriesName, int? seriesYear, string targ
Recursive = true,
Name = info.ItemName,
DtoOptions = new DtoOptions(true)

}).Cast<Series>().FirstOrDefault(s => s.Path.StartsWith(targetFolder, StringComparison.Ordinal));
}
}
Expand All @@ -869,11 +852,8 @@ private Series GetMatchingSeries(string seriesName, int? seriesYear, string targ
}

/// <summary>
/// Get the new series name
/// Get the new series name.
/// </summary>
/// <param name="series"></param>
/// <param name="options"></param>
/// <returns></returns>
private string GetSeriesDirectoryName(Series series, TvFileOrganizationOptions options)
{
var seriesName = series.Name;
Expand All @@ -895,15 +875,16 @@ private string GetSeriesDirectoryName(Series series, TvFileOrganizationOptions o
}

/// <summary>
/// CreateNewEpisode
/// Look up metadata for an episode and use it to create an <see cref="Episode"/> object.
/// </summary>
/// <param name="series">The series.</param>
/// <param name="seasonNumber">The season number.</param>
/// <param name="series">The series the episode is in.</param>
/// <param name="seasonNumber">The season number the episode is in.</param>
/// <param name="episodeNumber">The episode number.</param>
/// <param name="endingEpisodeNumber">The ending episode number.</param>
/// <param name="premiereDate">The premiere date.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>System.String.</returns>
/// <returns>A task representing the creation of the <see cref="Episode"/> object.</returns>
/// <exception cref="OrganizationException">If no metadata can be found for the specified episode parameters.</exception>
private async Task<Episode> CreateNewEpisode(
Series series,
int? seasonNumber,
Expand All @@ -923,11 +904,9 @@ private async Task<Episode> CreateNewEpisode(
PremiereDate = premiereDate
};

var searchResults = await _providerManager.GetRemoteSearchResults<Episode, EpisodeInfo>(new RemoteSearchQuery<EpisodeInfo>
{
SearchInfo = episodeInfo

}, cancellationToken).ConfigureAwait(false);
var searchResults = await _providerManager.GetRemoteSearchResults<Episode, EpisodeInfo>(
new RemoteSearchQuery<EpisodeInfo> { SearchInfo = episodeInfo },
cancellationToken).ConfigureAwait(false);

var episodeSearch = searchResults.FirstOrDefault();

Expand Down Expand Up @@ -994,6 +973,7 @@ private bool ContainsEpisodesWithoutSeasonFolders(Series series)
return true;
}
}

return false;
}

Expand Down
Loading

0 comments on commit 116d2ee

Please sign in to comment.