Skip to content

Commit c348065

Browse files
committed
fixes
1 parent 8cc1d2b commit c348065

File tree

4 files changed

+35
-48
lines changed

4 files changed

+35
-48
lines changed

CustomMetadataDB/Helpers/Utils.cs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public class Utils
2323
public static ILogger Logger { get; set; } = null;
2424

2525
public static PersonInfo CreatePerson(string name, string provider_id)
26-
2726
{
28-
return new PersonInfo
27+
return new()
2928
{
3029
Name = name,
3130
Type = PersonKind.Director,
@@ -80,11 +79,7 @@ public static MetadataResult<Series> ToSeries(DTO data)
8079
item.ProductionYear = int.Parse(date.ToString("yyyy"));
8180
}
8281

83-
return new MetadataResult<Series>
84-
{
85-
HasMetadata = true,
86-
Item = item
87-
};
82+
return new() { HasMetadata = true, Item = item };
8883
}
8984

9085
public static EpisodeInfo FileToInfo(string file, DateTime? file_date = null)
@@ -107,7 +102,7 @@ public static EpisodeInfo FileToInfo(string file, DateTime? file_date = null)
107102

108103
if (!matcher.Success)
109104
{
110-
Logger?.LogInformation($"No match found for {file}.");
105+
Logger?.LogError($"No match found for '{file}'.");
111106
return new EpisodeInfo();
112107
}
113108

@@ -162,7 +157,7 @@ public static EpisodeInfo FileToInfo(string file, DateTime? file_date = null)
162157
// get the modified date of the file
163158
if (System.IO.File.Exists(file) || file_date != null)
164159
{
165-
episode += (file_date ?? System.IO.File.GetLastWriteTimeUtc(file)).ToString("mmss");
160+
episode += (file_date ?? System.IO.File.GetCreationTimeUtc(file)).ToString("mmss");
166161
}
167162
}
168163

@@ -185,6 +180,14 @@ public static EpisodeInfo FileToInfo(string file, DateTime? file_date = null)
185180
item.PremiereDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));
186181
}
187182

183+
if (!item.IndexNumber.HasValue || item.IndexNumber.GetValueOrDefault() == 0)
184+
{
185+
Logger?.LogError($"No episode number found for '{file}'.");
186+
return new EpisodeInfo();
187+
}
188+
189+
Logger?.LogInformation($"Parsed '{System.IO.Path.GetFileName(file)}' as 'S{item.ParentIndexNumber}E{item.IndexNumber}' - {item.Name}'.");
190+
188191
return item;
189192
}
190193

@@ -211,7 +214,8 @@ public static MetadataResult<Episode> ToEpisode(EpisodeInfo data)
211214
{
212215
item.PremiereDate = time;
213216
item.ProductionYear = time.Year;
214-
item.ForcedSortName = time.ToString("yyyyMMdd") + '-' + item.Name;
217+
item.SortName = $"{time:yyyyMMdd}-{item.IndexNumber} -{item.Name}";
218+
item.ForcedSortName = $"{time:yyyyMMdd}-{item.IndexNumber} -{item.Name}";
215219
}
216220

217221
data.TryGetProviderId(Constants.PLUGIN_EXTERNAL_ID, out string id);
@@ -220,29 +224,10 @@ public static MetadataResult<Episode> ToEpisode(EpisodeInfo data)
220224
item.SetProviderId(Constants.PLUGIN_EXTERNAL_ID, id);
221225
}
222226

223-
return new MetadataResult<Episode>
224-
{
225-
HasMetadata = true,
226-
Item = item
227-
};
227+
return new() { HasMetadata = true, Item = item };
228228
}
229229

230-
private static MetadataResult<Series> ErrorOut()
231-
{
232-
return new MetadataResult<Series>
233-
{
234-
HasMetadata = false,
235-
Item = new Series()
236-
};
237-
}
238-
239-
private static MetadataResult<Episode> ErrorOutEpisode()
240-
{
241-
return new MetadataResult<Episode>
242-
{
243-
HasMetadata = false,
244-
Item = new Episode()
245-
};
246-
}
230+
private static MetadataResult<Series> ErrorOut() => new() { HasMetadata = false, Item = new Series() };
231+
private static MetadataResult<Episode> ErrorOutEpisode() => new() { HasMetadata = false, Item = new Episode() };
247232
}
248233
}

