aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Gillen <thomas.gillen@googlemail.com>2015-09-19 23:56:59 +0100
committerThomas Gillen <thomas.gillen@googlemail.com>2015-09-19 23:56:59 +0100
commit6d25610d533798f07aa5dae3bffca22cd550ce95 (patch)
treeb8b6fec1fa6ff45483239d766aa7e3d1ea5315c3
parent556b34d0005dce04d6a798334fd37ba284cef3fd (diff)
Fix not initialising structs properly
-rw-r--r--MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs100
-rw-r--r--MediaBrowser.Providers/TV/TvdbSeasonIdentityProvider.cs7
2 files changed, 57 insertions, 50 deletions
diff --git a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs
index 0fda7edae..ec713064e 100644
--- a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs
+++ b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs
@@ -48,12 +48,12 @@ namespace MediaBrowser.Providers.TV
{
var list = new List<RemoteSearchResult>();
- var identity = ParseIdentity(searchInfo.GetProviderId(FullIdKey));
+ var identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
if (identity == null)
{
await Identify(searchInfo).ConfigureAwait(false);
- identity = ParseIdentity(searchInfo.GetProviderId(FullIdKey));
+ identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
}
if (identity != null)
@@ -104,12 +104,12 @@ namespace MediaBrowser.Providers.TV
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
- var identity = ParseIdentity(searchInfo.GetProviderId(FullIdKey));
+ var identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
if (identity == null)
{
await Identify(searchInfo).ConfigureAwait(false);
- identity = ParseIdentity(searchInfo.GetProviderId(FullIdKey));
+ identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
}
var result = new MetadataResult<Episode>();
@@ -783,71 +783,71 @@ namespace MediaBrowser.Providers.TV
return Task.FromResult<object>(null);
}
- var number = info.IndexNumber.Value.ToString();
- if (info.IndexNumberEnd != null)
- number += "-" + info.IndexNumberEnd;
-
- var id = string.Format(
- FullIdFormat,
- seriesTvdbId,
- info.ParentIndexNumber.HasValue ? info.ParentIndexNumber.Value.ToString() : "A",
- number);
-
- info.SetProviderId(FullIdKey, FullIdFormat);
+ var id = new Identity(seriesTvdbId, info.ParentIndexNumber, info.IndexNumber.Value, info.IndexNumberEnd);
+ info.SetProviderId(FullIdKey, id.ToString());
return Task.FromResult(id);
}
- private Identity? ParseIdentity(string id)
- {
- if (string.IsNullOrEmpty(id))
- return null;
-
- try
- {
- var parts = id.Split(':');
- var series = parts[0];
- var season = parts[1] != "A" ? (int?) int.Parse(parts[1]) : null;
-
- int index;
- int? indexEnd;
-
- if (parts[2].Contains("-"))
- {
- var split = parts[2].IndexOf("-", StringComparison.OrdinalIgnoreCase);
- index = int.Parse(parts[2].Substring(0, split));
- indexEnd = int.Parse(parts[2].Substring(split + 1));
- }
- else
- {
- index = int.Parse(parts[2]);
- indexEnd = null;
- }
-
- return new Identity(series, season, index, indexEnd);
- }
- catch
- {
- return null;
- }
- }
-
public int Order { get { return 0; } }
- private struct Identity
+ public struct Identity
{
public string SeriesId { get; private set; }
public int? SeasonIndex { get; private set; }
public int EpisodeNumber { get; private set; }
public int? EpisodeNumberEnd { get; private set; }
+ public Identity(string id)
+ : this()
+ {
+ this = ParseIdentity(id).Value;
+ }
+
public Identity(string seriesId, int? seasonIndex, int episodeNumber, int? episodeNumberEnd)
+ : this()
{
SeriesId = seriesId;
SeasonIndex = seasonIndex;
EpisodeNumber = episodeNumber;
EpisodeNumberEnd = episodeNumberEnd;
}
+
+ public override string ToString()
+ {
+ return string.Format("{0}:{1}:{2}",
+ SeriesId,
+ SeasonIndex != null ? SeasonIndex.Value.ToString() : "A",
+ EpisodeNumber + (EpisodeNumberEnd != null ? "-" + EpisodeNumberEnd.Value.ToString() : ""));
+ }
+
+ public static Identity? ParseIdentity(string id)
+ {
+ if (string.IsNullOrEmpty(id))
+ return null;
+
+ try {
+ var parts = id.Split(':');
+ var series = parts[0];
+ var season = parts[1] != "A" ? (int?)int.Parse(parts[1]) : null;
+
+ int index;
+ int? indexEnd;
+
+ if (parts[2].Contains("-")) {
+ var split = parts[2].IndexOf("-", StringComparison.OrdinalIgnoreCase);
+ index = int.Parse(parts[2].Substring(0, split));
+ indexEnd = int.Parse(parts[2].Substring(split + 1));
+ } else {
+ index = int.Parse(parts[2]);
+ indexEnd = null;
+ }
+
+ return new Identity(series, season, index, indexEnd);
+ } catch {
+ return null;
+ }
+ }
}
}
}
diff --git a/MediaBrowser.Providers/TV/TvdbSeasonIdentityProvider.cs b/MediaBrowser.Providers/TV/TvdbSeasonIdentityProvider.cs
index 3f95c18b9..edeea36e4 100644
--- a/MediaBrowser.Providers/TV/TvdbSeasonIdentityProvider.cs
+++ b/MediaBrowser.Providers/TV/TvdbSeasonIdentityProvider.cs
@@ -44,7 +44,14 @@ namespace MediaBrowser.Providers.TV
public string SeriesId { get; private set; }
public int Index { get; private set; }
+ public TvdbSeasonIdentity(string id)
+ : this()
+ {
+ this = TvdbSeasonIdentityProvider.ParseIdentity(id).Value;
+ }
+
public TvdbSeasonIdentity(string seriesId, int index)
+ : this()
{
SeriesId = seriesId;
Index = index;