< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.LiveTv.LiveTvProgram
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs
Line coverage
8%
Covered lines: 4
Uncovered lines: 45
Coverable lines: 49
Total lines: 258
Line coverage: 8.1%
Branch coverage
0%
Covered branches: 0
Total branches: 32
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591, SA1306
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Globalization;
 8using System.Linq;
 9using System.Text.Json.Serialization;
 10using Jellyfin.Data.Enums;
 11using Jellyfin.Extensions;
 12using MediaBrowser.Common.Configuration;
 13using MediaBrowser.Controller.Entities;
 14using MediaBrowser.Controller.Providers;
 15using MediaBrowser.Model.Entities;
 16using MediaBrowser.Model.LiveTv;
 17using MediaBrowser.Model.Providers;
 18
 19namespace MediaBrowser.Controller.LiveTv
 20{
 21    public class LiveTvProgram : BaseItem, IHasLookupInfo<ItemLookupInfo>, IHasStartDate, IHasProgramAttributes
 22    {
 23        private const string EmbyServiceName = "Emby";
 24
 125        public LiveTvProgram()
 26        {
 127            IsVirtualItem = true;
 128        }
 29
 30        public string SeriesName { get; set; }
 31
 32        [JsonIgnore]
 033        public override SourceType SourceType => SourceType.LiveTV;
 34
 35        /// <summary>
 36        /// Gets or sets start date of the program, in UTC.
 37        /// </summary>
 38        [JsonIgnore]
 39        public DateTime StartDate { get; set; }
 40
 41        /// <summary>
 42        /// Gets or sets a value indicating whether this instance is repeat.
 43        /// </summary>
 44        /// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value>
 45        [JsonIgnore]
 46        public bool IsRepeat { get; set; }
 47
 48        /// <summary>
 49        /// Gets or sets the episode title.
 50        /// </summary>
 51        /// <value>The episode title.</value>
 52        [JsonIgnore]
 53        public string EpisodeTitle { get; set; }
 54
 55        [JsonIgnore]
 56        public string ShowId { get; set; }
 57
 58        /// <summary>
 59        /// Gets or sets a value indicating whether this instance is movie.
 60        /// </summary>
 61        /// <value><c>true</c> if this instance is movie; otherwise, <c>false</c>.</value>
 62        [JsonIgnore]
 63        public bool IsMovie { get; set; }
 64
 65        /// <summary>
 66        /// Gets a value indicating whether this instance is sports.
 67        /// </summary>
 68        /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
 69        [JsonIgnore]
 070        public bool IsSports => Tags.Contains("Sports", StringComparison.OrdinalIgnoreCase);
 71
 72        /// <summary>
 73        /// Gets or sets a value indicating whether this instance is series.
 74        /// </summary>
 75        /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
 76        [JsonIgnore]
 77        public bool IsSeries { get; set; }
 78
 79        /// <summary>
 80        /// Gets a value indicating whether this instance is live.
 81        /// </summary>
 82        /// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
 83        [JsonIgnore]
 084        public bool IsLive => Tags.Contains("Live", StringComparison.OrdinalIgnoreCase);
 85
 86        /// <summary>
 87        /// Gets a value indicating whether this instance is news.
 88        /// </summary>
 89        /// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
 90        [JsonIgnore]
 091        public bool IsNews => Tags.Contains("News", StringComparison.OrdinalIgnoreCase);
 92
 93        /// <summary>
 94        /// Gets a value indicating whether this instance is kids.
 95        /// </summary>
 96        /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
 97        [JsonIgnore]
 098        public bool IsKids => Tags.Contains("Kids", StringComparison.OrdinalIgnoreCase);
 99
 100        /// <summary>
 101        /// Gets a value indicating whether this instance is premiere.
 102        /// </summary>
 103        /// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
 104        [JsonIgnore]
 0105        public bool IsPremiere => Tags.Contains("Premiere", StringComparison.OrdinalIgnoreCase);
 106
 107        /// <summary>
 108        /// Gets the folder containing the item.
 109        /// If the item is a folder, it returns the folder itself.
 110        /// </summary>
 111        /// <value>The containing folder path.</value>
 112        [JsonIgnore]
 0113        public override string ContainingFolderPath => Path;
 114
 115        // [JsonIgnore]
 116        // public override string MediaType
 117        // {
 118        //    get
 119        //    {
 120        //        return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio
 121        //    }
 122        // }
 123
 124        [JsonIgnore]
 125        public bool IsAiring
 126        {
 127            get
 128            {
 0129                var now = DateTime.UtcNow;
 130
 0131                return now >= StartDate && now < EndDate;
 132            }
 133        }
 134
 135        [JsonIgnore]
 136        public bool HasAired
 137        {
 138            get
 139            {
 0140                var now = DateTime.UtcNow;
 141
 0142                return now >= EndDate;
 143            }
 144        }
 145
 146        [JsonIgnore]
 147        public override bool SupportsPeople
 148        {
 149            get
 150            {
 151                // Optimization
 0152                if (IsNews || IsSports)
 153                {
 0154                    return false;
 155                }
 156
 0157                return base.SupportsPeople;
 158            }
 159        }
 160
 161        [JsonIgnore]
 0162        public override bool SupportsAncestors => false;
 163
 164        public override List<string> GetUserDataKeys()
 165        {
 0166            var list = base.GetUserDataKeys();
 167
 0168            if (!IsSeries)
 169            {
 0170                var key = this.GetProviderId(MetadataProvider.Imdb);
 0171                if (!string.IsNullOrEmpty(key))
 172                {
 0173                    list.Insert(0, key);
 174                }
 175
 0176                key = this.GetProviderId(MetadataProvider.Tmdb);
 0177                if (!string.IsNullOrEmpty(key))
 178                {
 0179                    list.Insert(0, key);
 180                }
 181            }
 0182            else if (!string.IsNullOrEmpty(EpisodeTitle))
 183            {
 0184                var name = GetClientTypeName();
 185
 0186                list.Insert(0, name + "-" + Name + (EpisodeTitle ?? string.Empty));
 187            }
 188
 0189            return list;
 190        }
 191
 192        public override double GetDefaultPrimaryImageAspectRatio()
 193        {
 0194            var serviceName = ServiceName;
 195
 0196            if (string.Equals(serviceName, EmbyServiceName, StringComparison.OrdinalIgnoreCase) || string.Equals(service
 197            {
 0198                return 2.0 / 3;
 199            }
 200
 0201            return 16.0 / 9;
 202        }
 203
 204        public override string GetClientTypeName()
 205        {
 1206            return "Program";
 207        }
 208
 209        public override UnratedItem GetBlockUnratedType()
 210        {
 0211            return UnratedItem.LiveTvProgram;
 212        }
 213
 214        protected override string GetInternalMetadataPath(string basePath)
 215        {
 0216            return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N", CultureInfo.InvariantCulture));
 217        }
 218
 219        public override bool CanDelete()
 220        {
 0221            return false;
 222        }
 223
 224        private LiveTvOptions GetConfiguration()
 225        {
 0226            return ConfigurationManager.GetConfiguration<LiveTvOptions>("livetv");
 227        }
 228
 229        private ListingsProviderInfo GetListingsProviderInfo()
 230        {
 0231            if (string.Equals(ServiceName, "Emby", StringComparison.OrdinalIgnoreCase))
 232            {
 0233                var config = GetConfiguration();
 234
 0235                return config.ListingProviders.FirstOrDefault(i => !string.IsNullOrEmpty(i.MoviePrefix));
 236            }
 237
 0238            return null;
 239        }
 240
 241        protected override string GetNameForMetadataLookup()
 242        {
 0243            var name = base.GetNameForMetadataLookup();
 244
 0245            var listings = GetListingsProviderInfo();
 246
 0247            if (listings is not null)
 248            {
 0249                if (!string.IsNullOrEmpty(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringCompariso
 250                {
 0251                    name = name.Substring(listings.MoviePrefix.Length).Trim();
 252                }
 253            }
 254
 0255            return name;
 256        }
 257    }
 258}