support multi-episode files from plex (#243)
* minor fallback metadata bug fixes * support multi-episode files from plex
This commit is contained in:
@@ -110,7 +110,8 @@ namespace ErsatzTV.Infrastructure.Plex
|
||||
IPlexServerApi service = XmlServiceFor(connection.Uri);
|
||||
return await service.GetSeasonChildren(season.Key.Split("/").Reverse().Skip(1).Head(), token.AuthToken)
|
||||
.Map(r => r.Metadata.Filter(m => m.Media.Count > 0 && m.Media[0].Part.Count > 0))
|
||||
.Map(list => list.Map(metadata => ProjectToEpisode(metadata, library.MediaSourceId)).ToList());
|
||||
.Map(list => list.Map(metadata => ProjectToEpisode(metadata, library.MediaSourceId)))
|
||||
.Map(ProcessMultiEpisodeFiles);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -118,6 +119,27 @@ namespace ErsatzTV.Infrastructure.Plex
|
||||
}
|
||||
}
|
||||
|
||||
private List<PlexEpisode> ProcessMultiEpisodeFiles(IEnumerable<PlexEpisode> episodes)
|
||||
{
|
||||
// add all metadata from duplicate paths to first entry with given path
|
||||
// i.e. s1e1 episode will add s1e2 metadata if s1e1 and s1e2 have same physical path
|
||||
var result = new Dictionary<string, PlexEpisode>();
|
||||
foreach (PlexEpisode episode in episodes.OrderBy(e => e.EpisodeMetadata.Head().EpisodeNumber))
|
||||
{
|
||||
string path = episode.MediaVersions.Head().MediaFiles.Head().Path;
|
||||
if (result.TryGetValue(path, out PlexEpisode existing))
|
||||
{
|
||||
existing.EpisodeMetadata.Add(episode.EpisodeMetadata.Head());
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(path, episode);
|
||||
}
|
||||
}
|
||||
|
||||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
public async Task<Either<BaseError, MovieMetadata>> GetMovieMetadata(
|
||||
PlexLibrary library,
|
||||
string key,
|
||||
|
||||
Reference in New Issue
Block a user