Skip to content

Commit

Permalink
Fix MediaBrowser#17 : Add Season folder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
PoppyPop committed Jul 27, 2018
1 parent 33a087a commit 9dc5247
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
73 changes: 70 additions & 3 deletions Emby.AutoOrganize/Configuration/autoorganizetv.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,72 @@
<input is="emby-input" id="txtMinFileSize" type="number" label="Min file size:" pattern="[0-9]*" min="0" required />
<div class="fieldDescription">Files smaller than this will be ignored.</div>
</div>
<div class="inputContainer">
<input is="emby-input" id="txtSeasonFolderPattern" type="text" label="Season folder pattern:" required />
<div class="fieldDescription seasonFolderFieldDescription"></div>

<div is="emby-collapse" title="Season directory pattern">
<div class="collapseContent">
<br />
<div class="inputContainer">
<input is="emby-input" id="txtSeasonFolderPattern" type="text" label="Season folder pattern:" required />
<div class="fieldDescription seasonFolderFieldDescription"></div>
</div>

<br />
<p>Supported Patterns</p>

<table id="series-table" class="ui-responsive">
<thead>
<tr>
<th>Term</th>
<th>Pattern</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>Series name</td>
<td>%sn</td>
<td>Series name</td>
</tr>
<tr>
<td>Series name</td>
<td>%s.n</td>
<td>Series.name</td>
</tr>
<tr>
<td>Series name</td>
<td>%s_n</td>
<td>Series_name</td>
</tr>
<tr>
<td>Series year</td>
<td>%sy</td>
<td>2017</td>
</tr>
<tr>
<td>Season number</td>
<td>%s</td>
<td>1</td>
</tr>
<tr>
<td>Season number</td>
<td>%0s</td>
<td>01</td>
</tr>
<tr>
<td>Season number</td>
<td>%00s</td>
<td>001</td>
</tr>
<tr>
<td>Original Directory Path</td>
<td>Season %s</td>
<td>Season 1</td>
</tr>
</tbody>
</table>
</div>
</div>

<div class="inputContainer">
<input is="emby-input" id="txtSeasonZeroName" type="text" label="Season zero folder name:" required />
<div class="fieldDescription"></div>
Expand Down Expand Up @@ -131,6 +193,11 @@
<td>%0s</td>
<td>01</td>
</tr>
<tr>
<td>Season number</td>
<td>%00s</td>
<td>001</td>
</tr>
<tr>
<td>Episode number</td>
<td>%e</td>
Expand Down
11 changes: 10 additions & 1 deletion Emby.AutoOrganize/Configuration/autoorganizetv.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,18 @@
}

function updateSeasonPatternHelp() {
var seriesName = "Series Name";
var seriesYear = "2017";

var value = view.querySelector('#txtSeasonFolderPattern').value;
value = value.replace('%s', '1').replace('%0s', '01').replace('%00s', '001');

value = value.replace('%sn', seriesName)
.replace('%s.n', seriesName.replace(' ', '.'))
.replace('%s_n', seriesName.replace(' ', '_'))
.replace('%sy', seriesYear)
.replace('%s', '1')
.replace('%0s', '01')
.replace('%00s', '001');

var replacementHtmlResult = 'Result: ' + value;

Expand Down
16 changes: 12 additions & 4 deletions Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ private async Task<Episode> GetMatchingEpisode(Series series,
&& e.IndexNumber == episodeNumber
&& e.IndexNumberEnd == endingEpiosdeNumber
&& e.LocationType == LocationType.FileSystem
&& Path.GetExtension(e.Path)==Path.GetExtension(result.OriginalPath));
&& Path.GetExtension(e.Path) == Path.GetExtension(result.OriginalPath));

if (episode == null)
{
Expand Down Expand Up @@ -954,6 +954,9 @@ private string GetSeasonFolderPath(Series series, int seasonNumber, TvFileOrgani
{
var path = series.Path;

var seriesName = series.Name.Trim();
var serieYear = series.ProductionYear;

if (ContainsEpisodesWithoutSeasonFolders(series))
{
return path;
Expand All @@ -965,9 +968,14 @@ private string GetSeasonFolderPath(Series series, int seasonNumber, TvFileOrgani
}

var seasonFolderName = options.SeasonFolderPattern
.Replace("%sn", seriesName)
.Replace("%s.n", seriesName.Replace(" ", "."))
.Replace("%s_n", seriesName.Replace(" ", "_"))
.Replace("%sy", serieYear.ToString())
.Replace("%s", seasonNumber.ToString(_usCulture))
.Replace("%0s", seasonNumber.ToString("00", _usCulture))
.Replace("%00s", seasonNumber.ToString("000", _usCulture));
.Replace("%00s", seasonNumber.ToString("000", _usCulture))
;

return Path.Combine(path, _fileSystem.GetValidFilename(seasonFolderName));
}
Expand All @@ -987,9 +995,9 @@ private bool ContainsEpisodesWithoutSeasonFolders(Series series)

private void SetEpisodeFileName(string sourcePath, Series series, Season season, Episode episode, TvFileOrganizationOptions options)
{
var seriesName = _fileSystem.GetValidFilename(series.Name).Trim();
var seriesName = series.Name.Trim();

var episodeTitle = _fileSystem.GetValidFilename(episode.Name).Trim();
var episodeTitle = episode.Name.Trim();

if (!episode.IndexNumber.HasValue || !season.IndexNumber.HasValue)
{
Expand Down

0 comments on commit 9dc5247

Please sign in to comment.