CustomMetadataDB/Provider/EpisodeProvider.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ public EpisodeProvider(ILogger<EpisodeProvider> logger)
2727

2828
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
2929
{
30-
_logger.LogDebug($"DEP HasChanged: {item.Path}");
31-
3230
FileSystemMetadata fileInfo = directoryService.GetFile(item.Path);
33-
var result = fileInfo.Exists && fileInfo.LastWriteTimeUtc.ToUniversalTime() > item.DateLastSaved.ToUniversalTime();
3431

35-
string status = result ? "Has Changed" : "Has Not Changed";
32+
if (false == fileInfo.Exists)
33+
{
34+
_logger.LogWarning($"CMD HasChanged: '{item.Path}' not found.");
35+
return true;
36+
}
3637

37-
_logger.LogDebug($"DEP HasChanged Result: {status}");
38+
if (fileInfo.LastWriteTimeUtc.ToUniversalTime() > item.DateLastSaved.ToUniversalTime())
39+
{
40+
_logger.LogInformation($"CMD HasChanged: '{item.Path}' has changed");
41+
return true;
42+
}
3843

39-
return result;
44+
return false;
4045
}
4146

4247
public Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)

CustomMetadataDB/Provider/SeasonProvider.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,18 @@ public SeasonProvider(ILogger<SeasonProvider> logger)
2424

2525
public Task<MetadataResult<Season>> GetMetadata(SeasonInfo info, CancellationToken cancellationToken)
2626
{
27-
_logger.LogDebug($"CMD Season GetMetadata: {JsonSerializer.Serialize(info)}");
28-
27+
_logger.LogInformation($"CMD Season GetMetadata: {JsonSerializer.Serialize(info)}");
2928
cancellationToken.ThrowIfCancellationRequested();
3029

31-
var result = new MetadataResult<Season>
30+
return Task.FromResult(new MetadataResult<Season>
3231
{
3332
HasMetadata = true,
3433
Item = new Season
3534
{
3635
Name = info.Name,
3736
IndexNumber = info.IndexNumber
3837
}
39-
};
40-
41-
return Task.FromResult(result);
38+
});
4239
}
4340

4441
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeasonInfo searchInfo, CancellationToken cancellationToken) => throw new NotImplementedException();

CustomMetadataDB/Provider/SeriesProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, Cancellat
4343
{
4444
using var httpResponse = await QueryAPI("series", info.Name, cancellationToken).ConfigureAwait(false);
4545

46-
if (httpResponse.StatusCode != HttpStatusCode.OK)
46+
if (HttpStatusCode.OK != httpResponse.StatusCode)
4747
{
48-
_logger.LogInformation($"CMD Series GetMetadata: {info.Name} ({info.Path}) - Status Code: {httpResponse.StatusCode}");
48+
_logger.LogError($"CMD Series GetMetadata: '{info.Name}' '{info.Path}' - Status Code: {httpResponse.StatusCode}");
4949
return result;
5050
}
5151

@@ -81,9 +81,9 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo s
8181
{
8282
using var httpResponse = await QueryAPI("series", searchInfo.Name, cancellationToken, limit: 20).ConfigureAwait(false);
8383

84-
if (httpResponse.StatusCode != HttpStatusCode.OK)
84+
if (HttpStatusCode.OK != httpResponse.StatusCode)
8585
{
86-
_logger.LogInformation($"CMD Series GetMetadata: {searchInfo.Name} ({searchInfo.Path}) - Status Code: {httpResponse.StatusCode}");
86+
_logger.LogInformation($"CMD Series GetMetadata: '{searchInfo.Name}' '{searchInfo.Path}' - Status Code: {httpResponse.StatusCode}");
8787
return result;
8888
}
8989

0 commit comments

Comments
 (0)