125 lines
3.3 KiB
Dart
125 lines
3.3 KiB
Dart
import '../utils/json_utils.dart';
|
|
|
|
/// Represents a Live TV channel from the EPG
|
|
class LiveTvChannel {
|
|
final String key;
|
|
final String? identifier;
|
|
final String? callSign;
|
|
final String? title;
|
|
final String? thumb;
|
|
final String? art;
|
|
final String? number;
|
|
final bool hd;
|
|
final String? lineup;
|
|
final String? slug;
|
|
final bool? drm;
|
|
|
|
// Multi-server support
|
|
final String? serverId;
|
|
final String? serverName;
|
|
|
|
LiveTvChannel({
|
|
required this.key,
|
|
this.identifier,
|
|
this.callSign,
|
|
this.title,
|
|
this.thumb,
|
|
this.art,
|
|
this.number,
|
|
this.hd = false,
|
|
this.lineup,
|
|
this.slug,
|
|
this.drm,
|
|
this.serverId,
|
|
this.serverName,
|
|
});
|
|
|
|
factory LiveTvChannel.fromJson(Map<String, dynamic> json) {
|
|
return LiveTvChannel(
|
|
key:
|
|
json['key'] as String? ??
|
|
json['ratingKey'] as String? ??
|
|
json['identifier'] as String? ??
|
|
json['id'] as String? ??
|
|
json['channelIdentifier'] as String? ??
|
|
'',
|
|
identifier: json['identifier'] as String? ?? json['id'] as String? ?? json['channelIdentifier'] as String?,
|
|
callSign: json['callSign'] as String?,
|
|
title: json['title'] as String? ?? json['callSign'] as String?,
|
|
thumb: json['thumb'] as String?,
|
|
art: json['art'] as String?,
|
|
number:
|
|
json['number'] as String? ??
|
|
json['channelNumber'] as String? ??
|
|
json['channelVcn']?.toString() ??
|
|
json['vcn']?.toString(),
|
|
hd: flexibleBool(json['hd']),
|
|
lineup: json['lineup'] as String?,
|
|
slug: json['slug'] as String?,
|
|
drm: flexibleBool(json['drm']),
|
|
);
|
|
}
|
|
|
|
LiveTvChannel copyWith({String? serverId, String? serverName}) {
|
|
return LiveTvChannel(
|
|
key: key,
|
|
identifier: identifier,
|
|
callSign: callSign,
|
|
title: title,
|
|
thumb: thumb,
|
|
art: art,
|
|
number: number,
|
|
hd: hd,
|
|
lineup: lineup,
|
|
slug: slug,
|
|
drm: drm,
|
|
serverId: serverId ?? this.serverId,
|
|
serverName: serverName ?? this.serverName,
|
|
);
|
|
}
|
|
|
|
/// Display name: prefer callSign, fallback to title
|
|
String get displayName => callSign ?? title ?? 'Channel $number';
|
|
}
|
|
|
|
/// A channel entry in the Plex cloud favorites list.
|
|
/// Stored at `https://epg.provider.plex.tv/settings/favoriteChannels`.
|
|
class FavoriteChannel {
|
|
final String source;
|
|
final String id;
|
|
final String? title;
|
|
final String? thumb;
|
|
final String? vcn;
|
|
|
|
FavoriteChannel({required this.source, required this.id, this.title, this.thumb, this.vcn});
|
|
|
|
factory FavoriteChannel.fromJson(Map<String, dynamic> json) {
|
|
return FavoriteChannel(
|
|
source: json['source'] as String? ?? '',
|
|
id: json['id'] as String? ?? json['key'] as String? ?? '',
|
|
title: json['title'] as String?,
|
|
thumb: json['thumb'] as String?,
|
|
vcn: json['vcn'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'source': source,
|
|
'id': id,
|
|
if (title != null) 'title': title,
|
|
if (thumb != null) 'thumb': thumb,
|
|
if (vcn != null) 'vcn': vcn,
|
|
};
|
|
|
|
/// Create from a [LiveTvChannel] and a source URI.
|
|
factory FavoriteChannel.fromLiveTvChannel(LiveTvChannel channel, String source) {
|
|
return FavoriteChannel(
|
|
source: source,
|
|
id: channel.key,
|
|
title: channel.title ?? channel.callSign,
|
|
thumb: channel.thumb,
|
|
vcn: channel.number,
|
|
);
|
|
}
|
|
}
|