@ -14,16 +14,10 @@ using Refit;
namespace ErsatzTV.Infrastructure.Plex ;
namespace ErsatzTV.Infrastructure.Plex ;
public class PlexServerApiClient : IPlexServerApiClient
public class PlexServerApiClient ( PlexEtag plexEtag , ILogger < PlexServerApiClient > logger ) : IPlexServerApiClient
{
{
private readonly ILogger < PlexServerApiClient > _l ogger ;
private const string PersonalMediaAgent = "com.plexapp.agents.none" ;
private readonly PlexEtag _ plexEtag ;
private const string PlexPersonalMediaAgent = "tv.plex.agents.none" ;
public PlexServerApiClient ( PlexEtag plexEtag , ILogger < PlexServerApiClient > logger )
{
_ plexEtag = plexEtag ;
_l ogger = logger ;
}
public async Task < bool > Ping (
public async Task < bool > Ping (
PlexConnection connection ,
PlexConnection connection ,
@ -537,7 +531,7 @@ public class PlexServerApiClient : IPlexServerApiClient
{
{
Key = response . Key ,
Key = response . Key ,
Name = response . Title ,
Name = response . Title ,
MediaKind = response . Agent = = "com.plexapp.agents.none" & & response . Language = = "xn"
MediaKind = response . Agent is PersonalMediaAgent or PlexPersonalMediaAgent
? LibraryMediaKind . OtherVideos
? LibraryMediaKind . OtherVideos
: LibraryMediaKind . Movies ,
: LibraryMediaKind . Movies ,
ShouldSyncItems = false ,
ShouldSyncItems = false ,
@ -565,13 +559,13 @@ public class PlexServerApiClient : IPlexServerApiClient
return new PlexCollection
return new PlexCollection
{
{
Key = item . RatingKey ,
Key = item . RatingKey ,
Etag = _ plexEtag . ForCollection ( item ) ,
Etag = plexEtag . ForCollection ( item ) ,
Name = item . Title
Name = item . Title
} ;
} ;
}
}
catch ( Exception ex )
catch ( Exception ex )
{
{
_l ogger . LogWarning ( ex , "Error projecting Plex collection" ) ;
l ogger. LogWarning ( ex , "Error projecting Plex collection" ) ;
return None ;
return None ;
}
}
}
}
@ -591,7 +585,7 @@ public class PlexServerApiClient : IPlexServerApiClient
}
}
catch ( Exception ex )
catch ( Exception ex )
{
{
_l ogger . LogWarning ( ex , "Error projecting Plex collection media item" ) ;
l ogger. LogWarning ( ex , "Error projecting Plex collection media item" ) ;
return None ;
return None ;
}
}
}
}
@ -610,7 +604,7 @@ public class PlexServerApiClient : IPlexServerApiClient
}
}
catch ( Exception ex )
catch ( Exception ex )
{
{
_l ogger . LogWarning ( ex , "Error projecting Plex tag" ) ;
l ogger. LogWarning ( ex , "Error projecting Plex tag" ) ;
return None ;
return None ;
}
}
}
}
@ -651,7 +645,7 @@ public class PlexServerApiClient : IPlexServerApiClient
var movie = new PlexMovie
var movie = new PlexMovie
{
{
Etag = _ plexEtag . ForMovie ( response ) ,
Etag = plexEtag . ForMovie ( response ) ,
Key = response . Key ,
Key = response . Key ,
MovieMetadata = [ metadata ] ,
MovieMetadata = [ metadata ] ,
MediaVersions = [ version ] ,
MediaVersions = [ version ] ,
@ -884,7 +878,7 @@ public class PlexServerApiClient : IPlexServerApiClient
var show = new PlexShow
var show = new PlexShow
{
{
Key = response . Key ,
Key = response . Key ,
Etag = _ plexEtag . ForShow ( response ) ,
Etag = plexEtag . ForShow ( response ) ,
ShowMetadata = new List < ShowMetadata > { metadata } ,
ShowMetadata = new List < ShowMetadata > { metadata } ,
TraktListItems = new List < TraktListItem > ( )
TraktListItems = new List < TraktListItem > ( )
} ;
} ;
@ -1046,7 +1040,7 @@ public class PlexServerApiClient : IPlexServerApiClient
var season = new PlexSeason
var season = new PlexSeason
{
{
Key = response . Key ,
Key = response . Key ,
Etag = _ plexEtag . ForSeason ( response ) ,
Etag = plexEtag . ForSeason ( response ) ,
SeasonNumber = response . Index ,
SeasonNumber = response . Index ,
SeasonMetadata = new List < SeasonMetadata > { metadata } ,
SeasonMetadata = new List < SeasonMetadata > { metadata } ,
TraktListItems = new List < TraktListItem > ( )
TraktListItems = new List < TraktListItem > ( )
@ -1092,7 +1086,7 @@ public class PlexServerApiClient : IPlexServerApiClient
var episode = new PlexEpisode
var episode = new PlexEpisode
{
{
Key = response . Key ,
Key = response . Key ,
Etag = _ plexEtag . ForEpisode ( response ) ,
Etag = plexEtag . ForEpisode ( response ) ,
EpisodeMetadata = [ metadata ] ,
EpisodeMetadata = [ metadata ] ,
MediaVersions = [ version ] ,
MediaVersions = [ version ] ,
TraktListItems = [ ]
TraktListItems = [ ]
@ -1238,7 +1232,7 @@ public class PlexServerApiClient : IPlexServerApiClient
var otherVideo = new PlexOtherVideo
var otherVideo = new PlexOtherVideo
{
{
Etag = _ plexEtag . ForMovie ( response ) ,
Etag = plexEtag . ForMovie ( response ) ,
Key = response . Key ,
Key = response . Key ,
OtherVideoMetadata = [ metadata ] ,
OtherVideoMetadata = [ metadata ] ,
MediaVersions = [ version ] ,
MediaVersions = [ version ] ,
@ -1431,7 +1425,7 @@ public class PlexServerApiClient : IPlexServerApiClient
}
}
else
else
{
{
_l ogger . LogWarning ( "Unsupported guid format from Plex; ignoring: {Guid}" , guid ) ;
l ogger. LogWarning ( "Unsupported guid format from Plex; ignoring: {Guid}" , guid ) ;
}
}
return None ;
return None ;