├── .github ├── cover.png ├── workflows │ └── dotnet.yml └── FUNDING.yml ├── IptvPlaylistAggregator ├── Service │ ├── IPlaylistAggregator.cs │ ├── IFileDownloader.cs │ ├── IMediaSourceChecker.cs │ ├── Models │ │ ├── StreamState.cs │ │ ├── Host.cs │ │ ├── Group.cs │ │ ├── MediaStreamStatus.cs │ │ ├── ChannelDefinition.cs │ │ ├── Playlist.cs │ │ ├── PlaylistProvider.cs │ │ ├── Channel.cs │ │ └── ChannelName.cs │ ├── IChannelMatcher.cs │ ├── IPlaylistFileBuilder.cs │ ├── IPlaylistFetcher.cs │ ├── ICacheManager.cs │ ├── Mapping │ │ ├── GroupMapping.cs │ │ ├── ChannelDefinitionMapping.cs │ │ └── PlaylistProviderMapping.cs │ ├── FileDownloader.cs │ ├── ChannelMatcher.cs │ ├── PlaylistFileBuilder.cs │ ├── PlaylistFetcher.cs │ ├── MediaSourceChecker.cs │ ├── CacheManager.cs │ └── PlaylistAggregator.cs ├── Configuration │ ├── DataStoreSettings.cs │ ├── ApplicationSettings.cs │ └── CacheSettings.cs ├── DataAccess │ └── DataObjects │ │ ├── GroupEntity.cs │ │ ├── PlaylistProviderEntity.cs │ │ └── ChannelDefinitionEntity.cs ├── Logging │ ├── MyOperation.cs │ └── MyLogInfoKey.cs ├── appsettings.json ├── IptvPlaylistAggregator.csproj ├── Data │ ├── groups.xml │ └── providers.xml └── Program.cs ├── release.sh ├── IptvPlaylistAggregator.UnitTests ├── IptvPlaylistAggregator.UnitTests.csproj └── Service │ ├── MediaSourceCheckerTests.cs │ └── ChannelMatcherTests.cs ├── IptvPlaylistAggregator.sln ├── README.md ├── .gitignore └── LICENSE /.github/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmlendea/iptv-playlist-aggregator/HEAD/.github/cover.png -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/IPlaylistAggregator.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Service 2 | { 3 | public interface IPlaylistAggregator 4 | { 5 | string GatherPlaylist(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DOTNET_VERSION='9.0' 3 | RELEASE_SCRIPT_URL="https://raw.githubusercontent.com/hmlendea/deployment-scripts/master/release/dotnet/${DOTNET_VERSION}.sh" 4 | curl -sSL "${RELEASE_SCRIPT_URL}" | bash -s ${1} --no-trim -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/IFileDownloader.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace IptvPlaylistAggregator.Service 4 | { 5 | public interface IFileDownloader 6 | { 7 | Task TryDownloadStringAsync(string url); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/IMediaSourceChecker.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace IptvPlaylistAggregator.Service 4 | { 5 | public interface IMediaSourceChecker 6 | { 7 | Task IsSourcePlayableAsync(string url); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/StreamState.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Service.Models 2 | { 3 | public enum StreamState 4 | { 5 | Alive, 6 | Dead, 7 | Unauthorised, 8 | NotFound, 9 | Unsupported, 10 | Blacklisted 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/Host.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IptvPlaylistAggregator.Service.Models 4 | { 5 | public sealed class Host 6 | { 7 | public string Domain { get; set; } 8 | 9 | public string Ip { get; set; } 10 | 11 | public DateTime ResolutionTime { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/Group.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Service.Models 2 | { 3 | public class Group 4 | { 5 | public string Id { get; set; } 6 | 7 | public bool IsEnabled { get; set; } 8 | 9 | public string Name { get; set; } 10 | 11 | public int Priority { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/IChannelMatcher.cs: -------------------------------------------------------------------------------- 1 | using IptvPlaylistAggregator.Service.Models; 2 | 3 | namespace IptvPlaylistAggregator.Service 4 | { 5 | public interface IChannelMatcher 6 | { 7 | string NormaliseName(string name, string country); 8 | 9 | bool DoesMatch(ChannelName name1, string name2, string country2); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Configuration/DataStoreSettings.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Configuration 2 | { 3 | public sealed class DataStoreSettings 4 | { 5 | public string ChannelStorePath { get; set; } 6 | 7 | public string PlaylistProviderStorePath { get; set; } 8 | 9 | public string GroupStorePath { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/IPlaylistFileBuilder.cs: -------------------------------------------------------------------------------- 1 | using IptvPlaylistAggregator.Service.Models; 2 | 3 | namespace IptvPlaylistAggregator.Service 4 | { 5 | public interface IPlaylistFileBuilder 6 | { 7 | string BuildFile(Playlist playlist); 8 | 9 | Playlist TryParseFile(string file); 10 | 11 | Playlist ParseFile(string file); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/MediaStreamStatus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IptvPlaylistAggregator.Service.Models 4 | { 5 | public sealed class MediaStreamStatus 6 | { 7 | public string Url { get; set; } 8 | 9 | public bool IsAlive => State is StreamState.Alive; 10 | 11 | public StreamState State { get; set; } 12 | 13 | public DateTime LastCheckTime { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/DataAccess/DataObjects/GroupEntity.cs: -------------------------------------------------------------------------------- 1 | using NuciDAL.DataObjects; 2 | 3 | namespace IptvPlaylistAggregator.DataAccess.DataObjects 4 | { 5 | public class GroupEntity : EntityBase 6 | { 7 | public bool IsEnabled { get; set; } 8 | 9 | public string Name { get; set; } 10 | 11 | public int Priority { get; set; } 12 | 13 | public GroupEntity() => Priority = int.MaxValue; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/IPlaylistFetcher.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | 4 | using IptvPlaylistAggregator.Service.Models; 5 | 6 | namespace IptvPlaylistAggregator.Service 7 | { 8 | public interface IPlaylistFetcher 9 | { 10 | IEnumerable FetchProviderPlaylists(IEnumerable providers); 11 | 12 | Task FetchProviderPlaylistAsync(PlaylistProvider provider); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/ChannelDefinition.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Service.Models 2 | { 3 | public sealed class ChannelDefinition 4 | { 5 | public string Id { get; set; } 6 | 7 | public bool IsEnabled { get; set; } 8 | 9 | public ChannelName Name { get; set; } 10 | 11 | public string Country { get; set; } 12 | 13 | public string GroupId { get; set; } 14 | 15 | public string LogoUrl { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Configuration/ApplicationSettings.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Configuration 2 | { 3 | public sealed class ApplicationSettings 4 | { 5 | public string OutputPlaylistPath { get; set; } 6 | 7 | public int DaysToCheck { get; set; } 8 | 9 | public bool CanIncludeUnmatchedChannels { get; set; } 10 | 11 | public bool AreTvGuideTagsEnabled { get; set; } 12 | 13 | public bool ArePlaylistDetailsTagsEnabled { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/Playlist.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NuciExtensions; 3 | 4 | namespace IptvPlaylistAggregator.Service.Models 5 | { 6 | public sealed class Playlist 7 | { 8 | public IList Channels; 9 | 10 | public bool IsEmpty => EnumerableExt.IsNullOrEmpty(Channels); 11 | 12 | public Playlist() => Channels = []; 13 | 14 | public static bool IsNullOrEmpty(Playlist playlist) 15 | => playlist is null || playlist.IsEmpty; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Configuration/CacheSettings.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Configuration 2 | { 3 | public sealed class CacheSettings 4 | { 5 | public string CacheDirectoryPath { get; set; } 6 | 7 | public int HostCacheTimeout { get; set; } 8 | 9 | public int StreamAliveStatusCacheTimeout { get; set; } 10 | 11 | public int StreamDeadStatusCacheTimeout { get; set; } 12 | 13 | public int StreamUnauthorisedStatusCacheTimeout { get; set; } 14 | 15 | public int StreamNotFoundStatusCacheTimeout { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/PlaylistProvider.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Service.Models 2 | { 3 | public class PlaylistProvider 4 | { 5 | public string Id { get; set; } 6 | 7 | public bool IsEnabled { get; set; } 8 | 9 | public int Priority { get; set; } 10 | 11 | public bool AllowCaching { get; set; } 12 | 13 | public string Name { get; set; } 14 | 15 | public string UrlFormat { get; set; } 16 | 17 | public string Country { get; set; } 18 | 19 | public string ChannelNameOverride { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | name: Build 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v1 18 | with: 19 | dotnet-version: 9.0.x 20 | - name: Restore dependencies 21 | run: dotnet restore 22 | - name: Build 23 | run: dotnet build --no-restore 24 | - name: Test 25 | run: dotnet test --no-build --verbosity normal 26 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/Channel.cs: -------------------------------------------------------------------------------- 1 | namespace IptvPlaylistAggregator.Service.Models 2 | { 3 | public sealed class Channel 4 | { 5 | public string Id { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Group { get; set; } 10 | 11 | public string Country { get; set; } 12 | 13 | public string LogoUrl { get; set; } 14 | 15 | public int Number { get; set; } 16 | 17 | public string PlaylistId { get; set; } 18 | 19 | public string PlaylistChannelName { get; set; } 20 | 21 | public string Url { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /IptvPlaylistAggregator.UnitTests/IptvPlaylistAggregator.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | IptvPlaylistAggregator.UnitTests 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Logging/MyOperation.cs: -------------------------------------------------------------------------------- 1 | using NuciLog.Core; 2 | 3 | namespace IptvPlaylistAggregator.Logging 4 | { 5 | public sealed class MyOperation : Operation 6 | { 7 | private MyOperation(string name) : base(name) { } 8 | 9 | public static Operation PlaylistFetching => new MyOperation(nameof(PlaylistFetching)); 10 | 11 | public static Operation ProviderChannelsFiltering => new MyOperation(nameof(ProviderChannelsFiltering)); 12 | 13 | public static Operation ChannelMatching => new MyOperation(nameof(ChannelMatching)); 14 | 15 | public static Operation MediaSourceCheck => new MyOperation(nameof(MediaSourceCheck)); 16 | 17 | public static Operation CacheSaving => new MyOperation(nameof(CacheSaving)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/DataAccess/DataObjects/PlaylistProviderEntity.cs: -------------------------------------------------------------------------------- 1 | using NuciDAL.DataObjects; 2 | 3 | namespace IptvPlaylistAggregator.DataAccess.DataObjects 4 | { 5 | public class PlaylistProviderEntity : EntityBase 6 | { 7 | public bool IsEnabled { get; set; } 8 | 9 | public int Priority { get; set; } 10 | 11 | public bool AllowCaching { get; set; } 12 | 13 | public string Name { get; set; } 14 | 15 | public string UrlFormat { get; set; } 16 | 17 | public string Country { get; set; } 18 | 19 | public string ChannelNameOverride { get; set; } 20 | 21 | public PlaylistProviderEntity() 22 | { 23 | Priority = int.MaxValue; 24 | AllowCaching = true; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Logging/MyLogInfoKey.cs: -------------------------------------------------------------------------------- 1 | using NuciLog.Core; 2 | 3 | namespace IptvPlaylistAggregator.Logging 4 | { 5 | public sealed class MyLogInfoKey : LogInfoKey 6 | { 7 | private MyLogInfoKey(string name) : base(name) { } 8 | 9 | public static LogInfoKey Channel => new MyLogInfoKey(nameof(Channel)); 10 | 11 | public static LogInfoKey ChannelsCount => new MyLogInfoKey(nameof(ChannelsCount)); 12 | 13 | public static LogInfoKey Group => new MyLogInfoKey(nameof(Group)); 14 | 15 | public static LogInfoKey Provider => new MyLogInfoKey(nameof(Provider)); 16 | 17 | public static LogInfoKey Url => new MyLogInfoKey(nameof(Url)); 18 | 19 | public static LogInfoKey StreamState => new MyLogInfoKey(nameof(StreamState)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: hmlendea 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: hmlendea 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: HMlendea 10 | issuehunt: # Replace with a single IssueHunt username 11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 12 | polar: # Replace with a single Polar username 13 | buy_me_a_coffee: hmlendea 14 | thanks_dev: # Replace with a single thanks.dev username 15 | custom: https://hmlendea.go.ro/fund.html 16 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/DataAccess/DataObjects/ChannelDefinitionEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | using NuciDAL.DataObjects; 4 | 5 | namespace IptvPlaylistAggregator.DataAccess.DataObjects 6 | { 7 | public sealed class ChannelDefinitionEntity : EntityBase 8 | { 9 | private const string UnknownGroupPlaceholder = "unknown"; 10 | 11 | public bool IsEnabled { get; set; } 12 | 13 | public string Name { get; set; } 14 | 15 | public string Country { get; set; } 16 | 17 | public string GroupId { get; set; } 18 | 19 | public string LogoUrl { get; set; } 20 | 21 | public List Aliases { get; set; } 22 | 23 | public ChannelDefinitionEntity() 24 | { 25 | IsEnabled = true; 26 | GroupId = UnknownGroupPlaceholder; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "nuciLoggerSettings": { 3 | "logFilePath": "logfile.log", 4 | "isFileOutputEnabled": true, 5 | "minimumLevel": "Info" 6 | }, 7 | "applicationSettings": { 8 | "outputPlaylistPath": "result.m3u", 9 | "daysToCheck": "7", 10 | "canIncludeUnmatchedChannels": "true", 11 | "areTvGuideTagsEnabled": "true", 12 | "arePlaylistDetailsTagsEnabled": "true" 13 | }, 14 | "cacheSettings": { 15 | "cacheDirectoryPath": "Cache", 16 | "hostCacheTimeout": "43200", 17 | "streamAliveStatusCacheTimeout": "2000", 18 | "streamDeadStatusCacheTimeout": "3600", 19 | "streamUnauthorisedStatusCacheTimeout": "172800", 20 | "streamNotFoundStatusCacheTimeout": "129600" 21 | }, 22 | "dataStoreSettings": { 23 | "channelStorePath": "Data/channels.xml", 24 | "groupStorePath": "Data/groups.xml", 25 | "playlistProviderStorePath": "Data/providers.xml" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Models/ChannelName.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace IptvPlaylistAggregator.Service.Models 5 | { 6 | public sealed class ChannelName(string name, string country, IEnumerable aliases) 7 | { 8 | public string Value { get; set; } = name; 9 | 10 | public string Country { get; set; } = country; 11 | 12 | public IEnumerable Aliases { get; set; } = aliases; 13 | 14 | public ChannelName(string name) : this(name, country: null) { } 15 | 16 | public ChannelName(string name, string country) : this(name, country, new List()) { } 17 | 18 | public ChannelName(string name, params string[] aliases) : this(name, country: null, aliases) { } 19 | 20 | public ChannelName(string name, string country, params string[] aliases) : this(name, country, aliases.ToList()) { } 21 | 22 | public ChannelName(string name, IEnumerable aliases) : this(name, country: null, aliases) { } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/ICacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography.X509Certificates; 3 | 4 | using IptvPlaylistAggregator.Service.Models; 5 | 6 | namespace IptvPlaylistAggregator.Service 7 | { 8 | public interface ICacheManager 9 | { 10 | void SaveCacheToDisk(); 11 | 12 | void StoreNormalisedChannelName(string name, string normalisedName); 13 | string GetNormalisedChannelName(string name); 14 | 15 | void StoreSslCertificate(string host, X509Certificate2 certificate); 16 | X509Certificate2 GetSslCertificate(string host); 17 | 18 | void StoreStreamStatus(MediaStreamStatus status); 19 | MediaStreamStatus GetStreamStatus(string url); 20 | 21 | void StoreWebDownload(string url, string content); 22 | string GetWebDownload(string url); 23 | 24 | void StorePlaylist(string fileContent, Playlist playlist); 25 | Playlist GetPlaylist(string fileContent); 26 | 27 | void StorePlaylistFile(string name, DateTime date, string content); 28 | string GetPlaylistFile(string name, DateTime date); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Mapping/GroupMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | using IptvPlaylistAggregator.DataAccess.DataObjects; 5 | using IptvPlaylistAggregator.Service.Models; 6 | 7 | namespace IptvPlaylistAggregator.Service.Mapping 8 | { 9 | internal static class GroupMapping 10 | { 11 | internal static Group ToServiceModel(this GroupEntity dataObject) => new() 12 | { 13 | Id = dataObject.Id, 14 | IsEnabled = dataObject.IsEnabled, 15 | Name = dataObject.Name, 16 | Priority = dataObject.Priority 17 | }; 18 | 19 | internal static GroupEntity ToDataObject(this Group serviceModel) => new() 20 | { 21 | Id = serviceModel.Id, 22 | IsEnabled = serviceModel.IsEnabled, 23 | Name = serviceModel.Name, 24 | Priority = serviceModel.Priority 25 | }; 26 | 27 | internal static IEnumerable ToServiceModels(this IEnumerable dataObjects) 28 | => dataObjects.Select(dataObject => dataObject.ToServiceModel()); 29 | 30 | internal static IEnumerable ToEntities(this IEnumerable serviceModels) 31 | => serviceModels.Select(serviceModel => serviceModel.ToDataObject()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Mapping/ChannelDefinitionMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | using IptvPlaylistAggregator.DataAccess.DataObjects; 5 | using IptvPlaylistAggregator.Service.Models; 6 | 7 | namespace IptvPlaylistAggregator.Service.Mapping 8 | { 9 | internal static class ChannelDefinitionMapping 10 | { 11 | internal static ChannelDefinition ToServiceModel(this ChannelDefinitionEntity dataObject) => new() 12 | { 13 | Id = dataObject.Id, 14 | IsEnabled = dataObject.IsEnabled, 15 | Name = new(dataObject.Name, dataObject.Country, dataObject.Aliases), 16 | Country = dataObject.Country, 17 | GroupId = dataObject.GroupId, 18 | LogoUrl = dataObject.LogoUrl 19 | }; 20 | 21 | internal static ChannelDefinitionEntity ToDataObject(this ChannelDefinition serviceModel) => new() 22 | { 23 | Id = serviceModel.Id, 24 | IsEnabled = serviceModel.IsEnabled, 25 | Name = serviceModel.Name.Value, 26 | Country = serviceModel.Country, 27 | GroupId = serviceModel.GroupId, 28 | LogoUrl = serviceModel.LogoUrl, 29 | Aliases = serviceModel.Name.Aliases.ToList() 30 | }; 31 | 32 | internal static IEnumerable ToServiceModels(this IEnumerable dataObjects) 33 | => dataObjects.Select(dataObject => dataObject.ToServiceModel()); 34 | 35 | internal static IEnumerable ToEntities(this IEnumerable serviceModels) 36 | => serviceModels.Select(serviceModel => serviceModel.ToDataObject()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/IptvPlaylistAggregator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | IptvPlaylistAggregator 7 | 8 | 9 | 10 | PreserveNewest 11 | PreserveNewest 12 | PreserveNewest 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | PreserveNewest 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/Mapping/PlaylistProviderMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | using IptvPlaylistAggregator.DataAccess.DataObjects; 5 | using IptvPlaylistAggregator.Service.Models; 6 | 7 | namespace IptvPlaylistAggregator.Service.Mapping 8 | { 9 | internal static class PlaylistProviderMapping 10 | { 11 | internal static PlaylistProvider ToServiceModel(this PlaylistProviderEntity dataObject) => new() 12 | { 13 | Id = dataObject.Id, 14 | IsEnabled = dataObject.IsEnabled, 15 | Priority = dataObject.Priority, 16 | AllowCaching = dataObject.AllowCaching, 17 | Name = dataObject.Name, 18 | UrlFormat = dataObject.UrlFormat, 19 | Country = dataObject.Country, 20 | ChannelNameOverride = dataObject.ChannelNameOverride 21 | }; 22 | 23 | internal static PlaylistProviderEntity ToDataObject(this PlaylistProvider serviceModel) => new() 24 | { 25 | Id = serviceModel.Id, 26 | IsEnabled = serviceModel.IsEnabled, 27 | Priority = serviceModel.Priority, 28 | AllowCaching = serviceModel.AllowCaching, 29 | Name = serviceModel.Name, 30 | UrlFormat = serviceModel.UrlFormat, 31 | Country = serviceModel.Country, 32 | ChannelNameOverride = serviceModel.ChannelNameOverride 33 | }; 34 | 35 | internal static IEnumerable ToServiceModels(this IEnumerable dataObjects) 36 | => dataObjects.Select(dataObject => dataObject.ToServiceModel()); 37 | 38 | internal static IEnumerable ToEntities(this IEnumerable serviceModels) 39 | => serviceModels.Select(serviceModel => serviceModel.ToDataObject()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/FileDownloader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading.Tasks; 4 | using NuciWeb.HTTP; 5 | 6 | namespace IptvPlaylistAggregator.Service 7 | { 8 | public sealed class FileDownloader : IFileDownloader 9 | { 10 | private readonly ICacheManager cache; 11 | private readonly HttpClient httpClient; 12 | 13 | public FileDownloader(ICacheManager cache) 14 | { 15 | this.cache = cache; 16 | 17 | httpClient = HttpClientCreator.Create(); 18 | httpClient.Timeout = TimeSpan.FromSeconds(3); 19 | } 20 | 21 | public async Task TryDownloadStringAsync(string url) 22 | { 23 | string content = cache.GetWebDownload(url); 24 | 25 | if (content is not null) 26 | { 27 | return content; 28 | } 29 | 30 | try 31 | { 32 | content = await GetAsync(url); 33 | } 34 | catch 35 | { 36 | return null; 37 | } 38 | 39 | cache.StoreWebDownload(url, content); 40 | 41 | return content; 42 | } 43 | 44 | private async Task GetAsync(string url) 45 | { 46 | if (string.IsNullOrWhiteSpace(url)) 47 | { 48 | return null; 49 | } 50 | 51 | string content = await SendGetRequestAsync(url); 52 | cache.StoreWebDownload(url, content); 53 | 54 | return content; 55 | } 56 | 57 | private async Task SendGetRequestAsync(string url) 58 | { 59 | using HttpResponseMessage response = await httpClient.GetAsync(url); 60 | using HttpContent content = response.Content; 61 | 62 | return await content.ReadAsStringAsync(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.6.30114.105 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{6C08895A-A364-4051-9BF5-5F35FCDD07AC}") = "IptvPlaylistAggregator", "IptvPlaylistAggregator\IptvPlaylistAggregator.csproj", "{9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}" 7 | EndProject 8 | Project("{6C08895A-A364-4051-9BF5-5F35FCDD07AC}") = "IptvPlaylistAggregator.UnitTests", "IptvPlaylistAggregator.UnitTests\IptvPlaylistAggregator.UnitTests.csproj", "{70DDC29A-AE81-4069-9714-B8F1F1B7A831}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Debug|x64.ActiveCfg = Debug|Any CPU 26 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Debug|x64.Build.0 = Debug|Any CPU 27 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Debug|x86.ActiveCfg = Debug|Any CPU 28 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Debug|x86.Build.0 = Debug|Any CPU 29 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Release|x64.ActiveCfg = Release|Any CPU 32 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Release|x64.Build.0 = Release|Any CPU 33 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Release|x86.ActiveCfg = Release|Any CPU 34 | {9BF6E191-B3C4-4772-B28C-F6F86CFE60CA}.Release|x86.Build.0 = Release|Any CPU 35 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Debug|x64.ActiveCfg = Debug|Any CPU 38 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Debug|x64.Build.0 = Debug|Any CPU 39 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Debug|x86.ActiveCfg = Debug|Any CPU 40 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Debug|x86.Build.0 = Debug|Any CPU 41 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Release|x64.ActiveCfg = Release|Any CPU 44 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Release|x64.Build.0 = Release|Any CPU 45 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Release|x86.ActiveCfg = Release|Any CPU 46 | {70DDC29A-AE81-4069-9714-B8F1F1B7A831}.Release|x86.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator.UnitTests/Service/MediaSourceCheckerTests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using NuciLog.Core; 3 | using NUnit.Framework; 4 | 5 | using IptvPlaylistAggregator.Configuration; 6 | using IptvPlaylistAggregator.Service; 7 | 8 | namespace IptvPlaylistAggregator.UnitTests.Service 9 | { 10 | public sealed class MediaSourceCheckerTests 11 | { 12 | private Mock fileDownloaderMock; 13 | private Mock playlistFileBuilderMock; 14 | private Mock cacheMock; 15 | private Mock loggerMock; 16 | private ApplicationSettings applicationSettings; 17 | 18 | private MediaSourceChecker mediaSourceChecker; 19 | 20 | [SetUp] 21 | public void SetUp() 22 | { 23 | fileDownloaderMock = new(); 24 | playlistFileBuilderMock = new(); 25 | cacheMock = new(); 26 | loggerMock = new(); 27 | applicationSettings = new(); 28 | 29 | mediaSourceChecker = new( 30 | fileDownloaderMock.Object, 31 | playlistFileBuilderMock.Object, 32 | cacheMock.Object, 33 | loggerMock.Object, 34 | applicationSettings); 35 | } 36 | 37 | [TestCase("https://www.youtube.com/watch?v=fxFIgBld95E")] 38 | [Test] 39 | public void GivenTheSourceIsYouTubeVideo_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 40 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 41 | 42 | [TestCase("https://dotto.edvr.ro/dottotv_1603019528.mp4")] 43 | [TestCase("https://iptvcat.com/assets/videos/lazycat-iptvcat.com.mp4?fluxustv.m3u8")] 44 | [TestCase("https://iptvcat.com/assets/videos/lazycat-iptvcat.com.mp4")] 45 | [Test] 46 | public void GivenTheSourceIsShortenedUrl_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 47 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 48 | 49 | [TestCase("https://tinyurl.com/y9k7rbje")] 50 | [Test] 51 | public void GivenTheSourceIsAnMP4File_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 52 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 53 | 54 | [TestCase("mms://86.34.169.52:8080/")] 55 | [TestCase("mms://musceltvlive.muscel.ro:8080")] 56 | [Test] 57 | public void GivenTheSourceIsUsingTeMmsProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 58 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 59 | 60 | [TestCase("mmsh://82.137.6.58:1234/")] 61 | [TestCase("mmsh://musceltvlive.muscel.ro:8080")] 62 | [Test] 63 | public void GivenTheSourceIsUsingTeMmshProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 64 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 65 | 66 | [TestCase("rtmp://212.0.209.209:1935/live/_definst_mp4:Moldova")] 67 | [TestCase("rtmp://81.18.66.155/live/banat-tv")] 68 | [TestCase("rtmp://86.106.82.47/baricadatv_live/livestream")] 69 | [TestCase("rtmp://89.33.78.174:1935/live/livestream")] 70 | [TestCase("rtmp://89.33.78.174/live/livestream")] 71 | [TestCase("rtmp://columna1.arya.ro/live//columnatv1")] 72 | [TestCase("rtmp://columna1.arya.ro/live/columnatv1")] 73 | [TestCase("rtmp://direct.multimedianet.ro:1935/live/livestream")] 74 | [TestCase("rtmp://gtv1.arya.ro:1935/live/gtv1.flv")] 75 | [TestCase("rtmp://rapsodia1.arya.ro/live//rapsodiatv1")] 76 | [TestCase("rtmp://rapsodia1.arya.ro/live/rapsodiatv1")] 77 | [TestCase("rtmp://streaming.tvmures.ro:1935/live/ttm")] 78 | [TestCase("rtmp://streaming.tvsatrm.ro/live/tvsat")] 79 | [TestCase("rtmp://traditii1.arya.ro/live/traditiitv1")] 80 | [TestCase("rtmp://v1.arya.ro:1935/live/ptv1.flv")] 81 | [Test] 82 | public void GivenTheSourceIsUsingTeRtmpProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 83 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 84 | 85 | [TestCase("rtsp://195.64.178.23/somax")] 86 | [TestCase("rtsp://195.64.178.23/telem")] 87 | [TestCase("rtsp://212.0.209.209:1935/live/_definst_/mp4:MoldovaUnu1")] 88 | [TestCase("rtsp://83.218.202.202:1935/live/wt_publika.stream")] 89 | [TestCase("rtsp://live.trm.md:1935/live/M1Mlive")] 90 | [Test] 91 | public void GivenTheSourceIsUsingTeRtspProtocol_WhenCheckingThatItIsPlayable_ThenFalseIsReturned(string sourceUrl) 92 | => AssertThatSourceUrlIsNotPlayable(sourceUrl); 93 | 94 | private void AssertThatSourceUrlIsNotPlayable(string sourceUrl) 95 | => Assert.That(!mediaSourceChecker.IsSourcePlayableAsync(sourceUrl).Result); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Data/groups.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | general 6 | true 7 | 1 8 | Generale 9 | 10 | 11 | 12 | news 13 | true 14 | 4 15 | Știri 16 | 17 | 18 | 19 | entertainment 20 | true 21 | 7 22 | Divertisment 23 | 24 | 25 | 26 | movies 27 | true 28 | 10 29 | Filme 30 | 31 | 32 | 33 | educational 34 | true 35 | 15 36 | Documentare 37 | 38 | 39 | 40 | thematic 41 | true 42 | 20 43 | Tematice 44 | 45 | 46 | 47 | sport 48 | true 49 | 25 50 | Sport 51 | 52 | 53 | 54 | international 55 | true 56 | 30 57 | Internaționale 58 | 59 | 60 | 61 | local-crisana 62 | true 63 | 31 64 | Locale (Crișana) 65 | 66 | 67 | 68 | local-transilvania 69 | true 70 | 32 71 | Locale (Transilvania) 72 | 73 | 74 | 75 | local-maramures 76 | true 77 | 33 78 | Locale (Maramureș) 79 | 80 | 81 | 82 | local-banat 83 | true 84 | 34 85 | Locale (Banat) 86 | 87 | 88 | 89 | local-muntenia 90 | true 91 | 35 92 | Locale (Muntenia) 93 | 94 | 95 | 96 | local-oltenia 97 | true 98 | 36 99 | Locale (Oltenia) 100 | 101 | 102 | 103 | local-dobrogea 104 | true 105 | 37 106 | Locale (Dobrogea) 107 | 108 | 109 | 110 | local-bucovina 111 | true 112 | 38 113 | Locale (Bucovina) 114 | 115 | 116 | 117 | local-moldova 118 | true 119 | 39 120 | Locale (Moldova) 121 | 122 | 123 | 124 | local-basarabia 125 | true 126 | 40 127 | Locale (Basarabia) 128 | 129 | 130 | 131 | local-unknown 132 | true 133 | 41 134 | Locale (???) 135 | 136 | 137 | 138 | unknown 139 | true 140 | 45 141 | Necunoscute 142 | 143 | 144 | 145 | kids 146 | true 147 | 60 148 | Copii 149 | 150 | 151 | 152 | religious 153 | true 154 | 70 155 | Religioase 156 | 157 | 158 | 159 | foreign 160 | true 161 | 80 162 | Străine 163 | 164 | 165 | 166 | music 167 | true 168 | 90 169 | Muzică 170 | 171 | 172 | 173 | radio 174 | true 175 | 100 176 | Radio 177 | 178 | 179 | 180 | porn 181 | false 182 | 900 183 | Erotice 184 | 185 | 186 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | using NuciDAL.Repositories; 8 | using NuciLog; 9 | using NuciLog.Configuration; 10 | using NuciLog.Core; 11 | using NuciWeb.HTTP; 12 | 13 | using IptvPlaylistAggregator.Configuration; 14 | using IptvPlaylistAggregator.DataAccess.DataObjects; 15 | using IptvPlaylistAggregator.Logging; 16 | using IptvPlaylistAggregator.Service; 17 | 18 | namespace IptvPlaylistAggregator 19 | { 20 | public class Program 21 | { 22 | private static ApplicationSettings applicationSettings; 23 | private static CacheSettings cacheSettings; 24 | private static DataStoreSettings dataStoreSettings; 25 | private static NuciLoggerSettings nuciLoggerSettings; 26 | 27 | private static ILogger logger; 28 | private static ICacheManager cacheManager; 29 | 30 | public static void Main(string[] args) 31 | { 32 | IConfiguration config = LoadConfiguration(); 33 | 34 | applicationSettings = new ApplicationSettings(); 35 | cacheSettings = new CacheSettings(); 36 | dataStoreSettings = new DataStoreSettings(); 37 | nuciLoggerSettings = new NuciLoggerSettings(); 38 | 39 | config.Bind(nameof(ApplicationSettings), applicationSettings); 40 | config.Bind(nameof(CacheSettings), cacheSettings); 41 | config.Bind(nameof(DataStoreSettings), dataStoreSettings); 42 | config.Bind(nameof(NuciLoggerSettings), nuciLoggerSettings); 43 | 44 | IServiceProvider serviceProvider = new ServiceCollection() 45 | .AddSingleton(applicationSettings) 46 | .AddSingleton(cacheSettings) 47 | .AddSingleton(dataStoreSettings) 48 | .AddSingleton(nuciLoggerSettings) 49 | .AddSingleton() 50 | .AddSingleton() 51 | .AddSingleton() 52 | .AddSingleton() 53 | .AddSingleton() 54 | .AddSingleton() 55 | .AddSingleton() 56 | .AddSingleton>(s => new XmlRepository(dataStoreSettings.ChannelStorePath)) 57 | .AddSingleton>(s => new XmlRepository(dataStoreSettings.GroupStorePath)) 58 | .AddSingleton>(s => new XmlRepository(dataStoreSettings.PlaylistProviderStorePath)) 59 | .AddSingleton() 60 | .BuildServiceProvider(); 61 | 62 | logger = serviceProvider.GetService(); 63 | cacheManager = serviceProvider.GetService(); 64 | 65 | logger.Info(Operation.StartUp, OperationStatus.Success); 66 | 67 | if (!NetworkUtils.HasInternetAccess()) 68 | { 69 | logger.Fatal(Operation.StartUp, OperationStatus.Failure, "No internet access detected. Please check the network connection."); 70 | return; 71 | } 72 | 73 | try 74 | { 75 | IPlaylistAggregator aggregator = serviceProvider.GetService(); 76 | 77 | string playlistFile = aggregator.GatherPlaylist(); 78 | File.WriteAllText(applicationSettings.OutputPlaylistPath, playlistFile); 79 | } 80 | catch (AggregateException ex) 81 | { 82 | LogInnerExceptions(ex); 83 | } 84 | catch (Exception ex) 85 | { 86 | logger.Fatal(Operation.Unknown, OperationStatus.Failure, ex); 87 | } 88 | 89 | SaveCacheToDisk(); 90 | 91 | logger.Info(Operation.ShutDown, OperationStatus.Success); 92 | } 93 | 94 | private static IConfiguration LoadConfiguration() 95 | => new ConfigurationBuilder() 96 | .AddJsonFile("appsettings.json", true, true) 97 | .Build(); 98 | 99 | private static void LogInnerExceptions(AggregateException exception) 100 | { 101 | foreach (Exception innerException in exception.InnerExceptions) 102 | { 103 | if (innerException is not AggregateException) 104 | { 105 | logger.Fatal(Operation.Unknown, OperationStatus.Failure, innerException); 106 | } 107 | else 108 | { 109 | LogInnerExceptions(innerException as AggregateException); 110 | } 111 | } 112 | } 113 | 114 | private static void SaveCacheToDisk() 115 | { 116 | logger.Info(MyOperation.CacheSaving, OperationStatus.Started); 117 | cacheManager.SaveCacheToDisk(); 118 | logger.Debug(MyOperation.CacheSaving, OperationStatus.Success); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/ChannelMatcher.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Text.RegularExpressions; 5 | 6 | using NuciExtensions; 7 | 8 | using IptvPlaylistAggregator.Service.Models; 9 | 10 | namespace IptvPlaylistAggregator.Service 11 | { 12 | public sealed class ChannelMatcher(ICacheManager cache) : IChannelMatcher 13 | { 14 | private static readonly string[] SubstringsToStrip = [ "www.iptvsource.com", "iptvsource.com", "backup" ]; 15 | 16 | private static readonly IDictionary TextReplacements = new Dictionary 17 | { 18 | { "^\\s+", "" }, 19 | { "\\s+$", "" }, 20 | { "&", "&" }, 21 | 22 | { "[\\(\\[]]*([Aa]uto|[Bb]|[Bb]ackup|[Ll]ive [Oo]n [Mm]atches|[Mm]atch[ -]*[Tt]ime|[Mm]ulti-*[Aa]udio|[Mm]ulti-*[Ss]ub|[Nn]ew!*|[Oo]n-[Dd]emand)[\\)\\]]*", "" }, 23 | { "(.)[ \\.:_\\-\\|\\[\\(\\]\\)\"]+(Ultra|Full|[FU])*[_-]*[HMS][DQ]", "$1" }, 24 | { "4[Kk]\\+", "" }, 25 | { "\\((270|406|480|540|576|720|1080|2160)p\\)", "" }, 26 | 27 | { "\\[Not 24/7\\]", "" }, 28 | { "\\[Geo-blocked\\]", "" }, 29 | 30 | { "^(.+)\\s+VIP\\s+([A-Z][A-Z])\\s*$", "$2: $1" }, 31 | 32 | { "RO\\(L\\) *[\\|\\[\\(\\]\\)\".:-]", "RO:" }, 33 | 34 | { "^([\\|\\[\\(\\]\\)\".:-]* *([A-Z][A-Z]) *[\\|\\[\\(\\]\\)\".:-] *)+", "$2:" }, 35 | { "^([A-Z][A-Z]): *(.*) \\(*\\1\\)*$", "$1: $2" }, 36 | 37 | { "Moldavia", "Moldova" }, 38 | { "RUMANIA", "Romania" }, 39 | 40 | { "^((?!RO).*) *Moldova$", "MD: $1" }, 41 | { "(.+) +\\(Moldova\\)$", "MD: $1" }, 42 | { "(.+) +\\(Romania\\)$", "RO: $1" }, 43 | { "(.+) +\\(*(RO|MD)\\)*$", "$2: $1" }, 44 | { "^RO *[\\|\\[\\(\\]\\)\".:-] *(.*) *\\(*Romania\\)*$", "RO: $1" }, 45 | 46 | { "^[\\|\\[\\(\\]\\)\".:-]* *Romania *[\\|\\[\\(\\]\\)\".:-]", "RO:" }, 47 | 48 | { " S[0-9]-[0-9]$", "" }, 49 | { " S[0-9]$", "" }, 50 | { "\\(18\\+\\)", "" }, 51 | { "\\(Opt-[0-9]\\)", "" }, 52 | { "[\\[\\(][0-9]*p[\\]\\)]", "" }, 53 | 54 | { " HEVC$", "" }, 55 | { " HEVC ", "" }, 56 | 57 | { "^RO ", "RO: " }, 58 | { " \\(*ROM\\)*$", "" }, 59 | { " *[\\|\\()]*ROM*[\\|\\):]", "RO:" }, 60 | { "^Romania[n]*:", "RO:" }, 61 | { "^[\\|]*VIP *([A-Z][A-Z]):", "$1:" }, 62 | 63 | { "^([A-Z][A-Z]: *)*", "$1" }, 64 | 65 | { "^(RO: *)*", "" }, 66 | }; 67 | 68 | private readonly ICacheManager cache = cache; 69 | 70 | public string NormaliseName(string name, string country) 71 | { 72 | string fullName = name; 73 | 74 | if (!string.IsNullOrWhiteSpace(country)) 75 | { 76 | fullName = $"{country}: {name}"; 77 | } 78 | 79 | string normalisedName = cache.GetNormalisedChannelName(fullName); 80 | 81 | if (!string.IsNullOrWhiteSpace(normalisedName)) 82 | { 83 | return normalisedName; 84 | } 85 | 86 | normalisedName = fullName.RemoveDiacritics(); 87 | normalisedName = StripChannelName(normalisedName); 88 | normalisedName = normalisedName.ToUpper(); 89 | 90 | cache.StoreNormalisedChannelName(fullName, normalisedName); 91 | 92 | return normalisedName; 93 | } 94 | 95 | public bool DoesMatch(ChannelName name1, string name2, string country2) 96 | => DoChannelNamesMatch(name1.Value, name1.Country, name2, country2) || 97 | name1.Aliases.Any(name1alias => DoChannelNamesMatch(name1alias, name1.Country, name2, country2)); 98 | 99 | private bool DoChannelNamesMatch(string name1, string country1, string name2, string country2) 100 | => name1.Equals(name2) || NormaliseName(name1, country1).Equals(NormaliseName(name2, country2)); 101 | 102 | private static string StripChannelName(string name) 103 | { 104 | const string allowedChars = 105 | "abcdefghijklmnopqrstuvwxyz" + 106 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + 107 | "0123456789"; 108 | 109 | string strippedName = name; 110 | 111 | foreach (string substringToStrip in SubstringsToStrip) 112 | { 113 | strippedName = strippedName.Replace(substringToStrip, "", true, CultureInfo.InvariantCulture); 114 | } 115 | 116 | foreach (string pattern in TextReplacements.Keys) 117 | { 118 | strippedName = Regex.Replace( 119 | strippedName, 120 | pattern, 121 | TextReplacements[pattern], 122 | RegexOptions.IgnoreCase); 123 | } 124 | 125 | string finalString = string.Empty; 126 | 127 | foreach (char c in strippedName) 128 | { 129 | if (allowedChars.Contains(c)) 130 | { 131 | finalString += c; 132 | } 133 | } 134 | 135 | return finalString; 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/PlaylistFileBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using IptvPlaylistAggregator.Configuration; 6 | using IptvPlaylistAggregator.Service.Models; 7 | 8 | namespace IptvPlaylistAggregator.Service 9 | { 10 | public sealed class PlaylistFileBuilder( 11 | ICacheManager cache, 12 | ApplicationSettings settings) : IPlaylistFileBuilder 13 | { 14 | private const string FileHeader = "#EXTM3U"; 15 | private const string EntryHeader = "#EXTINF"; 16 | private const string EntryHeaderExtendedInfo = "#EXT-X-STREAM-INF"; 17 | private const string EntryHeaderSeparator = ":"; 18 | private const string EntryValuesSeparator = ","; 19 | private const string TvGuideChannelNumberTagKey = "tvg-chno"; 20 | private const string TvGuideNameTagKey = "tvg-name"; 21 | private const string TvGuideIdTagKey = "tvg-id"; 22 | private const string TvGuideLogoTagKey = "tvg-logo"; 23 | private const string TvGuideCountryTagKey = "tvg-country"; 24 | private const string TvGuideGroupTagKey = "group-title"; 25 | private const string PlaylistIdTagKey = "playlist-id"; 26 | private const string PlaylistChannelNameTagKey = "playlist-channel-name"; 27 | private const int DefaultEntryRuntime = -1; 28 | 29 | private readonly ICacheManager cache = cache; 30 | private readonly ApplicationSettings settings = settings; 31 | 32 | public string BuildFile(Playlist playlist) 33 | { 34 | string file = FileHeader + Environment.NewLine; 35 | 36 | foreach (Channel channel in playlist.Channels) 37 | { 38 | file += 39 | $"{EntryHeader}{EntryHeaderSeparator}" + 40 | $"{DefaultEntryRuntime}"; 41 | 42 | if (settings.AreTvGuideTagsEnabled) 43 | { 44 | file += BuildTvGuideHeaderTags(channel); 45 | } 46 | 47 | if (settings.ArePlaylistDetailsTagsEnabled) 48 | { 49 | file += BuildPlaylistDetailsHeaderTags(channel); 50 | } 51 | 52 | file += 53 | $"{EntryValuesSeparator}{channel.Name}{Environment.NewLine}" + 54 | $"{channel.Url}{Environment.NewLine}"; 55 | } 56 | 57 | return file; 58 | } 59 | 60 | public Playlist TryParseFile(string file) 61 | { 62 | if (string.IsNullOrWhiteSpace(file)) 63 | { 64 | return null; 65 | } 66 | 67 | try 68 | { 69 | return ParseFile(file); 70 | } 71 | catch 72 | { 73 | return null; 74 | } 75 | } 76 | 77 | public Playlist ParseFile(string content) 78 | { 79 | Playlist playlist = cache.GetPlaylist(content); 80 | 81 | if (playlist is not null) 82 | { 83 | return playlist; 84 | } 85 | 86 | playlist = new Playlist(); 87 | 88 | if (string.IsNullOrWhiteSpace(content)) 89 | { 90 | throw new ArgumentNullException(nameof(content)); 91 | } 92 | 93 | IEnumerable lines = content 94 | .Replace("\r", "") 95 | .Split('\n') 96 | .Where(x => !string.IsNullOrWhiteSpace(x)); 97 | 98 | foreach (string line in lines) 99 | { 100 | if (line.StartsWith(EntryHeader)) 101 | { 102 | string[] lineSplit = line.Split(','); 103 | 104 | Channel channel = new() 105 | { 106 | Name = lineSplit[lineSplit.Length - 1] 107 | }; 108 | channel.PlaylistChannelName = channel.Name; 109 | 110 | playlist.Channels.Add(channel); 111 | } 112 | else if (line.StartsWith(EntryHeaderExtendedInfo)) 113 | { 114 | Channel channel = new(); 115 | // TODO: Where should I take the name from ??? 116 | 117 | playlist.Channels.Add(channel); 118 | } 119 | else if (line.StartsWith('#')) 120 | { 121 | continue; 122 | } 123 | else 124 | { 125 | playlist.Channels.Last().Url = line; 126 | } 127 | } 128 | 129 | cache.StorePlaylist(content, playlist); 130 | 131 | return playlist; 132 | } 133 | 134 | private static string BuildTvGuideHeaderTags(Channel channel) 135 | { 136 | string tvgTags = 137 | $" {TvGuideChannelNumberTagKey}=\"{channel.Number}\"" + 138 | $" {TvGuideIdTagKey}=\"{channel.Id}\"" + 139 | $" {TvGuideNameTagKey}=\"{channel.Name}\""; 140 | 141 | if (!string.IsNullOrWhiteSpace(channel.LogoUrl)) 142 | { 143 | tvgTags += $" {TvGuideLogoTagKey}=\"{channel.LogoUrl}\""; 144 | } 145 | 146 | if (!string.IsNullOrWhiteSpace(channel.Country)) 147 | { 148 | tvgTags += $" {TvGuideCountryTagKey}=\"{channel.Country}\""; 149 | } 150 | 151 | if (!string.IsNullOrWhiteSpace(channel.Group)) 152 | { 153 | tvgTags += $" {TvGuideGroupTagKey}=\"{channel.Group}\""; 154 | } 155 | 156 | return tvgTags; 157 | } 158 | 159 | private static string BuildPlaylistDetailsHeaderTags(Channel channel) 160 | => $" {PlaylistIdTagKey}=\"{channel.PlaylistId}\"" + 161 | $" {PlaylistChannelNameTagKey}=\"{channel.PlaylistChannelName}\""; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/PlaylistFetcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using NuciLog.Core; 8 | 9 | using IptvPlaylistAggregator.Configuration; 10 | using IptvPlaylistAggregator.Logging; 11 | using IptvPlaylistAggregator.Service.Models; 12 | 13 | namespace IptvPlaylistAggregator.Service 14 | { 15 | public sealed class PlaylistFetcher( 16 | IFileDownloader fileDownloader, 17 | IPlaylistFileBuilder playlistFileBuilder, 18 | ICacheManager cache, 19 | ApplicationSettings applicationSettings, 20 | ILogger logger) : IPlaylistFetcher 21 | { 22 | private readonly IFileDownloader fileDownloader = fileDownloader; 23 | private readonly IPlaylistFileBuilder playlistFileBuilder = playlistFileBuilder; 24 | private readonly ICacheManager cache = cache; 25 | private readonly ApplicationSettings applicationSettings = applicationSettings; 26 | private readonly ILogger logger = logger; 27 | 28 | public IEnumerable FetchProviderPlaylists(IEnumerable providers) 29 | { 30 | ConcurrentDictionary playlists = new(); 31 | 32 | logger.Info(MyOperation.PlaylistFetching, OperationStatus.Started, "Fetching provider playlists"); 33 | 34 | List tasks = []; 35 | 36 | foreach (PlaylistProvider provider in providers) 37 | { 38 | Task task = Task.Run(async () => 39 | { 40 | Playlist playlist = await FetchProviderPlaylistAsync(provider); 41 | 42 | if (!Playlist.IsNullOrEmpty(playlist)) 43 | { 44 | playlists.AddOrUpdate( 45 | provider.Priority, 46 | playlist, 47 | (key, oldValue) => playlist); 48 | 49 | if (!string.IsNullOrWhiteSpace(provider.Country)) 50 | { 51 | foreach (Channel channel in playlist.Channels) 52 | { 53 | channel.Country = provider.Country; 54 | } 55 | } 56 | } 57 | }); 58 | 59 | tasks.Add(task); 60 | } 61 | 62 | Task.WaitAll(tasks.ToArray()); 63 | 64 | return playlists 65 | .OrderBy(x => x.Key) 66 | .Select(x => x.Value); 67 | } 68 | 69 | public async Task FetchProviderPlaylistAsync(PlaylistProvider provider) 70 | { 71 | Playlist playlist = await GetPlaylistAsync(provider); 72 | 73 | if (Playlist.IsNullOrEmpty(playlist)) 74 | { 75 | logger.Debug( 76 | MyOperation.PlaylistFetching, 77 | OperationStatus.Failure, 78 | new LogInfo(MyLogInfoKey.Provider, provider.Name)); 79 | 80 | return null; 81 | } 82 | 83 | foreach (Channel channel in playlist.Channels) 84 | { 85 | channel.PlaylistId = provider.Id; 86 | 87 | if (!string.IsNullOrWhiteSpace(provider.ChannelNameOverride)) 88 | { 89 | channel.Name = provider.ChannelNameOverride; 90 | } 91 | } 92 | 93 | logger.Debug( 94 | MyOperation.PlaylistFetching, 95 | OperationStatus.Success, 96 | new LogInfo(MyLogInfoKey.Provider, provider.Name)); 97 | 98 | return playlist; 99 | } 100 | 101 | private async Task GetPlaylistAsync(PlaylistProvider provider) 102 | { 103 | Playlist playlist = await GetPlaylistForTodayAsync(provider); 104 | 105 | if (Playlist.IsNullOrEmpty(playlist)) 106 | { 107 | playlist = GetPlaylistForPastDays(provider); 108 | } 109 | 110 | return playlist; 111 | } 112 | 113 | private async Task GetPlaylistForTodayAsync(PlaylistProvider provider) 114 | { 115 | string playlistFile = await DownloadPlaylistFileAsync(provider, DateTime.UtcNow); 116 | Playlist playlist = LoadPlaylistFromCache(provider, DateTime.UtcNow); 117 | 118 | playlist ??= playlistFileBuilder.TryParseFile(playlistFile); 119 | 120 | if (provider.AllowCaching && !Playlist.IsNullOrEmpty(playlist)) 121 | { 122 | cache.StorePlaylistFile(provider.Id, DateTime.UtcNow, playlistFile); 123 | } 124 | 125 | return playlist; 126 | } 127 | 128 | private Playlist GetPlaylistForPastDays(PlaylistProvider provider) 129 | { 130 | if (!provider.UrlFormat.Contains("{0")) 131 | { 132 | return null; 133 | } 134 | 135 | Playlist playlist = null; 136 | 137 | for (int i = 1; i < applicationSettings.DaysToCheck; i++) 138 | { 139 | DateTime date = DateTime.UtcNow.AddDays(-i); 140 | 141 | playlist = LoadPlaylistFromCache(provider, date); 142 | 143 | if (playlist is not null) 144 | { 145 | break; 146 | } 147 | } 148 | 149 | return playlist; 150 | } 151 | 152 | private Playlist LoadPlaylistFromCache(PlaylistProvider provider, DateTime date) 153 | { 154 | if (!provider.AllowCaching) 155 | { 156 | return null; 157 | } 158 | 159 | string content = cache.GetPlaylistFile(provider.Id, date); 160 | 161 | if (string.IsNullOrWhiteSpace(content)) 162 | { 163 | return null; 164 | } 165 | 166 | return playlistFileBuilder.TryParseFile(content); 167 | } 168 | 169 | private async Task DownloadPlaylistFileAsync(PlaylistProvider provider, DateTime date) 170 | => await fileDownloader.TryDownloadStringAsync(string.Format(provider.UrlFormat, date)); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/MediaSourceChecker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Text.RegularExpressions; 8 | using System.Threading.Tasks; 9 | 10 | using IptvPlaylistAggregator.Configuration; 11 | using IptvPlaylistAggregator.Logging; 12 | using IptvPlaylistAggregator.Service.Models; 13 | 14 | using NuciLog.Core; 15 | using NuciWeb.HTTP; 16 | 17 | namespace IptvPlaylistAggregator.Service 18 | { 19 | public sealed class MediaSourceChecker( 20 | IFileDownloader fileDownloader, 21 | IPlaylistFileBuilder playlistFileBuilder, 22 | ICacheManager cache, 23 | ILogger logger, 24 | ApplicationSettings applicationSettings) : IMediaSourceChecker 25 | { 26 | private const string YouTubeVideoUrlPattern = "^(https?\\:\\/\\/)?(www\\.youtube\\.com|youtu\\.?be)\\/.+$"; 27 | private const string TinyUrlPattern = "^(https?\\:\\/\\/)?((www\\.)?tinyurl\\.com)\\/.+$"; 28 | private const string NonHttpUrlPattern = "^(?!http).*"; 29 | 30 | private static readonly string[] BlacklistedSources = [ "http://hls.protv.md/acasatv/acasatv.m3u8" ]; 31 | 32 | private readonly IFileDownloader fileDownloader = fileDownloader; 33 | private readonly IPlaylistFileBuilder playlistFileBuilder = playlistFileBuilder; 34 | private readonly ICacheManager cache = cache; 35 | private readonly ILogger logger = logger; 36 | private readonly ApplicationSettings applicationSettings = applicationSettings; 37 | private readonly HttpClient httpClient = HttpClientCreator.Create(); 38 | 39 | public async Task IsSourcePlayableAsync(string url) 40 | { 41 | MediaStreamStatus status = cache.GetStreamStatus(url); 42 | 43 | if (status is not null) 44 | { 45 | return status.IsAlive; 46 | } 47 | 48 | logger.Verbose(MyOperation.MediaSourceCheck, OperationStatus.Started, new LogInfo(MyLogInfoKey.Url, url)); 49 | 50 | StreamState state; 51 | 52 | if (IsUrlUnsupported(url)) 53 | { 54 | state = StreamState.Unsupported; 55 | } 56 | else if (IsUrlBlacklisted(url)) 57 | { 58 | state = StreamState.Blacklisted; 59 | } 60 | else if (url.Contains(".m3u") || url.Contains(".m3u8")) 61 | { 62 | state = await GetPlaylistStateAsync(url); 63 | } 64 | else 65 | { 66 | state = await GetStreamStateAsync(url); 67 | } 68 | 69 | if (state.Equals(StreamState.Alive)) 70 | { 71 | logger.Verbose(MyOperation.MediaSourceCheck, OperationStatus.Success, new LogInfo(MyLogInfoKey.Url, url)); 72 | } 73 | else 74 | { 75 | logger.Verbose(MyOperation.MediaSourceCheck, OperationStatus.Failure, new LogInfo(MyLogInfoKey.Url, url), new LogInfo(MyLogInfoKey.StreamState, state)); 76 | } 77 | 78 | SaveToCache(url, state); 79 | return state.Equals(StreamState.Alive); 80 | } 81 | 82 | private static bool IsUrlUnsupported(string url) 83 | { 84 | if (Regex.IsMatch(url, YouTubeVideoUrlPattern) || 85 | Regex.IsMatch(url, TinyUrlPattern) || 86 | Regex.IsMatch(url, NonHttpUrlPattern)) 87 | { 88 | return true; 89 | } 90 | 91 | if (url.EndsWith(".mp4") || url.Contains(".mp4?")) 92 | { 93 | return true; 94 | } 95 | 96 | return false; 97 | } 98 | 99 | private static bool IsUrlBlacklisted(string url) 100 | { 101 | if (BlacklistedSources.Any(x => x.Contains(url))) 102 | { 103 | return true; 104 | } 105 | 106 | return false; 107 | } 108 | 109 | private async Task GetPlaylistStateAsync(string playlistUrl) 110 | { 111 | if (playlistUrl.Contains("googlevideo")) 112 | { 113 | return StreamState.Alive; 114 | } 115 | 116 | StreamState streamState = await GetStreamStateAsync(playlistUrl); 117 | 118 | if (streamState != StreamState.Alive) 119 | { 120 | return streamState; 121 | } 122 | 123 | string fileContent = await fileDownloader.TryDownloadStringAsync(playlistUrl); 124 | Playlist playlist = playlistFileBuilder.TryParseFile(fileContent); 125 | 126 | if (Playlist.IsNullOrEmpty(playlist)) 127 | { 128 | return StreamState.Dead; 129 | } 130 | 131 | foreach (Channel channel in playlist.Channels) 132 | { 133 | List channelUrlsToCheck = []; 134 | 135 | if (channel.Url.StartsWith("http")) 136 | { 137 | channelUrlsToCheck.Add(channel.Url); 138 | } 139 | else 140 | { 141 | Uri uri = new(playlistUrl); 142 | 143 | channelUrlsToCheck.Add(Path.GetDirectoryName(playlistUrl).Replace(":/", "://") + "/" + channel.Url); 144 | channelUrlsToCheck.Add($"{uri.Scheme}://{uri.Host}/{channel.Url}"); 145 | } 146 | 147 | foreach (string channelUrl in channelUrlsToCheck) 148 | { 149 | bool isPlayable = await IsSourcePlayableAsync(channelUrl); 150 | 151 | if (isPlayable) 152 | { 153 | return StreamState.Alive; 154 | } 155 | } 156 | } 157 | 158 | return StreamState.Dead; 159 | } 160 | 161 | private async Task GetStreamStateAsync(string url) 162 | { 163 | HttpStatusCode statusCode = await GetHttpStatusCode(url); 164 | 165 | if (statusCode.Equals(HttpStatusCode.OK)) 166 | { 167 | return StreamState.Alive; 168 | } 169 | 170 | if (statusCode.Equals(HttpStatusCode.Unauthorized)) 171 | { 172 | return StreamState.Unauthorised; 173 | } 174 | 175 | if (statusCode.Equals(HttpStatusCode.NotFound)) 176 | { 177 | return StreamState.NotFound; 178 | } 179 | 180 | return StreamState.Dead; 181 | } 182 | 183 | private void SaveToCache(string url, StreamState state) 184 | => cache.StoreStreamStatus(new() 185 | { 186 | Url = url, 187 | State = state, 188 | LastCheckTime = DateTime.UtcNow 189 | }); 190 | 191 | private async Task GetHttpStatusCode(string url) 192 | { 193 | HttpStatusCode statusCode = HttpStatusCode.RequestTimeout; 194 | bool doCacheContent = url.Contains(".m3u") || url.Contains(".m3u8"); 195 | string content = string.Empty; 196 | 197 | try 198 | { 199 | using var response = await httpClient.GetAsync(url); 200 | statusCode = response.StatusCode; 201 | 202 | if (doCacheContent) 203 | { 204 | content = await response.Content.ReadAsStringAsync(); 205 | } 206 | } 207 | catch (WebException ex) 208 | { 209 | if (ex.Status is WebExceptionStatus.ProtocolError && 210 | ex.Response is HttpWebResponse response) 211 | { 212 | statusCode = response.StatusCode; 213 | } 214 | } 215 | catch { } 216 | 217 | if (doCacheContent) 218 | { 219 | cache.StoreWebDownload(url, content); 220 | } 221 | 222 | return statusCode; 223 | } 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Donate](https://img.shields.io/badge/-%E2%99%A5%20Donate-%23ff69b4)](https://hmlendea.go.ro/fund.html) [![Build Status](https://github.com/hmlendea/iptv-playlist-aggregator/actions/workflows/dotnet.yml/badge.svg)](https://github.com/hmlendea/iptv-playlist-aggregator/actions/workflows/dotnet.yml) [![Latest GitHub release](https://img.shields.io/github/v/release/hmlendea/iptv-playlist-aggregator)](https://github.com/hmlendea/iptv-playlist-aggregator/releases/latest) 2 | 3 | # About 4 | 5 | IPTV Playlist Aggregator is a tool for downloading IPTV playlists from multiple sources and aggregating their channels into a single playlist. It will match the duplicated channels into a single one, based on their name, and will override any channel data (such as logo, TVG ID, etc) with your own custom one. 6 | 7 | Example use case: 8 | Run as a background service on a Raspberry Pi, to periodically output the playlist to an HTTP server, from where it can be directly accessed by the IPTV application via URL. 9 | 10 | # Contributions 11 | 12 | Feel free to fork and implement any change you consider useful, and open a pull request so that I can review it and merge into the master branch here. 13 | 14 | Rules: 15 | - Make sure that anything you implement workson any OS supported by .NET Core 16 | - Make sure that your code is formatted correctly and it respects the basic C# coding and naming standards 17 | 18 | # Instructions 19 | 20 | ## Compiling 21 | 22 | Firstly you need to make sure you have the .NET Core SDK installed and up to date. 23 | 24 | Chose one of the following methods based on which system you want this service to be running on, and run the command inside of the source directory (where the .csproj is) 25 | 26 | ### For the current system: 27 | 28 | `dotnet publish -c Release` 29 | 30 | The output will be located in `./bin/Release/net5.0` 31 | 32 | ### For a different system: 33 | 34 | `dotnet publish -c Release -r [RID]` 35 | 36 | For a list of all possible RID values, check out [the official documentation](https://docs.microsoft.com/en-us/dotnet/core/rid-catalog). 37 | 38 | The output will be located in `./bin/Release/net5.0/[RID]/'. 39 | 40 | If the target system will have the *.NET Core Runtime* installed, delete or ignore the `./bin/Release/net5.0/[RID]/publish` directory. 41 | If not, use **only** the publish directory, since that one contains all the necessary libraries that the runtime would normally provide. 42 | 43 | ## Running in background as a service 44 | 45 | **Note:** The following instructions only apply for *Linux* distributions using *systemd*. 46 | 47 | Create the following service file: /lib/systemd/system/iptv-playlist-aggregator.service 48 | ``` 49 | [Unit] 50 | Description=IPTV Playlist Aggregator 51 | 52 | [Service] 53 | WorkingDirectory=[ABSOLUTE_PATH_TO_SERVICE_DIRECTORY] 54 | ExecStart=[ABSOLUTE_PATH_TO_SERVICE_DIRECTORY]/IptvPlaylistAggregator 55 | User=[YOUR_USERNAME] 56 | 57 | [Install] 58 | WantedBy=multi-user.target 59 | ``` 60 | 61 | Create the following timer file: /lib/systemd/system/iptv-playlist-aggregator.timer 62 | ``` 63 | [Unit] 64 | Description=Periodically aggregates an IPTV M3U playlist 65 | 66 | [Timer] 67 | OnBootSec=5min 68 | OnUnitActiveSec=50min 69 | 70 | [Install] 71 | WantedBy=timers.target 72 | ``` 73 | 74 | Values that you might want to change: 75 | - *OnBootSec*: the delay before the service is started after the OS is booted 76 | - *OnUnitActiveSec*: how often the service will be triggered 77 | 78 | In the above example, the service will start 5 minutes after boot, and then again once every 50 minutes. 79 | 80 | ## Configuration 81 | 82 | ### Settings 83 | 84 | The settings are stored in the `appsettings.json` file in the root directory. 85 | 86 | - *channelStorePath*: The file where all your channel data is stored 87 | - *groupStorePath*: The file where all your group data is stored 88 | - *playlistProviderStorePath*: The file where all the playlist provider URLs are stored 89 | - *outputPlaylistPath*: The location where the output playlist will be written. Can be used to write directly to an http server 90 | - *cacheDirectoryPath*: The directory where all the cache files will be written. Leave as default unless you specifically require to move it 91 | - *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. 92 | - *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 93 | - *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 94 | - *arePlaylistDetailsTagsEnabled*: Boolean value indicating whether playlist details (playlist ID, the playlist's original channel name) should be included in the output file or not 95 | 96 | ### Channel data 97 | 98 | The channel data file is an XML file, whose name and location is configred in `appsetting.json` by the *channelStorePath* value. 99 | 100 | The file needs to be .NET serializable as an array of ChannelDefinitionEntity objects. 101 | 102 | ChannelDefinitionEntity fields: 103 | - *Id* (string): The TVG ID. If using a TVG provider within your IPTV application, make sure the channel IDs match the TVG IDs of your provider. 104 | - *IsEnabled* (bool): Indicates whether the final playlist will contain this channel or not. Even if enabled, if the group is disabled, the channel will still be omitted. 105 | - *Name* (string): The name of the channel, as displayed in your IPTV application. 106 | - *Country* (string): (Optional) The country where the channel is being broadcasted. The `tvg-country` property will be populated with this value, if it exists. It will also be used uin the channel matching process. 107 | - *GroupId* (string): The ID of the group that this channel will be part of. 108 | - *LogoUrl* (string): The URL to a logo for the channel. Make sure your IPTV application supports the logo format you provide here. 109 | - *Aliases* (string collection): Different variants of the name of the channel, as it can appear in the provider playlists. This is the criteria used to match provider channels to this definition. 110 | 111 | ### Group data 112 | 113 | The group data file is an XML file, whose name and location is configred in `appsetting.json` by the *groupStorePath* value. 114 | 115 | The file needs to be .NET serializable as an array of GroupEntity objects. 116 | 117 | GroupEntity fields: 118 | - *Id* (string): Used for matching channels to this group 119 | - *IsEnabled* (bool): Indicates whether the final playlist will contain channels in this group or not 120 | - *Priority* (int): The order of the group, starting from 1. The lowest value means that the group will appear first in your IPTV application. The playlist will also have its channels sorted based on their group's priority 121 | - *Name* (string): The name of the group, as displayed in your IPTV application. 122 | 123 | ### Providers data 124 | 125 | The providers data file is an XML file, whose name and location is configred in `appsetting.json` by the *playlistProviderStorePath* value. 126 | 127 | The file needs to be .NET serializable as an array of PlaylistProviderDefinitionEntity objects. 128 | 129 | PlaylistProviderDefinitionEntity fields: 130 | - *Id* (string): The ID of the provider. You can put anything here, used only to distinguish between them. 131 | - *IsEnabled* (bool): Indicates whether this provider will be used or not. 132 | - *Priority* (int): The lower the value, the sooner the provider will be processed. Try to make sure the most reliable providers are processed first, as once a channel is matched with a provider, it will be ignored for all other providers after it. 133 | - *AllowCaching* (bool): (Optional) Indicates whether this provider's playlist should be cached or not. Useful when the provider updates the playlist multiple times a day. By default it's true. 134 | - *UrlFormat* (string): The URL to the m3u playlist file of that provider. Replace the date part of the URL with a timestamp format. For example, *2019-05-19* will be replaced with *{0:yyyy-MM-dd}*. The *0* is the calendar day that is processed (today, or one of the previous ones depending on the *daysToCheck* setting) 135 | - *Country* (string): (Optional) If set, the country will be used in the channel matching process. 136 | - *ChannelNameOverride* (string): (Optional) The channel name override for all the channels in the provider's playlist. 137 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Data/providers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | github-hmlendea-ro-indev 6 | true 7 | 1 8 | false 9 | hmlendea's GitHub Channels RO (In-development version) 10 | https://raw.githubusercontent.com/hmlendea/iptv-playlist/refs/heads/ro/md.m3u 11 | RO 12 | 13 | 14 | 15 | github-hmlendea-ro 16 | true 17 | 2 18 | false 19 | hmlendea's GitHub Channels RO 20 | https://raw.githubusercontent.com/hmlendea/iptv-playlist/master/ro.m3u 21 | RO 22 | 23 | 24 | 25 | github-hmlendea-md-indev 26 | true 27 | 3 28 | false 29 | hmlendea's GitHub Channels MD (In-development version) 30 | https://raw.githubusercontent.com/hmlendea/iptv-playlist/refs/heads/md/md.m3u 31 | MD 32 | 33 | 34 | 35 | 36 | github-hmlendea-md 37 | true 38 | 4 39 | false 40 | hmlendea's GitHub Channels MD 41 | https://raw.githubusercontent.com/hmlendea/iptv-playlist/master/md.m3u 42 | MD 43 | 44 | 45 | 46 | github-iptvorg-ro 47 | false 48 | 100 49 | IPTV org's GitHub RO Channels 50 | https://raw.githubusercontent.com/iptv-org/iptv/refs/heads/master/streams/ro.m3u 51 | RO 52 | 53 | 54 | 55 | github-iptvorg-md 56 | false 57 | 101 58 | IPTV org's GitHub MD Channels 59 | https://raw.githubusercontent.com/iptv-org/iptv/refs/heads/master/streams/md.m3u 60 | MD 61 | 62 | 63 | 64 | github-iptvorg-romanian-language 65 | false 66 | 102 67 | IPTV org's GitHub Romanian Language Channels 68 | https://iptv-org.github.io/iptv/languages/ron.m3u 69 | RO 70 | 71 | 72 | 73 | github-freetv-ro 74 | false 75 | 102 76 | Free-'s GitHub RO Channels 77 | https://raw.githubusercontent.com/Free-TV/IPTV/refs/heads/master/playlists/playlist_romania.m3u8 78 | RO 79 | 80 | 81 | 82 | github-freetv-md 83 | false 84 | 103 85 | Free-'s GitHub MD Channels 86 | https://raw.githubusercontent.com/Free-TV/IPTV/refs/heads/master/playlists/playlist_moldova.m3u8 87 | MD 88 | 89 | 90 | 91 | github-chzw2025-ro 92 | true 93 | 110 94 | chzw2025's IPTV GitHub RO Channels 95 | https://raw.githubusercontent.com/chzw2025/iptv2025/refs/heads/master/streams/ro.m3u 96 | RO 97 | 98 | 99 | 100 | github-chzw2025-md 101 | true 102 | 111 103 | chzw2025's IPTV GitHub MD Channels 104 | https://raw.githubusercontent.com/chzw2025/iptv2025/refs/heads/master/streams/md.m3u 105 | MD 106 | 107 | 108 | 109 | github-kilirushi-ro 110 | true 111 | 112 112 | kilirushi's IPTV GitHub RO Channels 113 | https://raw.githubusercontent.com/kilirushi/iptv/refs/heads/master/ro.m3u 114 | RO 115 | 116 | 117 | 118 | github-kilirushi-md 119 | true 120 | 113 121 | kilirushi's IPTV GitHub MD Channels 122 | https://raw.githubusercontent.com/kilirushi/iptv/refs/heads/master/md.m3u 123 | MD 124 | 125 | 126 | 127 | freetuxtv-ro 128 | true 129 | 680 130 | Free Tux TV Romania 131 | http://database.freetuxtv.net/playlists/playlist_webtv_ro.m3u 132 | RO 133 | 134 | 135 | 136 | freetuxtv-ro-alt 137 | true 138 | 681 139 | Free Tux TV Romania (Alternative) 140 | https://database.freetuxtv.net/WebStreamExport/index?format=m3u&status=2&country=ro&isp=all 141 | RO 142 | 143 | 144 | 145 | freetuxtv-md 146 | true 147 | 682 148 | Free Tux TV Moldova 149 | http://database.freetuxtv.net/playlists/playlist_webtv_md.m3u 150 | MD 151 | 152 | 153 | 154 | freetuxtv-md-alt 155 | true 156 | 683 157 | Free Tux TV Moldova (Alternative) 158 | https://database.freetuxtv.net/WebStreamExport/index?format=m3u&status=2&country=md&isp=all 159 | RO 160 | 161 | 162 | 163 | royiptv-ro 164 | true 165 | 690 166 | RoyIPTV TV Romania 167 | https://m3u.royiptv.com/channels/country/ro.m3u 168 | RO 169 | 170 | 171 | 172 | royiptv-md 173 | true 174 | 691 175 | RoyIPTV TV Moldova 176 | https://m3u.royiptv.com/channels/country/md.m3u 177 | MD 178 | 179 | 180 | 181 | github-vb6rocod-ro 182 | true 183 | 1100 184 | vb6rocod's IPTV GitHub RO Channels 185 | https://raw.githubusercontent.com/vb6rocod/hddlinks_android/master/tv/pl/Frecvente.m3u 186 | RO 187 | 188 | 189 | 190 | hmlendea-livestreams-ro 191 | true 192 | 5000 193 | false 194 | hmlendea's livestreams RO 195 | https://www.nucilandia.ro/iptv/livestreams/ro/playlist.m3u 196 | RO 197 | 198 | 199 | 200 | hmlendea-livestreams-md 201 | true 202 | 5001 203 | false 204 | hmlendea's livestreams MD 205 | https://www.nucilandia.ro/iptv/livestreams/md/playlist.m3u 206 | MD 207 | 208 | 209 | 210 | hmlendea-livestreams-int 211 | true 212 | 5002 213 | false 214 | hmlendea's livestreams INT 215 | https://www.nucilandia.ro/iptv/livestreams/int/playlist.m3u 216 | INT 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/CacheManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Security.Cryptography.X509Certificates; 8 | 9 | using NuciExtensions; 10 | 11 | using IptvPlaylistAggregator.Configuration; 12 | using IptvPlaylistAggregator.Service.Models; 13 | 14 | namespace IptvPlaylistAggregator.Service 15 | { 16 | public sealed class CacheManager : ICacheManager 17 | { 18 | private const char CsvFieldSeparator = ','; 19 | private const string TimestampFormat = "yyyy-MM-dd_HH-mm-ss"; 20 | private const string PlaylistFileNameFormat = "{0}_playlist_{1:yyyy-MM-dd}.m3u"; 21 | private const string StreamStatusesFileName = "stream-statuses.csv"; 22 | 23 | private readonly CacheSettings cacheSettings; 24 | 25 | private readonly ConcurrentDictionary normalisedNames; 26 | private readonly ConcurrentDictionary sslCertificates; 27 | private readonly ConcurrentDictionary streamStatuses; 28 | private readonly ConcurrentDictionary webDownloads; 29 | private readonly ConcurrentDictionary playlists; 30 | 31 | public CacheManager(CacheSettings cacheSettings) 32 | { 33 | this.cacheSettings = cacheSettings; 34 | 35 | normalisedNames = new ConcurrentDictionary(); 36 | sslCertificates = new ConcurrentDictionary(); 37 | streamStatuses = new ConcurrentDictionary(); 38 | webDownloads = new ConcurrentDictionary(); 39 | playlists = new ConcurrentDictionary(); 40 | 41 | PrepareFilesystem(); 42 | 43 | LoadStreamStatuses(); 44 | } 45 | 46 | public void SaveCacheToDisk() 47 | => SaveStreamStatuses(); 48 | 49 | public void StoreNormalisedChannelName(string name, string normalisedName) 50 | => normalisedNames.TryAdd(name, normalisedName); 51 | 52 | public string GetNormalisedChannelName(string name) 53 | => normalisedNames.TryGetValue(name); 54 | 55 | public void StoreSslCertificate(string host, X509Certificate2 certificate) 56 | { 57 | if (!string.IsNullOrWhiteSpace(host) && certificate is not null) 58 | { 59 | sslCertificates.TryAdd(host, certificate); 60 | } 61 | } 62 | 63 | public X509Certificate2 GetSslCertificate(string host) 64 | { 65 | if (string.IsNullOrWhiteSpace(host)) 66 | { 67 | return null; 68 | } 69 | 70 | return sslCertificates.TryGetValue(host); 71 | } 72 | 73 | public void StoreStreamStatus(MediaStreamStatus streamStatus) 74 | => streamStatuses.TryAdd(streamStatus.Url, streamStatus); 75 | 76 | public MediaStreamStatus GetStreamStatus(string url) 77 | { 78 | MediaStreamStatus streamStatus = streamStatuses.TryGetValue(url); 79 | 80 | if (string.IsNullOrWhiteSpace(url)) 81 | { 82 | return new MediaStreamStatus() 83 | { 84 | Url = url, 85 | State = StreamState.Dead, 86 | LastCheckTime = DateTime.UtcNow 87 | }; 88 | } 89 | else 90 | { 91 | streamStatus ??= streamStatuses.TryGetValue(url); 92 | } 93 | 94 | return streamStatus; 95 | } 96 | 97 | public void StoreWebDownload(string url, string content) 98 | => webDownloads.TryAdd(url, content ?? string.Empty); 99 | 100 | public string GetWebDownload(string url) 101 | { 102 | string cachedDownload = webDownloads.TryGetValue(url); 103 | 104 | if (cachedDownload is not null) 105 | { 106 | return cachedDownload; 107 | } 108 | 109 | if (string.IsNullOrWhiteSpace(url)) 110 | { 111 | return string.Empty; 112 | } 113 | else 114 | { 115 | cachedDownload = webDownloads.TryGetValue(url); 116 | 117 | if (cachedDownload is not null) 118 | { 119 | return cachedDownload; 120 | } 121 | } 122 | 123 | MediaStreamStatus streamStatus = GetStreamStatus(url); 124 | 125 | if (streamStatus is not null && !streamStatus.IsAlive) 126 | { 127 | return string.Empty; 128 | } 129 | 130 | return null; 131 | } 132 | 133 | public void StorePlaylist(string fileContent, Playlist playlist) 134 | => playlists.TryAdd(fileContent.GetHashCode(), playlist); 135 | 136 | public Playlist GetPlaylist(string fileContent) 137 | => playlists.TryGetValue(fileContent.GetHashCode()); 138 | 139 | public void StorePlaylistFile(string providerId, DateTime date, string content) 140 | { 141 | string fileName = string.Format(PlaylistFileNameFormat, providerId, date); 142 | string filePath = Path.Combine(cacheSettings.CacheDirectoryPath, fileName); 143 | 144 | File.WriteAllText(filePath, content); 145 | } 146 | 147 | public string GetPlaylistFile(string providerId, DateTime date) 148 | { 149 | string fileName = string.Format(PlaylistFileNameFormat, providerId, date); 150 | string filePath = Path.Combine(cacheSettings.CacheDirectoryPath, fileName); 151 | 152 | if (File.Exists(filePath)) 153 | { 154 | return File.ReadAllText(filePath); 155 | } 156 | 157 | return null; 158 | } 159 | 160 | private void PrepareFilesystem() 161 | { 162 | if (!Directory.Exists(cacheSettings.CacheDirectoryPath)) 163 | { 164 | Directory.CreateDirectory(cacheSettings.CacheDirectoryPath); 165 | } 166 | } 167 | 168 | private void LoadStreamStatuses() 169 | { 170 | string filePath = Path.Combine(cacheSettings.CacheDirectoryPath, StreamStatusesFileName); 171 | 172 | if (!File.Exists(filePath)) 173 | { 174 | return; 175 | } 176 | 177 | List lines = File.ReadAllLines(filePath).ToList(); 178 | 179 | foreach (string line in lines) 180 | { 181 | string[] fields = line.Split(CsvFieldSeparator); 182 | 183 | MediaStreamStatus streamStatus = new() 184 | { 185 | Url = fields[0], 186 | LastCheckTime = DateTime.ParseExact(fields[1], TimestampFormat, CultureInfo.InvariantCulture), 187 | State = Enum.Parse(fields[2]) 188 | }; 189 | 190 | if ((streamStatus.State.Equals(StreamState.Alive) && (DateTime.UtcNow - streamStatus.LastCheckTime).TotalSeconds > cacheSettings.StreamAliveStatusCacheTimeout) || 191 | (streamStatus.State.Equals(StreamState.Dead) && (DateTime.UtcNow - streamStatus.LastCheckTime).TotalSeconds > cacheSettings.StreamDeadStatusCacheTimeout) || 192 | (streamStatus.State.Equals(StreamState.Unauthorised) && (DateTime.UtcNow - streamStatus.LastCheckTime).TotalSeconds > cacheSettings.StreamUnauthorisedStatusCacheTimeout) || 193 | (streamStatus.State.Equals(StreamState.NotFound) && (DateTime.UtcNow - streamStatus.LastCheckTime).TotalSeconds > cacheSettings.StreamNotFoundStatusCacheTimeout)) 194 | { 195 | continue; 196 | } 197 | 198 | streamStatuses.TryAdd(streamStatus.Url, streamStatus); 199 | } 200 | } 201 | 202 | private void SaveStreamStatuses() 203 | { 204 | string filePath = Path.Combine(cacheSettings.CacheDirectoryPath, StreamStatusesFileName); 205 | 206 | List lines = []; 207 | 208 | foreach (MediaStreamStatus streamStatus in streamStatuses.Values) 209 | { 210 | string timestamp = streamStatus.LastCheckTime.ToString( 211 | TimestampFormat, 212 | CultureInfo.InvariantCulture); 213 | 214 | string url = streamStatus.Url; 215 | 216 | if (url.Contains(',')) 217 | { 218 | url = url.Split(',')[0]; 219 | } 220 | 221 | lines.Add($"{url}{CsvFieldSeparator}{timestamp}{CsvFieldSeparator}{streamStatus.State}"); 222 | } 223 | 224 | File.WriteAllLines(filePath, lines); 225 | } 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator/Service/PlaylistAggregator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using NuciDAL.Repositories; 7 | using NuciLog.Core; 8 | 9 | using IptvPlaylistAggregator.Configuration; 10 | using IptvPlaylistAggregator.DataAccess.DataObjects; 11 | using IptvPlaylistAggregator.Logging; 12 | using IptvPlaylistAggregator.Service.Mapping; 13 | using IptvPlaylistAggregator.Service.Models; 14 | 15 | namespace IptvPlaylistAggregator.Service 16 | { 17 | public sealed class PlaylistAggregator( 18 | IPlaylistFetcher playlistFetcher, 19 | IPlaylistFileBuilder playlistFileBuilder, 20 | IChannelMatcher channelMatcher, 21 | IMediaSourceChecker mediaSourceChecker, 22 | IFileRepository channelRepository, 23 | IFileRepository groupRepository, 24 | IFileRepository playlistProviderRepository, 25 | ApplicationSettings settings, 26 | ILogger logger) : IPlaylistAggregator 27 | { 28 | private IEnumerable channelDefinitions; 29 | private IEnumerable playlistProviders; 30 | private IDictionary groups; 31 | 32 | public string GatherPlaylist() 33 | { 34 | groups = groupRepository 35 | .GetAll() 36 | .ToServiceModels() 37 | .ToDictionary(x => x.Id, x => x); 38 | 39 | channelDefinitions = channelRepository 40 | .GetAll() 41 | .OrderBy(x => groups[x.GroupId].Priority) 42 | .ThenBy(x => x.Name) 43 | .ToServiceModels(); 44 | 45 | playlistProviders = playlistProviderRepository 46 | .GetAll() 47 | .Where(x => x.IsEnabled) 48 | .ToServiceModels(); 49 | 50 | IList providerChannels = playlistFetcher 51 | .FetchProviderPlaylists(playlistProviders) 52 | .SelectMany(x => x.Channels) 53 | .ToList(); 54 | 55 | Playlist playlist = new(); 56 | 57 | IEnumerable channels = GetChannels(providerChannels); 58 | 59 | foreach (Channel channel in channels) 60 | { 61 | playlist.Channels.Add(channel); 62 | } 63 | 64 | return playlistFileBuilder.BuildFile(playlist); 65 | } 66 | 67 | private IEnumerable GetChannels(IList providerChannels) 68 | { 69 | IEnumerable filteredProviderChannels = GetProvicerChannels(providerChannels); 70 | 71 | logger.Info(MyOperation.ChannelMatching, OperationStatus.Started); 72 | 73 | IDictionary enabledChannels = GetEnabledChannels(filteredProviderChannels).ToDictionary(x => x.Id, x => x); 74 | IEnumerable unmatchedChannels = GetUnmatchedChannels(filteredProviderChannels); 75 | 76 | List channels = []; 77 | 78 | foreach (ChannelDefinition channelDef in channelDefinitions) 79 | { 80 | if (!enabledChannels.ContainsKey(channelDef.Id)) 81 | { 82 | continue; 83 | } 84 | 85 | Channel channel = enabledChannels[channelDef.Id]; 86 | channel.Number = channels.Count + 1; 87 | 88 | channels.Add(channel); 89 | } 90 | 91 | foreach (Channel channel in unmatchedChannels) 92 | { 93 | channel.Number = channels.Count + 1; 94 | channels.Add(channel); 95 | } 96 | 97 | logger.Debug( 98 | MyOperation.ChannelMatching, 99 | OperationStatus.Success, 100 | new LogInfo(MyLogInfoKey.ChannelsCount, channels.Count.ToString())); 101 | 102 | return channels; 103 | } 104 | 105 | private IEnumerable GetEnabledChannels(IEnumerable filteredProviderChannels) 106 | { 107 | ConcurrentBag channels = []; 108 | IEnumerable enabledChannelDefinitions = channelDefinitions 109 | .Where(x => x.IsEnabled && groups[x.GroupId].IsEnabled); 110 | 111 | Parallel.ForEach(enabledChannelDefinitions, channelDef => 112 | { 113 | logger.Debug( 114 | MyOperation.ChannelMatching, 115 | OperationStatus.Started, 116 | new LogInfo(MyLogInfoKey.Channel, channelDef.Name.Value)); 117 | 118 | List matchedChannels = filteredProviderChannels 119 | .Where(x => channelMatcher.DoesMatch(channelDef.Name, x.Name, x.Country)) 120 | .ToList(); 121 | 122 | if (!matchedChannels.Any()) 123 | { 124 | return; 125 | } 126 | 127 | logger.Debug( 128 | MyOperation.ChannelMatching, 129 | OperationStatus.InProgress, 130 | new LogInfo(MyLogInfoKey.Channel, channelDef.Name.Value), 131 | new LogInfo(MyLogInfoKey.ChannelsCount, matchedChannels.Count)); 132 | 133 | Channel matchedChannel = matchedChannels.FirstOrDefault(x => mediaSourceChecker.IsSourcePlayableAsync(x.Url).Result); 134 | 135 | if (matchedChannel is null) 136 | { 137 | logger.Debug( 138 | MyOperation.ChannelMatching, 139 | OperationStatus.Failure, 140 | new LogInfo(MyLogInfoKey.Channel, channelDef.Name.Value)); 141 | 142 | return; 143 | } 144 | 145 | Channel channel = new() 146 | { 147 | Id = channelDef.Id, 148 | Name = channelDef.Name.Value, 149 | Country = channelDef.Country, 150 | Group = groups[channelDef.GroupId].Name, 151 | LogoUrl = channelDef.LogoUrl, 152 | PlaylistId = matchedChannel.PlaylistId, 153 | PlaylistChannelName = matchedChannel.PlaylistChannelName, 154 | Url = matchedChannel.Url 155 | }; 156 | 157 | channels.Add(channel); 158 | 159 | logger.Debug( 160 | MyOperation.ChannelMatching, 161 | OperationStatus.Success, 162 | new LogInfo(MyLogInfoKey.Channel, channelDef.Name.Value)); 163 | }); 164 | 165 | return channels; 166 | } 167 | 168 | private IEnumerable GetUnmatchedChannels(IEnumerable filteredProviderChannels) 169 | { 170 | ConcurrentBag channels = []; 171 | 172 | if (!settings.CanIncludeUnmatchedChannels) 173 | { 174 | return channels; 175 | } 176 | 177 | logger.Info(MyOperation.ChannelMatching, OperationStatus.InProgress, $"Getting unmatched channels"); 178 | 179 | IEnumerable unmatchedChannels = filteredProviderChannels 180 | .Where(x => channelDefinitions.All(y => !channelMatcher.DoesMatch(y.Name, x.Name, x.Country))) 181 | .GroupBy(x => x.Name) 182 | .Select(g => g.First()) 183 | .OrderBy(x => x.Name); 184 | 185 | Parallel.ForEach(unmatchedChannels, unmatchedChannel => 186 | { 187 | if (!mediaSourceChecker.IsSourcePlayableAsync(unmatchedChannel.Url).Result) 188 | { 189 | return; 190 | } 191 | 192 | logger.Warn(MyOperation.ChannelMatching, OperationStatus.Failure, new LogInfo(MyLogInfoKey.Channel, unmatchedChannel.Name)); 193 | 194 | channels.Add(unmatchedChannel); 195 | }); 196 | 197 | return channels; 198 | } 199 | 200 | private IEnumerable GetProvicerChannels( 201 | IList channels) 202 | { 203 | logger.Info( 204 | MyOperation.ProviderChannelsFiltering, 205 | OperationStatus.Started, 206 | new LogInfo(MyLogInfoKey.ChannelsCount, channels.Count)); 207 | 208 | List tasks = []; 209 | IEnumerable filteredChannels = channels 210 | .Where(x => !string.IsNullOrWhiteSpace(x.Url)) 211 | .GroupBy(x => x.Url) 212 | .Select(g => g.First()) 213 | .OrderBy(x => channels.IndexOf(x)) 214 | .ToList(); 215 | 216 | logger.Info( 217 | MyOperation.ProviderChannelsFiltering, 218 | OperationStatus.Success); 219 | 220 | return filteredChannels; 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | [Aa][Rr][Mm]64[Ee][Cc]/ 30 | bld/ 31 | [Bb]in/ 32 | [Oo]bj/ 33 | [Oo]ut/ 34 | [Ll]og/ 35 | [Ll]ogs/ 36 | 37 | # Visual Studio 2015/2017 cache/options directory 38 | .vs/ 39 | # Uncomment if you have tasks that create the project's static files in wwwroot 40 | #wwwroot/ 41 | 42 | # Visual Studio 2017 auto generated files 43 | Generated\ Files/ 44 | 45 | # MSTest test Results 46 | [Tt]est[Rr]esult*/ 47 | [Bb]uild[Ll]og.* 48 | 49 | # NUnit 50 | *.VisualState.xml 51 | TestResult.xml 52 | nunit-*.xml 53 | 54 | # Build Results of an ATL Project 55 | [Dd]ebugPS/ 56 | [Rr]eleasePS/ 57 | dlldata.c 58 | 59 | # Benchmark Results 60 | BenchmarkDotNet.Artifacts/ 61 | 62 | # .NET Core 63 | project.lock.json 64 | project.fragment.lock.json 65 | artifacts/ 66 | 67 | # ASP.NET Scaffolding 68 | ScaffoldingReadMe.txt 69 | 70 | # StyleCop 71 | StyleCopReport.xml 72 | 73 | # Files built by Visual Studio 74 | *_i.c 75 | *_p.c 76 | *_h.h 77 | *.ilk 78 | *.meta 79 | *.obj 80 | *.idb 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | # but not Directory.Build.rsp, as it configures directory-level build defaults 89 | !Directory.Build.rsp 90 | *.sbr 91 | *.tlb 92 | *.tli 93 | *.tlh 94 | *.tmp 95 | *.tmp_proj 96 | *_wpftmp.csproj 97 | *.log 98 | *.tlog 99 | *.vspscc 100 | *.vssscc 101 | .builds 102 | *.pidb 103 | *.svclog 104 | *.scc 105 | 106 | # Chutzpah Test files 107 | _Chutzpah* 108 | 109 | # Visual C++ cache files 110 | ipch/ 111 | *.aps 112 | *.ncb 113 | *.opendb 114 | *.opensdf 115 | *.sdf 116 | *.cachefile 117 | *.VC.db 118 | *.VC.VC.opendb 119 | 120 | # Visual Studio profiler 121 | *.psess 122 | *.vsp 123 | *.vspx 124 | *.sap 125 | 126 | # Visual Studio Trace Files 127 | *.e2e 128 | 129 | # TFS 2012 Local Workspace 130 | $tf/ 131 | 132 | # Guidance Automation Toolkit 133 | *.gpState 134 | 135 | # ReSharper is a .NET coding add-in 136 | _ReSharper*/ 137 | *.[Rr]e[Ss]harper 138 | *.DotSettings.user 139 | 140 | # TeamCity is a build add-in 141 | _TeamCity* 142 | 143 | # DotCover is a Code Coverage Tool 144 | *.dotCover 145 | 146 | # AxoCover is a Code Coverage Tool 147 | .axoCover/* 148 | !.axoCover/settings.json 149 | 150 | # Coverlet is a free, cross platform Code Coverage Tool 151 | coverage*.json 152 | coverage*.xml 153 | coverage*.info 154 | 155 | # Visual Studio code coverage results 156 | *.coverage 157 | *.coveragexml 158 | 159 | # NCrunch 160 | _NCrunch_* 161 | .NCrunch_* 162 | .*crunch*.local.xml 163 | nCrunchTemp_* 164 | 165 | # MightyMoose 166 | *.mm.* 167 | AutoTest.Net/ 168 | 169 | # Web workbench (sass) 170 | .sass-cache/ 171 | 172 | # Installshield output folder 173 | [Ee]xpress/ 174 | 175 | # DocProject is a documentation generator add-in 176 | DocProject/buildhelp/ 177 | DocProject/Help/*.HxT 178 | DocProject/Help/*.HxC 179 | DocProject/Help/*.hhc 180 | DocProject/Help/*.hhk 181 | DocProject/Help/*.hhp 182 | DocProject/Help/Html2 183 | DocProject/Help/html 184 | 185 | # Click-Once directory 186 | publish/ 187 | 188 | # Publish Web Output 189 | *.[Pp]ublish.xml 190 | *.azurePubxml 191 | # Note: Comment the next line if you want to checkin your web deploy settings, 192 | # but database connection strings (with potential passwords) will be unencrypted 193 | *.pubxml 194 | *.publishproj 195 | 196 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 197 | # checkin your Azure Web App publish settings, but sensitive information contained 198 | # in these scripts will be unencrypted 199 | PublishScripts/ 200 | 201 | # NuGet Packages 202 | *.nupkg 203 | # NuGet Symbol Packages 204 | *.snupkg 205 | # The packages folder can be ignored because of Package Restore 206 | **/[Pp]ackages/* 207 | # except build/, which is used as an MSBuild target. 208 | !**/[Pp]ackages/build/ 209 | # Uncomment if necessary however generally it will be regenerated when needed 210 | #!**/[Pp]ackages/repositories.config 211 | # NuGet v3's project.json files produces more ignorable files 212 | *.nuget.props 213 | *.nuget.targets 214 | 215 | # Microsoft Azure Build Output 216 | csx/ 217 | *.build.csdef 218 | 219 | # Microsoft Azure Emulator 220 | ecf/ 221 | rcf/ 222 | 223 | # Windows Store app package directories and files 224 | AppPackages/ 225 | BundleArtifacts/ 226 | Package.StoreAssociation.xml 227 | _pkginfo.txt 228 | *.appx 229 | *.appxbundle 230 | *.appxupload 231 | 232 | # Visual Studio cache files 233 | # files ending in .cache can be ignored 234 | *.[Cc]ache 235 | # but keep track of directories ending in .cache 236 | !?*.[Cc]ache/ 237 | 238 | # Others 239 | ClientBin/ 240 | ~$* 241 | *~ 242 | *.dbmdl 243 | *.dbproj.schemaview 244 | *.jfm 245 | *.pfx 246 | *.publishsettings 247 | orleans.codegen.cs 248 | 249 | # Including strong name files can present a security risk 250 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 251 | #*.snk 252 | 253 | # Since there are multiple workflows, uncomment next line to ignore bower_components 254 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 255 | #bower_components/ 256 | 257 | # RIA/Silverlight projects 258 | Generated_Code/ 259 | 260 | # Backup & report files from converting an old project file 261 | # to a newer Visual Studio version. Backup files are not needed, 262 | # because we have git ;-) 263 | _UpgradeReport_Files/ 264 | Backup*/ 265 | UpgradeLog*.XML 266 | UpgradeLog*.htm 267 | ServiceFabricBackup/ 268 | *.rptproj.bak 269 | 270 | # SQL Server files 271 | *.mdf 272 | *.ldf 273 | *.ndf 274 | 275 | # Business Intelligence projects 276 | *.rdl.data 277 | *.bim.layout 278 | *.bim_*.settings 279 | *.rptproj.rsuser 280 | *- [Bb]ackup.rdl 281 | *- [Bb]ackup ([0-9]).rdl 282 | *- [Bb]ackup ([0-9][0-9]).rdl 283 | 284 | # Microsoft Fakes 285 | FakesAssemblies/ 286 | 287 | # GhostDoc plugin setting file 288 | *.GhostDoc.xml 289 | 290 | # Node.js Tools for Visual Studio 291 | .ntvs_analysis.dat 292 | node_modules/ 293 | 294 | # Visual Studio 6 build log 295 | *.plg 296 | 297 | # Visual Studio 6 workspace options file 298 | *.opt 299 | 300 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 301 | *.vbw 302 | 303 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 304 | *.vbp 305 | 306 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 307 | *.dsw 308 | *.dsp 309 | 310 | # Visual Studio 6 technical files 311 | *.ncb 312 | *.aps 313 | 314 | # Visual Studio LightSwitch build output 315 | **/*.HTMLClient/GeneratedArtifacts 316 | **/*.DesktopClient/GeneratedArtifacts 317 | **/*.DesktopClient/ModelManifest.xml 318 | **/*.Server/GeneratedArtifacts 319 | **/*.Server/ModelManifest.xml 320 | _Pvt_Extensions 321 | 322 | # Paket dependency manager 323 | .paket/paket.exe 324 | paket-files/ 325 | 326 | # FAKE - F# Make 327 | .fake/ 328 | 329 | # CodeRush personal settings 330 | .cr/personal 331 | 332 | # Python Tools for Visual Studio (PTVS) 333 | __pycache__/ 334 | *.pyc 335 | 336 | # Cake - Uncomment if you are using it 337 | # tools/** 338 | # !tools/packages.config 339 | 340 | # Tabs Studio 341 | *.tss 342 | 343 | # Telerik's JustMock configuration file 344 | *.jmconfig 345 | 346 | # BizTalk build output 347 | *.btp.cs 348 | *.btm.cs 349 | *.odx.cs 350 | *.xsd.cs 351 | 352 | # OpenCover UI analysis results 353 | OpenCover/ 354 | 355 | # Azure Stream Analytics local run output 356 | ASALocalRun/ 357 | 358 | # MSBuild Binary and Structured Log 359 | *.binlog 360 | 361 | # AWS SAM Build and Temporary Artifacts folder 362 | .aws-sam 363 | 364 | # NVidia Nsight GPU debugger configuration file 365 | *.nvuser 366 | 367 | # MFractors (Xamarin productivity tool) working folder 368 | .mfractor/ 369 | 370 | # Local History for Visual Studio 371 | .localhistory/ 372 | 373 | # Visual Studio History (VSHistory) files 374 | .vshistory/ 375 | 376 | # BeatPulse healthcheck temp database 377 | healthchecksdb 378 | 379 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 380 | MigrationBackup/ 381 | 382 | # Ionide (cross platform F# VS Code tools) working folder 383 | .ionide/ 384 | 385 | # Fody - auto-generated XML schema 386 | FodyWeavers.xsd 387 | 388 | # VS Code files for those working on multiple tools 389 | .vscode/* 390 | !.vscode/settings.json 391 | !.vscode/tasks.json 392 | !.vscode/launch.json 393 | !.vscode/extensions.json 394 | *.code-workspace 395 | 396 | # Local History for Visual Studio Code 397 | .history/ 398 | 399 | # Windows Installer files from build outputs 400 | *.cab 401 | *.msi 402 | *.msix 403 | *.msm 404 | *.msp 405 | -------------------------------------------------------------------------------- /IptvPlaylistAggregator.UnitTests/Service/ChannelMatcherTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | using Moq; 4 | 5 | using IptvPlaylistAggregator.Service; 6 | using IptvPlaylistAggregator.Service.Models; 7 | 8 | namespace IptvPlaylistAggregator.UnitTests.Service 9 | { 10 | public sealed class ChannelMatcherTests 11 | { 12 | private Mock cacheMock; 13 | 14 | private IChannelMatcher channelMatcher; 15 | 16 | [SetUp] 17 | public void SetUp() 18 | { 19 | cacheMock = new Mock(); 20 | 21 | channelMatcher = new ChannelMatcher(cacheMock.Object); 22 | } 23 | 24 | [TestCase("Diaspora Media", "MD", "MD: Diaspora Media", "MD: Diaspora Media", "MD")] 25 | [TestCase("FOREIGN_CHANNEL", null, "M D Dunia Sinema", "Dunia Sinema (1080p)", "MD")] 26 | [TestCase("INVALID_CHANNEL", null, "iptvcat.com", "iptvcat.com", "RO")] 27 | [TestCase("INVALID_CHANNEL", null, "iptvcat.com", "iptvcat.com", null)] 28 | [TestCase("Moldova TV", "RO", "RO: M D Moldova TV", "Moldova TV (576p) [Not 24/7]", "MD")] 29 | [TestCase("Privesc EU", "MD", "Privesc.EU TV", "Privesc.Eu TV (2160p)", "MD")] 30 | [TestCase("Soroca TV", "MD", "MD: Sor TV", "Sor TV (720p)", "MD")] 31 | [TestCase("Valea Prahovei TV", "RO", "VP HD", "VP HD", "RO")] 32 | [TestCase("Valea Prahovei TV", "RO", "VP HD", "VP HD", null)] 33 | [TestCase("Vocea Basarabiei", "MD", "MD: Vocea Basarabiei TV", "Vocea Basarabiei TV (720p) [Not 24/7]", "MD")] 34 | [Test] 35 | public void ChannelNamesDoMatch_WithAliasWithCountry( 36 | string definedName, 37 | string definedCountry, 38 | string alias, 39 | string providerName, 40 | string providerCountry) 41 | { 42 | ChannelName channelName = GetChannelName(definedName, definedCountry, alias); 43 | 44 | Assert.That(channelMatcher.DoesMatch(channelName, providerName, providerCountry)); 45 | } 46 | 47 | [TestCase("TeleM Botoșani", "RO", "TeleM Botosani (540p) [Not 24/7]", "RO")] 48 | [Test] 49 | public void ChannelNamesDoMatch_WithoutAliasWithCountry( 50 | string definedName, 51 | string definedCountry, 52 | string providerName, 53 | string providerCountry) 54 | { 55 | ChannelName channelName = GetChannelName(definedName, definedCountry, null); 56 | 57 | Assert.That(channelMatcher.DoesMatch(channelName, providerName, providerCountry)); 58 | } 59 | 60 | [TestCase("Agro TV", "RO: Agro", "Agro RO")] 61 | [TestCase("Agro TV", "RO: Agro", "Agro RO")] 62 | [TestCase("Antena 1", "RO: Antenna", "RO: Antenna HD")] 63 | [TestCase("Ardeal TV", "RO: Ardeal TV", "|RO| Ardeal TV")] 64 | [TestCase("Bollywood Classic", "RO: Bollywood Classic TV", "Bollywood Classic TV VIP RO")] 65 | [TestCase("Cartoon Network", "RO: Cartoon Network", "VIP|RO|: Cartoon Network")] 66 | [TestCase("CineMAX 1", "RO: CineMAX", "CineMAX RO")] 67 | [TestCase("Digi Sport 2", "RO: Digi Sport 2", "RO: DIGI Sport 2")] 68 | [TestCase("Digi Sport 2", "RO: Digi Sport 2", "Romanian:DIGI Sport 2")] 69 | [TestCase("Digi World", "RO: Digi World FHD", "RUMANIA: DigiWorld FHD (Opt-1)")] 70 | [TestCase("Duna", "RO: Duna TV", "RO | Duna Tv")] 71 | [TestCase("Golf Channel", "FR: Golf Channel", "|FR| GOLF CHANNEL FHD")] 72 | [TestCase("H!T Music Channel", "RO: Hit Music Channel", "RO: Hit Music Channel")] 73 | [TestCase("H!T Music Channel", "RO: Hit Music Channel", "RO(L): HIT MUSIC CHANNEL SD")] 74 | [TestCase("H!T Music Channel", "RO: Hit", "RO | HIT")] 75 | [TestCase("HBO 1", "RO: HBO", "RO:HBO HD")] 76 | [TestCase("HD Net Van Damme", "HD NET Jean Claude Van Damme", "HD NET Jean Claude van Damme")] 77 | [TestCase("Hora TV", "RO: Hora TV", "RO(L): HORA TV SD")] 78 | [TestCase("Jurnal TV", "MD: Jurnal TV", "Jurnal TV Moldavia")] 79 | [TestCase("MegaMax", "RO: MegaMax", "RO: MegaMax-HD")] 80 | [TestCase("NCN TV", "RO: NCN", "RO: NCN HD")] 81 | [TestCase("Pro TV News", "RO: Pro News", "Pro News")] 82 | [TestCase("Publika TV", "MD: Publika", "PUBLIKA_TV_HD")] 83 | [TestCase("Realitatea Plus", "RO: Realitatea TV Plus", "RO(L): REALITATEA TV PLUS SD")] 84 | [TestCase("România TV", "România TV", "RO\" Romania TV")] 85 | [TestCase("Somax", "RO: Somax TV", "Somax TV")] 86 | [TestCase("Sundance", "RO: Sundance TV", "RO: Sundance TV FHD (MultiSub)")] 87 | [TestCase("Sundance", "RO: Sundance TV", "RO: Sundance TV FHD [Multi-Sub]")] 88 | [TestCase("Travel Channel", "RO: Travel", "RO | Travel")] 89 | [TestCase("Travel Mix", "RO: Travel Mix TV", "Travel Mix TV RO")] 90 | [TestCase("TV Paprika", "RO: Paprika TV", "RO TV Paprika")] 91 | [TestCase("TV8", "MD: TV8", "TV 8 Moldova HD")] 92 | [TestCase("TVC21", "MD: TVC21", "TVC 21 Moldova")] 93 | [TestCase("TVR Moldova", "RO: TVR Moldova", "RO: TVR Moldova")] 94 | [TestCase("TVR Târgu Mureș", "RO: TVR T?rgu-Mure?", "TVR: Targu Mureș")] 95 | [TestCase("VSV De Niro", "VSV Robert de Niro", "VSV Robert de Niro HD")] 96 | [Test] 97 | public void ChannelNamesDoMatch_WithAliasWithoutCountry( 98 | string definedName, 99 | string alias, 100 | string providerName) 101 | { 102 | ChannelName channelName = GetChannelName(definedName, alias); 103 | 104 | Assert.That(channelMatcher.DoesMatch(channelName, providerName, country2: null)); 105 | } 106 | 107 | [TestCase("AMC", "RO: AMC Romania")] 108 | [TestCase("Antena 3", "Antena 3 Ultra_HD")] 109 | [TestCase("Elita TV", "Elita TV")] 110 | [TestCase("Exploris", "Exploris (576p) [Not 24/7]")] 111 | [TestCase("HBO 3", "HBO 3 F_HD")] 112 | [TestCase("MTV Europe", "RO: MTV Europe")] 113 | [TestCase("Pro TV", "PRO TV ULTRA_HD")] 114 | [TestCase("Realitatea Plus", "Realitatea Plus")] 115 | [TestCase("TVR 1", "TVR1 [B] RO")] 116 | [TestCase("TVR", "RO: TVR HD (1080P)")] 117 | [TestCase("U TV", "UTV")] 118 | [TestCase("Vivid TV", "Vivid TV HD(18+)")] 119 | [Test] 120 | public void ChannelNamesDoMatch_WithoutAliasWithoutCountry( 121 | string definedName, 122 | string providerName) 123 | { 124 | ChannelName channelName = GetChannelName(definedName, alias: null); 125 | 126 | Assert.That(channelMatcher.DoesMatch(channelName, providerName, country2: null)); 127 | } 128 | 129 | [TestCase("Cromtel", "Cmrotel", "Cmtel")] 130 | [TestCase("Telekom Sport 2", "RO: Telekom Sport 2", "RO: Digi Sport 2")] 131 | [Test] 132 | public void ChannelNamesDoNotMatch_WithAliasWithoutCountry( 133 | string definedName, 134 | string alias, 135 | string providerName) 136 | { 137 | ChannelName channelName = GetChannelName(definedName, alias); 138 | 139 | Assert.That(!channelMatcher.DoesMatch(channelName, providerName, country2: null)); 140 | } 141 | 142 | [TestCase("Pro TV", "MD: Pro TV")] 143 | [TestCase("Pro TV", "MD: ProTV Chisinau")] 144 | [Test] 145 | public void ChannelNamesDoNotMatch_WithoutAliasWithoutCountry( 146 | string definedName, 147 | string providerName) 148 | { 149 | // Arrange 150 | ChannelName channelName = GetChannelName(definedName, alias: null); 151 | 152 | // Act 153 | bool isMatch = channelMatcher.DoesMatch(channelName, providerName, country2: null); 154 | 155 | // Assert 156 | Assert.That(isMatch, Is.False); 157 | } 158 | 159 | [TestCase(" MD| Publika", "MD", "MDPUBLIKA")] 160 | [TestCase("|AR| AD SPORT 4 HEVC", "AR", "ARADSPORT4")] 161 | [TestCase("|FR| GOLF CHANNELS HD", "FR", "FRGOLFCHANNELS")] 162 | [TestCase("|RO| Ardeal TV", "RO", "ARDEALTV")] 163 | [TestCase("|ROM|: Cromtel", "RO", "CROMTEL")] 164 | [TestCase("|UK| CHELSEA TV (Live On Matches) HD", "UK", "UKCHELSEATV")] 165 | [TestCase("Alfa & Omega RO", "RO", "ALFAOMEGA")] 166 | [TestCase("Bollywood VIP RO", "RO", "BOLLYWOOD")] 167 | [TestCase("Canal Regional (Moldova)", "MD", "MDCANALREGIONAL")] 168 | [TestCase("Crime & Investigation RO", "RO", "CRIMEINVESTIGATION")] 169 | [TestCase("iConcert FHD RO", "RO", "ICONCERT")] 170 | [TestCase("MD: MD: Diaspora Media", "MD", "MDDIASPORAMEDIA")] 171 | [TestCase("MD: Moldova TV", "RO", "MOLDOVATV")] 172 | [TestCase("Moldova TV (576p) [Not 24/7]", "MD", "MDMOLDOVATV")] 173 | [TestCase("Moldova TV", "RO", "MOLDOVATV")] 174 | [TestCase("RO | Travel", "RO", "TRAVEL")] 175 | [TestCase("RO: M D Moldova TV", "RO", "MDMOLDOVATV")] 176 | [TestCase("RO: Travel", "RO", "TRAVEL")] 177 | [TestCase("RO(L): TELEKOM SPORT 1 FHD", "RO", "TELEKOMSPORT1")] 178 | [TestCase("Telekom Sport 5 FHD [Match Time] RO", "RO", "TELEKOMSPORT5")] 179 | [TestCase("Travel Mix", "RO", "TRAVELMIX")] 180 | [TestCase("TV Paprika", "RO", "TVPAPRIKA")] 181 | [TestCase("TV8", "MD", "MDTV8")] 182 | [TestCase("TVC21", "MD", "MDTVC21")] 183 | [TestCase("TVR Moldova", "MD", "MDTVR")] 184 | [TestCase("TVR Târgu Mureș", "RO", "TVRTARGUMURES")] 185 | [TestCase("TVR1 [B] RO", "RO", "TVR1")] 186 | [TestCase("Vocea Basarabiei TV (720p) [Not 24/7]", "MD", "MDVOCEABASARABIEITV")] 187 | [TestCase("VP HD", "RO", "VP")] 188 | [TestCase("VSV De Niro", "RO", "VSVDENIRO")] 189 | [Test] 190 | public void NormaliseName_WithCountry_ReturnsExpectedValue(string name, string country, string expectedNormalisedName) 191 | { 192 | string actualNormalisedName = channelMatcher.NormaliseName(name, country); 193 | 194 | Assert.That(actualNormalisedName, Is.EqualTo(expectedNormalisedName)); 195 | } 196 | 197 | [TestCase(" MD| Publika", "MDPUBLIKA")] 198 | [TestCase("|AR| AD SPORT 4 HEVC", "ARADSPORT4")] 199 | [TestCase("|FR| GOLF CHANNELS HD", "FRGOLFCHANNELS")] 200 | [TestCase("|RO| Ardeal TV", "ARDEALTV")] 201 | [TestCase("|ROM|: Cromtel", "CROMTEL")] 202 | [TestCase("|UK| CHELSEA TV (Live On Matches) HD", "UKCHELSEATV")] 203 | [TestCase("Al Jazeera Documentary (270p) [Geo-blocked]", "ALJAZEERADOCUMENTARY")] 204 | [TestCase("Canal Regional (Moldova)", "MDCANALREGIONAL")] 205 | [TestCase("Cartoon Network FullHD", "CARTOONNETWORK")] 206 | [TestCase("Digi 4K", "DIGI4K")] 207 | [TestCase("DIGI SPORT 4 (RO)", "DIGISPORT4")] 208 | [TestCase("Jurnal TV Moldova", "MDJURNALTV")] 209 | [TestCase("MD: Canal Regional (Moldova)", "MDCANALREGIONAL")] 210 | [TestCase("MD: MD: [MD] Publika", "MDPUBLIKA")] 211 | [TestCase("MD: MD: Moldova 1", "MDMOLDOVA1")] 212 | [TestCase("MD: MD| Pro TV Chișinău.", "MDPROTVCHISINAU")] 213 | [TestCase("MD: ProTV Chisinau", "MDPROTVCHISINAU")] 214 | [TestCase("MINIMAX ROMANIA HD", "MINIMAXROMANIA")] 215 | [TestCase("Pro Cinema Full-HD", "PROCINEMA")] 216 | [TestCase("Pro TV [B] RO", "PROTV")] 217 | [TestCase("PUBLIKA_TV_HD", "PUBLIKATV")] 218 | [TestCase("RO \" DIGI SPORT 1 HD RO", "DIGISPORT1")] 219 | [TestCase("RO | Travel", "TRAVEL")] 220 | [TestCase("RO-Animal Planet HD", "ANIMALPLANET")] 221 | [TestCase("RO: 1HD", "1HD")] 222 | [TestCase("RO: Animal World [768p]", "ANIMALWORLD")] 223 | [TestCase("RO: Bit TV (ROM)", "BITTV")] 224 | [TestCase("RO: Digi24 (România)", "DIGI24")] 225 | [TestCase("RO: HBO 3 RO", "HBO3")] 226 | [TestCase("RO: HBO HD RO", "HBO")] 227 | [TestCase("RO: MiniMax-HD", "MINIMAX")] 228 | [TestCase("RO: Nașul TV (New!)", "NASULTV")] 229 | [TestCase("RO: Nickelodeon (RO)", "NICKELODEON")] 230 | [TestCase("Ro: Pro TV backup", "PROTV")] 231 | [TestCase("Ro: Romania TV backup", "ROMANIATV")] 232 | [TestCase("RO: Tele Moldova", "TELEMOLDOVA")] 233 | [TestCase("RO: Travel", "TRAVEL")] 234 | [TestCase("RO: TVR Moldova", "TVRMOLDOVA")] 235 | [TestCase("RO: U TV [b]", "UTV")] 236 | [TestCase("RO: U TV [B]", "UTV")] 237 | [TestCase("RO: U TV S1-1", "UTV")] 238 | [TestCase("RO:HBO HD", "HBO")] 239 | [TestCase("RO.| DIGI 24", "DIGI24")] 240 | [TestCase("RO(L): E! ENTERTAINMENT FHD", "EENTERTAINMENT")] 241 | [TestCase("RO(L): HIT MUSIC CHANNEL SD", "HITMUSICCHANNEL")] 242 | [TestCase("RO(L): IASI TV SD", "IASITV")] 243 | [TestCase("RO(L): KronehitTV FHD", "KRONEHITTV")] 244 | [TestCase("RO(L): REALITATEA TV PLUS SD", "REALITATEATVPLUS")] 245 | [TestCase("RO(L): VP SD", "VP")] 246 | [TestCase("RO\" Romania TV", "ROMANIATV")] 247 | [TestCase("RO| Antena 3 4K+", "ANTENA3")] 248 | [TestCase("RO| CINEMA RO.", "CINEMARO")] 249 | [TestCase("RO| Digi Life 4K+", "DIGILIFE")] 250 | [TestCase("RO| NGRO", "NGRO")] 251 | [TestCase("RO| TARAF:HD", "TARAF")] 252 | [TestCase("RO|DISOVERY_SCIENCE_HD", "DISOVERYSCIENCE")] 253 | [TestCase("RTR Moldova HD", "MDRTR")] 254 | [TestCase("RUMANIA: DigiWorld FHD (Opt-1)", "DIGIWORLD")] 255 | [TestCase("TV 8 HD (Auto)", "TV8")] 256 | [TestCase("TV 8 Moldova HD", "MDTV8")] 257 | [TestCase("TV Centrală Moldova", "MDTVCENTRALA")] 258 | [TestCase("TVR 1 (Backup) RO", "TVR1")] 259 | [TestCase("TVR Info (1080p) [Geo-blocked]", "TVRINFO")] 260 | [TestCase("TVR Moldova (720p) [Geo-blocked] [Not 24/7]", "TVRMOLDOVA")] 261 | [TestCase("TVR2 [B] RO", "TVR2")] 262 | [TestCase("U TV", "UTV")] 263 | [TestCase("US: NASA TV US", "USNASATV")] 264 | [TestCase("Viasat Explore Full_HD", "VIASATEXPLORE")] 265 | [TestCase("VIP|RO|: Discovery Channel FHD", "DISCOVERYCHANNEL")] 266 | [TestCase("Vocea Basarabiei TV (720p) [Not 24/7]", "VOCEABASARABIEITV")] 267 | [TestCase("VSV Robert de Niro HD", "VSVROBERTDENIRO")] 268 | [TestCase("VSV Robert de Niro", "VSVROBERTDENIRO")] 269 | [TestCase("ZonaM Moldova", "MDZONAM")] 270 | [Test] 271 | public void NormaliseName_WithoutCountry_ReturnsExpectedValue(string inputValue, string expectedValue) 272 | { 273 | string actualValue = channelMatcher.NormaliseName(inputValue, country: null); 274 | 275 | Assert.That(expectedValue, Is.EqualTo(actualValue)); 276 | } 277 | 278 | private ChannelName GetChannelName(string definedName, string alias) 279 | => GetChannelName(definedName, country: null, alias); 280 | 281 | private static ChannelName GetChannelName(string definedName, string country, string alias) 282 | { 283 | if (alias is null) 284 | { 285 | return new ChannelName(definedName); 286 | } 287 | 288 | return new ChannelName(definedName, country, alias); 289 | } 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------