https://github.com/eddami/xmltvsharp
A high-performance, asynchronous XMLTV parser for TV program data.
https://github.com/eddami/xmltvsharp
epg xmltv xmltv-epg xmltv-format
Last synced: 6 months ago
JSON representation
A high-performance, asynchronous XMLTV parser for TV program data.
- Host: GitHub
- URL: https://github.com/eddami/xmltvsharp
- Owner: eddami
- License: mit
- Created: 2023-10-04T18:10:33.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-24T01:44:44.000Z (over 1 year ago)
- Last Synced: 2025-04-06T05:36:00.343Z (6 months ago)
- Topics: epg, xmltv, xmltv-epg, xmltv-format
- Language: C#
- Homepage:
- Size: 45.9 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/eddami/XmlTvSharp/actions/workflows/build.yml)
[](https://github.com/eddami/XmlTvSharp/actions/workflows/release.yml)
[](https://github.com/eddami/XmlTvSharp/blob/main/LICENSE)
[](https://www.nuget.org/packages/XmlTvSharp)
[](https://www.nuget.org/packages/XmlTvSharp)
[](https://coveralls.io/github/eddami/XmlTvSharp?branch=main)# XmlTvSharp
A high-performance, asynchronous XMLTV parser for TV program data.
## Installation
You can install this library via NuGet Package Manager:
```bash
Install-Package XmlTvSharp
```## Benchmark
We tested the library using an XMLTV file featuring 19,804 channels and 1,979,805 programmes.
```
AMD Ryzen 5 3600, 1 CPU, 12 logical and 6 physical cores
.NET SDK 7.0.109
[Host] : .NET 7.0.9 (7.0.923.32301), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.9 (7.0.923.32301), X64 RyuJIT AVX2| Method | Mean | Error | StdDev |
|------------- |--------:|--------:|--------:|
| ReadAllAsync | 20.65 s | 0.293 s | 0.229 s |
```## Usage
### Reading All XMLTV Elements
```csharp
// Specify the path to the XML file containing TV program information
var xmlFilePath = "path/to/your/xmltv/file.xml";// Cancellation token
var cancellationToken = new CancellationToken();// Customize the parsing behaviour
var settings = new XmlTvReaderSettings();// Read all TV channels and programmes asynchronously
var result = await XmlTvReader.ReadAllAsync(xmlFilePath, settings, cancellationToken);// Access the parsed TV channels and programmes
var channels = result.Channels;
var programmes = result.Programmes;
```### Reading XMLTV Elements Sequentially
```csharp
// Specify the path to the XML file containing TV program information
var xmlFilePath = "path/to/your/xmltv/file.xml";// Cancellation token
var cancellationToken = new CancellationToken();// Customize the parsing behaviour
var settings = new XmlTvReaderSettings();using var reader = new XmlTvReader(xmlFilePath, settings);
IXmlTvElement element;
// Read XMLTV elements sequentially asynchronously
while ((element = await reader.ReadAsync(cancellationToken)) != null)
{
if (element is XmlTvChannel channel)
{
// Process the parsed channel element
}
else if (element is XmlTvProgramme programme)
{
// Process the parsed programme element
}
}
```### XmlTvReaderSettings
XmlTvReaderSettings allows customization of the parsing behavior. Here are the default values:
```csharp
var settings = new XmlTvReaderSettings
{
FilterByChannelId = null,
FilterByProgrammeChannelId = null,
FilterByProgrammeTime = null,
DefaultLanguage = "en",
TimeZone = TimeZoneInfo.Utc,
IgnoreChannels = false,
IgnoreProgrammes = false,
IncludeOuterXml = false
};
```- `FilterByChannelId`: A function to filter all elements by their channel IDs.
- `FilterByProgrammeChannelId`: A function to filter programme elements by their channel IDs.**Note:** When both `FilterByChannelId` and `FilterByProgrammeChannelId` are set, `FilterByProgrammeChannelId` takes
precedence over `FilterByChannelId` for filtering programme elements by their channel IDs.- `FilterByProgrammeTime`: A function to filter programmes by their start and stop times.
- `DefaultLanguage`: Default language to use if language information is not available in the XML data.
- `TimeZone`: Time zone to convert programme start and stop times. Default is UTC.
- `IgnoreChannels`: Set to true to ignore channel elements during parsing.
- `IgnoreProgrammes`: Set to true to ignore programme elements during parsing.
- `IncludeOuterXml`: Set to true to include the outer XML of elements during parsing.**Warning:** Setting `IncludeOuterXml` to `true` will cause the parser to allocate an extra `XmlReader` instance,
potentially impacting performance.**Example Usage:**
```csharp
var settings = new XmlTvReaderSettings
{
FilterByChannelId = channelId => channelId.StartsWith("custom_"),
FilterByProgrammeChannelId = channelId => channelId.StartsWith("custom_programme_"),
FilterByProgrammeTime = (startTime, endTime) => startTime.DayOfWeek == DayOfWeek.Monday && endTime.Hour < 18,
DefaultLanguage = "fr", // Set default language to French
TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"), // Set time zone to EST
IgnoreChannels = false, // Do not ignore channel elements
IgnoreProgrammes = true, // Ignore programme elements during parsing
IncludeOuterXml = true // Include outer XML of elements during parsing
};
```## Contributing
We welcome your contributions to this project. If you find a bug, have a feature request, or want to contribute in any
other way, please open an issue or submit a pull request.## License
This project is licensed under the MIT License - see
the [LICENSE](https://github.com/eddami/XmlTvSharp/blob/main/LICENSE) file for details.