@ -14,8 +14,9 @@ using System.Text;
using System.Text.Json ;
using System.Threading ;
using System.Threading.Tasks ;
using MediaBrowser.Common ;
using Emby.Server.Implementations.LiveTv.Listings.SchedulesDirectDtos ;
using Jellyfin.Extensions.Json ;
using MediaBrowser.Common ;
using MediaBrowser.Common.Net ;
using MediaBrowser.Controller.LiveTv ;
using MediaBrowser.Model.Cryptography ;
@ -96,12 +97,12 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var dates = GetScheduleRequestDates ( startDateUtc , endDateUtc ) ;
_logger . LogInformation ( "Channel Station ID is: {ChannelID}" , channelId ) ;
var requestList = new List < ScheduleDirect. RequestScheduleForChannel> ( )
var requestList = new List < RequestScheduleForChannelDto > ( )
{
new ScheduleDirect. RequestScheduleForChannel( )
new RequestScheduleForChannelDto ( )
{
stationID = channelId ,
d ate = dates
StationId = channelId ,
D ate = dates
}
} ;
@ -113,61 +114,61 @@ namespace Emby.Server.Implementations.LiveTv.Listings
options . Headers . TryAddWithoutValidation ( "token" , token ) ;
using var response = await Send ( options , true , info , cancellationToken ) . ConfigureAwait ( false ) ;
await using var responseStream = await response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
var dailySchedules = await JsonSerializer . DeserializeAsync < List < ScheduleDirect. Day> > ( responseStream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
var dailySchedules = await JsonSerializer . DeserializeAsync < List < DayDto > > ( responseStream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
_logger . LogDebug ( "Found {ScheduleCount} programs on {ChannelID} ScheduleDirect" , dailySchedules . Count , channelId ) ;
using var programRequestOptions = new HttpRequestMessage ( HttpMethod . Post , ApiUrl + "/programs" ) ;
programRequestOptions . Headers . TryAddWithoutValidation ( "token" , token ) ;
var programsID = dailySchedules . SelectMany ( d = > d . programs. Select ( s = > s . programID ) ) . Distinct ( ) ;
var programsID = dailySchedules . SelectMany ( d = > d . Programs. Select ( s = > s . ProgramId ) ) . Distinct ( ) ;
programRequestOptions . Content = new StringContent ( "[\"" + string . Join ( "\", \"" , programsID ) + "\"]" , Encoding . UTF8 , MediaTypeNames . Application . Json ) ;
using var innerResponse = await Send ( programRequestOptions , true , info , cancellationToken ) . ConfigureAwait ( false ) ;
await using var innerResponseStream = await innerResponse . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
var programDetails = await JsonSerializer . DeserializeAsync < List < ScheduleDirect. ProgramDetails> > ( innerResponseStream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
var programDict = programDetails . ToDictionary ( p = > p . programID , y = > y ) ;
var programDetails = await JsonSerializer . DeserializeAsync < List < ProgramDetailsDto > > ( innerResponseStream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
var programDict = programDetails . ToDictionary ( p = > p . ProgramId , y = > y ) ;
var programIdsWithImages = programDetails
. Where ( p = > p . h asImageArtwork) . Select ( p = > p . programID )
. Where ( p = > p . H asImageArtwork) . Select ( p = > p . ProgramId )
. ToList ( ) ;
var images = await GetImageForPrograms ( info , programIdsWithImages , cancellationToken ) . ConfigureAwait ( false ) ;
var programsInfo = new List < ProgramInfo > ( ) ;
foreach ( ScheduleDirect. Program schedule in dailySchedules . SelectMany ( d = > d . p rograms) )
foreach ( ProgramDto schedule in dailySchedules . SelectMany ( d = > d . P rograms) )
{
// _logger.LogDebug("Proccesing Schedule for statio ID " + stationID +
// " which corresponds to channel " + channelNumber + " and program id " +
// schedule. programID + " which says it has images? " +
// programDict[schedule. programID ].hasImageArtwork);
// schedule. ProgramId + " which says it has images? " +
// programDict[schedule. ProgramId ].hasImageArtwork);
if ( images ! = null )
{
var imageIndex = images . FindIndex ( i = > i . programID = = schedule . programID . Substring ( 0 , 10 ) ) ;
var imageIndex = images . FindIndex ( i = > i . ProgramId = = schedule . ProgramId [ . . 10 ] ) ;
if ( imageIndex > - 1 )
{
var programEntry = programDict [ schedule . programID ] ;
var programEntry = programDict [ schedule . ProgramId ] ;
var allImages = images [ imageIndex ] . d ata ? ? new List < ScheduleDirect. ImageData> ( ) ;
var imagesWithText = allImages . Where ( i = > string . Equals ( i . t ext, "yes" , StringComparison . OrdinalIgnoreCase ) ) ;
var imagesWithoutText = allImages . Where ( i = > string . Equals ( i . t ext, "no" , StringComparison . OrdinalIgnoreCase ) ) ;
var allImages = images [ imageIndex ] . D ata ? ? new List < ImageDataDto > ( ) ;
var imagesWithText = allImages . Where ( i = > string . Equals ( i . T ext, "yes" , StringComparison . OrdinalIgnoreCase ) ) ;
var imagesWithoutText = allImages . Where ( i = > string . Equals ( i . T ext, "no" , StringComparison . OrdinalIgnoreCase ) ) ;
const double DesiredAspect = 2.0 / 3 ;
programEntry . p rimaryImage = GetProgramImage ( ApiUrl , imagesWithText , true , DesiredAspect ) ? ?
programEntry . P rimaryImage = GetProgramImage ( ApiUrl , imagesWithText , true , DesiredAspect ) ? ?
GetProgramImage ( ApiUrl , allImages , true , DesiredAspect ) ;
const double WideAspect = 16.0 / 9 ;
programEntry . t humbImage = GetProgramImage ( ApiUrl , imagesWithText , true , WideAspect ) ;
programEntry . T humbImage = GetProgramImage ( ApiUrl , imagesWithText , true , WideAspect ) ;
// Don't supply the same image twice
if ( string . Equals ( programEntry . primaryImage, programEntry . t humbImage, StringComparison . Ordinal ) )
if ( string . Equals ( programEntry . PrimaryImage, programEntry . T humbImage, StringComparison . Ordinal ) )
{
programEntry . t humbImage = null ;
programEntry . T humbImage = null ;
}
programEntry . b ackdropImage = GetProgramImage ( ApiUrl , imagesWithoutText , true , WideAspect ) ;
programEntry . B ackdropImage = GetProgramImage ( ApiUrl , imagesWithoutText , true , WideAspect ) ;
// programEntry.bannerImage = GetProgramImage(ApiUrl, data, "Banner", false) ??
// GetProgramImage(ApiUrl, data, "Banner-L1", false) ??
@ -176,15 +177,15 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
programsInfo . Add ( GetProgram ( channelId , schedule , programDict [ schedule . programID ] ) ) ;
programsInfo . Add ( GetProgram ( channelId , schedule , programDict [ schedule . ProgramId ] ) ) ;
}
return programsInfo ;
}
private static int GetSizeOrder ( ScheduleDirect. ImageData image )
private static int GetSizeOrder ( ImageDataDto image )
{
if ( int . TryParse ( image . h eight, out int value ) )
if ( int . TryParse ( image . H eight, out int value ) )
{
return value ;
}
@ -192,53 +193,53 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return 0 ;
}
private static string GetChannelNumber ( ScheduleDirect. Map map )
private static string GetChannelNumber ( MapDto map )
{
var channelNumber = map . l ogicalChannelNumber;
var channelNumber = map . L ogicalChannelNumber;
if ( string . IsNullOrWhiteSpace ( channelNumber ) )
{
channelNumber = map . c hannel;
channelNumber = map . C hannel;
}
if ( string . IsNullOrWhiteSpace ( channelNumber ) )
{
channelNumber = map . atscMajor + "." + map . a tscMinor;
channelNumber = map . AtscMajor + "." + map . A tscMinor;
}
return channelNumber . TrimStart ( '0' ) ;
}
private static bool IsMovie ( ScheduleDirect. ProgramDetails programInfo )
private static bool IsMovie ( ProgramDetailsDto programInfo )
{
return string . Equals ( programInfo . e ntityType, "movie" , StringComparison . OrdinalIgnoreCase ) ;
return string . Equals ( programInfo . E ntityType, "movie" , StringComparison . OrdinalIgnoreCase ) ;
}
private ProgramInfo GetProgram ( string channelId , ScheduleDirect. Program programInfo , ScheduleDirect. ProgramDetails details )
private ProgramInfo GetProgram ( string channelId , ProgramDto programInfo , ProgramDetailsDto details )
{
var startAt = GetDate ( programInfo . a irDateTime) ;
var endAt = startAt . AddSeconds ( programInfo . d uration) ;
var startAt = GetDate ( programInfo . A irDateTime) ;
var endAt = startAt . AddSeconds ( programInfo . D uration) ;
var audioType = ProgramAudio . Stereo ;
var programId = programInfo . programID ? ? string . Empty ;
var programId = programInfo . ProgramId ? ? string . Empty ;
string newID = programId + "T" + startAt . Ticks + "C" + channelId ;
if ( programInfo . a udioProperties ! = null )
if ( programInfo . A udioProperties ! = null )
{
if ( programInfo . a udioProperties. Exists ( item = > string . Equals ( item , "atmos" , StringComparison . OrdinalIgnoreCase ) ) )
if ( programInfo . A udioProperties. Exists ( item = > string . Equals ( item , "atmos" , StringComparison . OrdinalIgnoreCase ) ) )
{
audioType = ProgramAudio . Atmos ;
}
else if ( programInfo . a udioProperties. Exists ( item = > string . Equals ( item , "dd 5.1" , StringComparison . OrdinalIgnoreCase ) ) )
else if ( programInfo . A udioProperties. Exists ( item = > string . Equals ( item , "dd 5.1" , StringComparison . OrdinalIgnoreCase ) ) )
{
audioType = ProgramAudio . DolbyDigital ;
}
else if ( programInfo . a udioProperties. Exists ( item = > string . Equals ( item , "dd" , StringComparison . OrdinalIgnoreCase ) ) )
else if ( programInfo . A udioProperties. Exists ( item = > string . Equals ( item , "dd" , StringComparison . OrdinalIgnoreCase ) ) )
{
audioType = ProgramAudio . DolbyDigital ;
}
else if ( programInfo . a udioProperties. Exists ( item = > string . Equals ( item , "stereo" , StringComparison . OrdinalIgnoreCase ) ) )
else if ( programInfo . A udioProperties. Exists ( item = > string . Equals ( item , "stereo" , StringComparison . OrdinalIgnoreCase ) ) )
{
audioType = ProgramAudio . Stereo ;
}
@ -249,9 +250,9 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
string episodeTitle = null ;
if ( details . e pisodeTitle150 ! = null )
if ( details . E pisodeTitle150 ! = null )
{
episodeTitle = details . e pisodeTitle150;
episodeTitle = details . E pisodeTitle150;
}
var info = new ProgramInfo
@ -260,22 +261,22 @@ namespace Emby.Server.Implementations.LiveTv.Listings
Id = newID ,
StartDate = startAt ,
EndDate = endAt ,
Name = details . titles[ 0 ] . t itle120 ? ? "Unknown" ,
Name = details . Titles[ 0 ] . T itle120 ? ? "Unknown" ,
OfficialRating = null ,
CommunityRating = null ,
EpisodeTitle = episodeTitle ,
Audio = audioType ,
// IsNew = programInfo.@new ?? false,
IsRepeat = programInfo . @n ew = = null ,
IsSeries = string . Equals ( details . e ntityType, "episode" , StringComparison . OrdinalIgnoreCase ) ,
ImageUrl = details . p rimaryImage,
ThumbImageUrl = details . t humbImage,
IsKids = string . Equals ( details . a udience, "children" , StringComparison . OrdinalIgnoreCase ) ,
IsSports = string . Equals ( details . e ntityType, "sports" , StringComparison . OrdinalIgnoreCase ) ,
IsRepeat = programInfo . N ew = = null ,
IsSeries = string . Equals ( details . E ntityType, "episode" , StringComparison . OrdinalIgnoreCase ) ,
ImageUrl = details . P rimaryImage,
ThumbImageUrl = details . T humbImage,
IsKids = string . Equals ( details . A udience, "children" , StringComparison . OrdinalIgnoreCase ) ,
IsSports = string . Equals ( details . E ntityType, "sports" , StringComparison . OrdinalIgnoreCase ) ,
IsMovie = IsMovie ( details ) ,
Etag = programInfo . m d5,
IsLive = string . Equals ( programInfo . l iveTapeDelay, "live" , StringComparison . OrdinalIgnoreCase ) ,
IsPremiere = programInfo . premiere | | ( programInfo . i sPremiereOrFinale ? ? string . Empty ) . IndexOf ( "premiere" , StringComparison . OrdinalIgnoreCase ) ! = - 1
Etag = programInfo . M d5,
IsLive = string . Equals ( programInfo . L iveTapeDelay, "live" , StringComparison . OrdinalIgnoreCase ) ,
IsPremiere = programInfo . Premiere | | ( programInfo . I sPremiereOrFinale ? ? string . Empty ) . IndexOf ( "premiere" , StringComparison . OrdinalIgnoreCase ) ! = - 1
} ;
var showId = programId ;
@ -298,15 +299,15 @@ namespace Emby.Server.Implementations.LiveTv.Listings
info . ShowId = showId ;
if ( programInfo . v ideoProperties ! = null )
if ( programInfo . V ideoProperties ! = null )
{
info . IsHD = programInfo . v ideoProperties. Contains ( "hdtv" , StringComparer . OrdinalIgnoreCase ) ;
info . Is3D = programInfo . v ideoProperties. Contains ( "3d" , StringComparer . OrdinalIgnoreCase ) ;
info . IsHD = programInfo . V ideoProperties. Contains ( "hdtv" , StringComparer . OrdinalIgnoreCase ) ;
info . Is3D = programInfo . V ideoProperties. Contains ( "3d" , StringComparer . OrdinalIgnoreCase ) ;
}
if ( details . c ontentRating ! = null & & details . c ontentRating. Count > 0 )
if ( details . C ontentRating ! = null & & details . C ontentRating. Count > 0 )
{
info . OfficialRating = details . contentRating[ 0 ] . c ode. Replace ( "TV" , "TV-" , StringComparison . Ordinal )
info . OfficialRating = details . ContentRating[ 0 ] . C ode. Replace ( "TV" , "TV-" , StringComparison . Ordinal )
. Replace ( "--" , "-" , StringComparison . Ordinal ) ;
var invalid = new [ ] { "N/A" , "Approved" , "Not Rated" , "Passed" } ;
@ -316,15 +317,15 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
if ( details . d escriptions ! = null )
if ( details . D escriptions ! = null )
{
if ( details . descriptions. d escription1000 ! = null & & details . descriptions. d escription1000. Count > 0 )
if ( details . Descriptions. D escription1000 ! = null & & details . Descriptions. D escription1000. Count > 0 )
{
info . Overview = details . descriptions. description1000 [ 0 ] . d escription;
info . Overview = details . Descriptions. Description1000 [ 0 ] . D escription;
}
else if ( details . descriptions. d escription100 ! = null & & details . descriptions. d escription100. Count > 0 )
else if ( details . Descriptions. D escription100 ! = null & & details . Descriptions. D escription100. Count > 0 )
{
info . Overview = details . descriptions. description100 [ 0 ] . d escription;
info . Overview = details . Descriptions. Description100 [ 0 ] . D escription;
}
}
@ -334,18 +335,18 @@ namespace Emby.Server.Implementations.LiveTv.Listings
info . SeriesProviderIds [ MetadataProvider . Zap2It . ToString ( ) ] = info . SeriesId ;
if ( details . m etadata ! = null )
if ( details . M etadata ! = null )
{
foreach ( var metadataProgram in details . m etadata)
foreach ( var metadataProgram in details . M etadata)
{
var gracenote = metadataProgram . Gracenote ;
if ( gracenote ! = null )
{
info . SeasonNumber = gracenote . s eason;
info . SeasonNumber = gracenote . S eason;
if ( gracenote . e pisode > 0 )
if ( gracenote . E pisode > 0 )
{
info . EpisodeNumber = gracenote . e pisode;
info . EpisodeNumber = gracenote . E pisode;
}
break ;
@ -354,25 +355,25 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
if ( ! string . IsNullOrWhiteSpace ( details . o riginalAirDate) )
if ( ! string . IsNullOrWhiteSpace ( details . O riginalAirDate) )
{
info . OriginalAirDate = DateTime . Parse ( details . o riginalAirDate, CultureInfo . InvariantCulture ) ;
info . OriginalAirDate = DateTime . Parse ( details . O riginalAirDate, CultureInfo . InvariantCulture ) ;
info . ProductionYear = info . OriginalAirDate . Value . Year ;
}
if ( details . m ovie ! = null )
if ( details . M ovie ! = null )
{
if ( ! string . IsNullOrEmpty ( details . movie. y ear)
& & int . TryParse ( details . movie. y ear, out int year ) )
if ( ! string . IsNullOrEmpty ( details . Movie. Y ear)
& & int . TryParse ( details . Movie. Y ear, out int year ) )
{
info . ProductionYear = year ;
}
}
if ( details . g enres ! = null )
if ( details . G enres ! = null )
{
info . Genres = details . g enres. Where ( g = > ! string . IsNullOrWhiteSpace ( g ) ) . ToList ( ) ;
info . IsNews = details . g enres. Contains ( "news" , StringComparer . OrdinalIgnoreCase ) ;
info . Genres = details . G enres. Where ( g = > ! string . IsNullOrWhiteSpace ( g ) ) . ToList ( ) ;
info . IsNews = details . G enres. Contains ( "news" , StringComparer . OrdinalIgnoreCase ) ;
if ( info . Genres . Contains ( "children" , StringComparer . OrdinalIgnoreCase ) )
{
@ -395,11 +396,11 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return date ;
}
private string GetProgramImage ( string apiUrl , IEnumerable < ScheduleDirect. ImageData> images , bool returnDefaultImage , double desiredAspect )
private string GetProgramImage ( string apiUrl , IEnumerable < ImageDataDto > images , bool returnDefaultImage , double desiredAspect )
{
var match = images
. OrderBy ( i = > Math . Abs ( desiredAspect - GetAspectRatio ( i ) ) )
. ThenByDescending ( GetSizeOrder)
. ThenByDescending ( i = > GetSizeOrder( i ) )
. FirstOrDefault ( ) ;
if ( match = = null )
@ -407,7 +408,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return null ;
}
var uri = match . u ri;
var uri = match . U ri;
if ( string . IsNullOrWhiteSpace ( uri ) )
{
@ -423,19 +424,19 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
private static double GetAspectRatio ( ScheduleDirect. ImageData i )
private static double GetAspectRatio ( ImageDataDto i )
{
int width = 0 ;
int height = 0 ;
if ( ! string . IsNullOrWhiteSpace ( i . w idth) )
if ( ! string . IsNullOrWhiteSpace ( i . W idth) )
{
int . TryParse ( i . w idth, out width ) ;
_ = int . TryParse ( i . W idth, out width ) ;
}
if ( ! string . IsNullOrWhiteSpace ( i . h eight) )
if ( ! string . IsNullOrWhiteSpace ( i . H eight) )
{
int . TryParse ( i . h eight, out height ) ;
_ = int . TryParse ( i . H eight, out height ) ;
}
if ( height = = 0 | | width = = 0 )
@ -448,14 +449,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return result ;
}
private async Task < List < S cheduleDirect. S howImages> > GetImageForPrograms (
private async Task < List < S howImagesDto > > GetImageForPrograms (
ListingsProviderInfo info ,
IReadOnlyList < string > programIds ,
CancellationToken cancellationToken )
{
if ( programIds . Count = = 0 )
{
return new List < S cheduleDirect. S howImages> ( ) ;
return new List < S howImagesDto > ( ) ;
}
StringBuilder str = new StringBuilder ( "[" , 1 + ( programIds . Count * 13 ) ) ;
@ -479,13 +480,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
{
using var innerResponse2 = await Send ( message , true , info , cancellationToken ) . ConfigureAwait ( false ) ;
await using var response = await innerResponse2 . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
return await JsonSerializer . DeserializeAsync < List < S cheduleDirect. S howImages> > ( response , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
return await JsonSerializer . DeserializeAsync < List < S howImagesDto > > ( response , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
}
catch ( Exception ex )
{
_logger . LogError ( ex , "Error getting image info from schedules direct" ) ;
return new List < S cheduleDirect. S howImages> ( ) ;
return new List < S howImagesDto > ( ) ;
}
}
@ -508,18 +509,18 @@ namespace Emby.Server.Implementations.LiveTv.Listings
using var httpResponse = await Send ( options , false , info , cancellationToken ) . ConfigureAwait ( false ) ;
await using var response = await httpResponse . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
var root = await JsonSerializer . DeserializeAsync < List < ScheduleDirect. Headends> > ( response , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
var root = await JsonSerializer . DeserializeAsync < List < HeadendsDto > > ( response , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
if ( root ! = null )
{
foreach ( ScheduleDirect. Headends headend in root )
foreach ( HeadendsDto headend in root )
{
foreach ( ScheduleDirect. Lineup lineup in headend . l ineups)
foreach ( LineupDto lineup in headend . L ineups)
{
lineups . Add ( new NameIdPair
{
Name = string . IsNullOrWhiteSpace ( lineup . name) ? lineup . lineup : lineup . n ame,
Id = lineup . uri. Substring ( 18 )
Name = string . IsNullOrWhiteSpace ( lineup . Name) ? lineup . Lineup : lineup . N ame,
Id = lineup . Uri[ 18. . ]
} ) ;
}
}
@ -649,14 +650,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
using var response = await Send ( options , false , null , cancellationToken ) . ConfigureAwait ( false ) ;
response . EnsureSuccessStatusCode ( ) ;
await using var stream = await response . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
var root = await JsonSerializer . DeserializeAsync < ScheduleDirect. Token> ( stream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
if ( string . Equals ( root . m essage, "OK" , StringComparison . Ordinal ) )
var root = await JsonSerializer . DeserializeAsync < TokenDto > ( stream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
if ( string . Equals ( root . M essage, "OK" , StringComparison . Ordinal ) )
{
_logger . LogInformation ( "Authenticated with Schedules Direct token: " + root . t oken) ;
return root . t oken;
_logger . LogInformation ( "Authenticated with Schedules Direct token: {Token}", root . T oken) ;
return root . T oken;
}
throw new Exception ( "Could not authenticate with Schedules Direct Error: " + root . m essage) ;
throw new Exception ( "Could not authenticate with Schedules Direct Error: " + root . M essage) ;
}
private async Task AddLineupToAccount ( ListingsProviderInfo info , CancellationToken cancellationToken )
@ -705,9 +706,9 @@ namespace Emby.Server.Implementations.LiveTv.Listings
httpResponse . EnsureSuccessStatusCode ( ) ;
await using var stream = await httpResponse . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
using var response = httpResponse . Content ;
var root = await JsonSerializer . DeserializeAsync < ScheduleDirect. Lineups> ( stream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
var root = await JsonSerializer . DeserializeAsync < LineupsDto > ( stream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
return root . l ineups. Any ( i = > string . Equals ( info . ListingsId , i . l ineup, StringComparison . OrdinalIgnoreCase ) ) ;
return root . L ineups. Any ( i = > string . Equals ( info . ListingsId , i . L ineup, StringComparison . OrdinalIgnoreCase ) ) ;
}
catch ( HttpRequestException ex )
{
@ -777,35 +778,35 @@ namespace Emby.Server.Implementations.LiveTv.Listings
using var httpResponse = await Send ( options , true , info , cancellationToken ) . ConfigureAwait ( false ) ;
await using var stream = await httpResponse . Content . ReadAsStreamAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
var root = await JsonSerializer . DeserializeAsync < ScheduleDirect. Channel> ( stream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
_logger . LogInformation ( "Found {ChannelCount} channels on the lineup on ScheduleDirect" , root . m ap. Count ) ;
var root = await JsonSerializer . DeserializeAsync < ChannelDto > ( stream , _jsonOptions , cancellationToken ) . ConfigureAwait ( false ) ;
_logger . LogInformation ( "Found {ChannelCount} channels on the lineup on ScheduleDirect" , root . M ap. Count ) ;
_logger . LogInformation ( "Mapping Stations to Channel" ) ;
var allStations = root . s tations ? ? new List < S cheduleDirect. S tation> ( ) ;
var allStations = root . S tations ? ? new List < S tationDto > ( ) ;
var map = root . m ap;
var map = root . M ap;
var list = new List < ChannelInfo > ( map . Count ) ;
foreach ( var channel in map )
{
var channelNumber = GetChannelNumber ( channel ) ;
var station = allStations . Find ( item = > string . Equals ( item . stationID, channel . stationID , StringComparison . OrdinalIgnoreCase ) )
? ? new S cheduleDirect. S tation
var station = allStations . Find ( item = > string . Equals ( item . StationId, channel . StationId , StringComparison . OrdinalIgnoreCase ) )
? ? new S tationDto
{
stationID = channel . stationID
StationId = channel . StationId
} ;
var channelInfo = new ChannelInfo
{
Id = station . stationID ,
CallSign = station . c allsign,
Id = station . StationId ,
CallSign = station . C allsign,
Number = channelNumber ,
Name = string . IsNullOrWhiteSpace ( station . name) ? channelNumber : station . n ame
Name = string . IsNullOrWhiteSpace ( station . Name) ? channelNumber : station . N ame
} ;
if ( station . l ogo ! = null )
if ( station . L ogo ! = null )
{
channelInfo . ImageUrl = station . logo. URL ;
channelInfo . ImageUrl = station . Logo. Url ;
}
list . Add ( channelInfo ) ;
@ -818,402 +819,5 @@ namespace Emby.Server.Implementations.LiveTv.Listings
{
return value . Replace ( " " , string . Empty , StringComparison . Ordinal ) . Replace ( "-" , string . Empty , StringComparison . Ordinal ) ;
}
public class ScheduleDirect
{
public class Token
{
public int code { get ; set ; }
public string message { get ; set ; }
public string serverID { get ; set ; }
public string token { get ; set ; }
}
public class Lineup
{
public string lineup { get ; set ; }
public string name { get ; set ; }
public string transport { get ; set ; }
public string location { get ; set ; }
public string uri { get ; set ; }
}
public class Lineups
{
public int code { get ; set ; }
public string serverID { get ; set ; }
public string datetime { get ; set ; }
public List < Lineup > lineups { get ; set ; }
}
public class Headends
{
public string headend { get ; set ; }
public string transport { get ; set ; }
public string location { get ; set ; }
public List < Lineup > lineups { get ; set ; }
}
public class Map
{
public string stationID { get ; set ; }
public string channel { get ; set ; }
public string logicalChannelNumber { get ; set ; }
public int uhfVhf { get ; set ; }
public int atscMajor { get ; set ; }
public int atscMinor { get ; set ; }
}
public class Broadcaster
{
public string city { get ; set ; }
public string state { get ; set ; }
public string postalcode { get ; set ; }
public string country { get ; set ; }
}
public class Logo
{
public string URL { get ; set ; }
public int height { get ; set ; }
public int width { get ; set ; }
public string md5 { get ; set ; }
}
public class Station
{
public string stationID { get ; set ; }
public string name { get ; set ; }
public string callsign { get ; set ; }
public List < string > broadcastLanguage { get ; set ; }
public List < string > descriptionLanguage { get ; set ; }
public Broadcaster broadcaster { get ; set ; }
public string affiliate { get ; set ; }
public Logo logo { get ; set ; }
public bool? isCommercialFree { get ; set ; }
}
public class Metadata
{
public string lineup { get ; set ; }
public string modified { get ; set ; }
public string transport { get ; set ; }
}
public class Channel
{
public List < Map > map { get ; set ; }
public List < Station > stations { get ; set ; }
public Metadata metadata { get ; set ; }
}
public class RequestScheduleForChannel
{
public string stationID { get ; set ; }
public List < string > date { get ; set ; }
}
public class Rating
{
public string body { get ; set ; }
public string code { get ; set ; }
}
public class Multipart
{
public int partNumber { get ; set ; }
public int totalParts { get ; set ; }
}
public class Program
{
public string programID { get ; set ; }
public string airDateTime { get ; set ; }
public int duration { get ; set ; }
public string md5 { get ; set ; }
public List < string > audioProperties { get ; set ; }
public List < string > videoProperties { get ; set ; }
public List < Rating > ratings { get ; set ; }
public bool? @new { get ; set ; }
public Multipart multipart { get ; set ; }
public string liveTapeDelay { get ; set ; }
public bool premiere { get ; set ; }
public bool repeat { get ; set ; }
public string isPremiereOrFinale { get ; set ; }
}
public class MetadataSchedule
{
public string modified { get ; set ; }
public string md5 { get ; set ; }
public string startDate { get ; set ; }
public string endDate { get ; set ; }
public int days { get ; set ; }
}
public class Day
{
public string stationID { get ; set ; }
public List < Program > programs { get ; set ; }
public MetadataSchedule metadata { get ; set ; }
public Day ( )
{
programs = new List < Program > ( ) ;
}
}
public class Title
{
public string title120 { get ; set ; }
}
public class EventDetails
{
public string subType { get ; set ; }
}
public class Description100
{
public string descriptionLanguage { get ; set ; }
public string description { get ; set ; }
}
public class Description1000
{
public string descriptionLanguage { get ; set ; }
public string description { get ; set ; }
}
public class DescriptionsProgram
{
public List < Description100 > description100 { get ; set ; }
public List < Description1000 > description1000 { get ; set ; }
}
public class Gracenote
{
public int season { get ; set ; }
public int episode { get ; set ; }
}
public class MetadataPrograms
{
public Gracenote Gracenote { get ; set ; }
}
public class ContentRating
{
public string body { get ; set ; }
public string code { get ; set ; }
}
public class Cast
{
public string billingOrder { get ; set ; }
public string role { get ; set ; }
public string nameId { get ; set ; }
public string personId { get ; set ; }
public string name { get ; set ; }
public string characterName { get ; set ; }
}
public class Crew
{
public string billingOrder { get ; set ; }
public string role { get ; set ; }
public string nameId { get ; set ; }
public string personId { get ; set ; }
public string name { get ; set ; }
}
public class QualityRating
{
public string ratingsBody { get ; set ; }
public string rating { get ; set ; }
public string minRating { get ; set ; }
public string maxRating { get ; set ; }
public string increment { get ; set ; }
}
public class Movie
{
public string year { get ; set ; }
public int duration { get ; set ; }
public List < QualityRating > qualityRating { get ; set ; }
}
public class Recommendation
{
public string programID { get ; set ; }
public string title120 { get ; set ; }
}
public class ProgramDetails
{
public string audience { get ; set ; }
public string programID { get ; set ; }
public List < Title > titles { get ; set ; }
public EventDetails eventDetails { get ; set ; }
public DescriptionsProgram descriptions { get ; set ; }
public string originalAirDate { get ; set ; }
public List < string > genres { get ; set ; }
public string episodeTitle150 { get ; set ; }
public List < MetadataPrograms > metadata { get ; set ; }
public List < ContentRating > contentRating { get ; set ; }
public List < Cast > cast { get ; set ; }
public List < Crew > crew { get ; set ; }
public string entityType { get ; set ; }
public string showType { get ; set ; }
public bool hasImageArtwork { get ; set ; }
public string primaryImage { get ; set ; }
public string thumbImage { get ; set ; }
public string backdropImage { get ; set ; }
public string bannerImage { get ; set ; }
public string imageID { get ; set ; }
public string md5 { get ; set ; }
public List < string > contentAdvisory { get ; set ; }
public Movie movie { get ; set ; }
public List < Recommendation > recommendations { get ; set ; }
}
public class Caption
{
public string content { get ; set ; }
public string lang { get ; set ; }
}
public class ImageData
{
public string width { get ; set ; }
public string height { get ; set ; }
public string uri { get ; set ; }
public string size { get ; set ; }
public string aspect { get ; set ; }
public string category { get ; set ; }
public string text { get ; set ; }
public string primary { get ; set ; }
public string tier { get ; set ; }
public Caption caption { get ; set ; }
}
public class ShowImages
{
public string programID { get ; set ; }
public List < ImageData > data { get ; set ; }
}
}
}
}