From 3ab6ac90ec947c111d42ba7e3f8e8754c53da798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mlendea=2C=20Hora=C8=9Biu?= Date: Mon, 19 Oct 2020 00:00:37 +0300 Subject: [PATCH] Write playlist details to the output file --- Configuration/ApplicationSettings.cs | 2 ++ README.md | 1 + Service/Models/Channel.cs | 4 ++++ Service/PlaylistAggregator.cs | 2 ++ Service/PlaylistFetcher.cs | 6 ++++-- Service/PlaylistFileBuilder.cs | 15 +++++++++++++++ appsettings.json | 1 + 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Configuration/ApplicationSettings.cs b/Configuration/ApplicationSettings.cs index 7840066..5119fd4 100644 --- a/Configuration/ApplicationSettings.cs +++ b/Configuration/ApplicationSettings.cs @@ -10,6 +10,8 @@ public sealed class ApplicationSettings public bool AreTvGuideTagsEnabled { get; set; } + public bool ArePlaylistDetailsTagsEnabled { get; set; } + public string UserAgent { get; set; } } } diff --git a/README.md b/README.md index ad0c30f..f167133 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ The settings are stored in the `appsettings.json` file in the root directory. - *daysToCheck*: How far in the past to go for each playlist. If today's playlist is not found (sometimes the providers skip some days) then the service will move on to the previous day, again and again until one is found or the daysToCheck limit is reached. - *canIncludeUnmatchedChannels*: Boolean value indicating whether provider channels that were not able to be matched with the data in the channelStorePath file should be included in the output file (in the Unknown category) or not at all - *areTvGuideTagsEnabled*: Boolean value indicating whether TV Guide tags (logo URLs, groups, TVG IDs, channel numbers, etc) should be included in the output file or not + - *arePlaylistDetailsTagsEnabled*: Boolean value indicating whether playlist details (playlist ID, the playlist's original channel name) should be included in the output file or not - *userAgent*: String value indicating the UserAgent that should be used when performing HTTP operations ### Channel data diff --git a/Service/Models/Channel.cs b/Service/Models/Channel.cs index 38058eb..430670a 100644 --- a/Service/Models/Channel.cs +++ b/Service/Models/Channel.cs @@ -14,6 +14,10 @@ public sealed class Channel public int Number { get; set; } + public string PlaylistId { get; set; } + + public string PlaylistChannelName { get; set; } + public string Url { get; set; } } } \ No newline at end of file diff --git a/Service/PlaylistAggregator.cs b/Service/PlaylistAggregator.cs index 2117009..e9006e6 100644 --- a/Service/PlaylistAggregator.cs +++ b/Service/PlaylistAggregator.cs @@ -171,6 +171,8 @@ IEnumerable GetEnabledChannels(IEnumerable filteredProviderCha channel.Country = channelDef.Country; channel.Group = groups[channelDef.GroupId].Name; channel.LogoUrl = channelDef.LogoUrl; + channel.PlaylistId = matchedChannel.PlaylistId; + channel.PlaylistChannelName = matchedChannel.PlaylistChannelName; channel.Url = matchedChannel.Url; channels.Add(channel); diff --git a/Service/PlaylistFetcher.cs b/Service/PlaylistFetcher.cs index fc90d7f..8941f84 100644 --- a/Service/PlaylistFetcher.cs +++ b/Service/PlaylistFetcher.cs @@ -89,9 +89,11 @@ public async Task FetchProviderPlaylistAsync(PlaylistProvider provider return null; } - if (!string.IsNullOrWhiteSpace(provider.ChannelNameOverride)) + foreach (Channel channel in playlist.Channels) { - foreach (Channel channel in playlist.Channels) + channel.PlaylistId = provider.Id; + + if (!string.IsNullOrWhiteSpace(provider.ChannelNameOverride)) { channel.Name = provider.ChannelNameOverride; } diff --git a/Service/PlaylistFileBuilder.cs b/Service/PlaylistFileBuilder.cs index fc82646..c12520f 100644 --- a/Service/PlaylistFileBuilder.cs +++ b/Service/PlaylistFileBuilder.cs @@ -20,6 +20,8 @@ public sealed class PlaylistFileBuilder : IPlaylistFileBuilder const string TvGuideLogoTagKey = "tvg-logo"; const string TvGuideCountryTagKey = "tvg-country"; const string TvGuideGroupTagKey = "group-title"; + const string PlaylistIdTagKey = "playlist-id"; + const string PlaylistChannelNameTagKey = "playlist-channel-name"; const int DefaultEntryRuntime = -1; readonly ICacheManager cache; @@ -48,6 +50,11 @@ public string BuildFile(Playlist playlist) file += BuildTvGuideHeaderTags(channel); } + if (settings.ArePlaylistDetailsTagsEnabled) + { + file += BuildPlaylistDetailsHeaderTags(channel); + } + file += $"{EntryValuesSeparator}{channel.Name}{Environment.NewLine}" + $"{channel.Url}{Environment.NewLine}"; @@ -102,6 +109,7 @@ public Playlist ParseFile(string content) Channel channel = new Channel(); channel.Name = lineSplit[lineSplit.Length - 1]; + channel.PlaylistChannelName = channel.Name; playlist.Channels.Add(channel); } @@ -151,5 +159,12 @@ string BuildTvGuideHeaderTags(Channel channel) return tvgTags; } + + string BuildPlaylistDetailsHeaderTags(Channel channel) + { + return + $" {PlaylistIdTagKey}=\"{channel.PlaylistId}\"" + + $" {PlaylistChannelNameTagKey}=\"{channel.PlaylistChannelName}\""; + } } } diff --git a/appsettings.json b/appsettings.json index 5d71a52..da993ec 100644 --- a/appsettings.json +++ b/appsettings.json @@ -9,6 +9,7 @@ "daysToCheck": "7", "canIncludeUnmatchedChannels": "true", "areTvGuideTagsEnabled": "true", + "arePlaylistDetailsTagsEnabled": "true", "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36" }, "cacheSettings": {