Skip to content

Commit

Permalink
- experimental support for Philips channel list format 125 (with auto…
Browse files Browse the repository at this point in the history
…matic sync to MtkChannelList.xml)

- experimental support for MtkChannelList.xml (which is part of several MediaTek based Google TVs, e.g. Philips formats 120 and 125)
- Philips formats 100-125: improved decoding of non-latin characters (turkish, cyrillic, ...)
  • Loading branch information
PredatH0r committed Oct 1, 2024
1 parent 5597d5b commit 8480fcf
Show file tree
Hide file tree
Showing 33 changed files with 668 additions and 63 deletions.
12 changes: 12 additions & 0 deletions source/ChanSort.Api/Controller/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,17 @@ protected long ParseLong(string input)
return 0;
}
#endregion

#region ParseDecimal()
protected decimal ParseDecimal(string input)
{
if (string.IsNullOrWhiteSpace(input))
return 0;
if (decimal.TryParse(input, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var value))
return value;
return 0;
}
#endregion

}
}
30 changes: 28 additions & 2 deletions source/ChanSort.Api/Utils/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;

namespace ChanSort.Api
{
Expand Down Expand Up @@ -149,11 +150,15 @@ public static string HexEncode(byte[] bytes, bool uppercase = false)
/// <summary>
/// This method tests whether the binary data can be interpreted as valid UTF-8. If not, it might be encoded with a locale specific encoding
/// </summary>
public static bool IsUtf8(byte[] buffer)
public static bool IsUtf8(byte[] buffer, int start=0, int count=-1)
{
if (count < 0)
count = buffer.Length - start;

int followBytes = 0;
foreach (byte b in buffer)
for (int i = start, e=Math.Min(start+count, buffer.Length); i<e; i++)
{
var b = buffer[i];
if (followBytes > 0)
{
if ((b & 0xC0) != 0x80) // follow-up bytes must be 10xx xxxx
Expand Down Expand Up @@ -227,6 +232,12 @@ public static T FirstNotDefault<T>(params T[] values)
}
#endregion

#region TrimGarbage()
/// <summary>
/// Remove a \0 and everything following it from a string
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string TrimGarbage(this string input)
{
if (input == null) return null;
Expand All @@ -235,6 +246,21 @@ public static string TrimGarbage(this string input)
return input.Substring(0, i);
return input;
}
#endregion

#region XmlNode: GetElement(), GetElementString(), GetElementInt()
public static XmlElement GetElement(this XmlNode node, string localName)
{
if (node is not XmlElement element)
return null;
var children = element.GetElementsByTagName(localName, node.NamespaceURI);
return children.Count >= 1 ? children[0] as XmlElement : null;
}

public static string GetElementString(this XmlNode node, string localName) => GetElement(node, localName)?.InnerText;
public static int GetElementInt(this XmlNode node, string localName, int defaultValue = 0) => int.TryParse(GetElementString(node, localName), out var value) ? value : defaultValue;

#endregion

}
}
28 changes: 28 additions & 0 deletions source/ChanSort.Loader.MediaTek/ChanSort.Loader.MediaTek.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\Debug\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<OutputPath>..\Debug\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\Release\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ChanSort.Api\ChanSort.Api.csproj" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions source/ChanSort.Loader.MediaTek/Channel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Xml;
using ChanSort.Api;

namespace ChanSort.Loader.MediaTek
{
internal class Channel : ChannelInfo
{
public XmlElement Xml { get; }

internal Channel(SignalSource source, int index, int oldProgNr, string name, XmlElement element) :base(source, index, oldProgNr, name)
{
this.Xml = element;
}
}
}
22 changes: 22 additions & 0 deletions source/ChanSort.Loader.MediaTek/MediatekPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.IO;
using ChanSort.Api;

namespace ChanSort.Loader.MediaTek;

public class MediatekPlugin : ISerializerPlugin
{
public string DllName { get; set; }
public string PluginName => "MediaTek (MtkChannelList.xml)";
public string FileFilter => "Mtk*.xml";

public SerializerBase CreateSerializer(string inputFile)
{
var dir = Path.GetDirectoryName(inputFile);

// if there is a chanLst.bin file, let the Philips module handle the channel list
//if (File.Exists(Path.Combine(dir, "chanLst.bin")))
// return null;

return new Serializer(inputFile);
}
}
33 changes: 33 additions & 0 deletions source/ChanSort.Loader.MediaTek/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ChanSort.Loader.MediaTek")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChanSort.Loader.MediaTek")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5fc54726-b7ec-4a81-919f-f924110c723e")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 8480fcf

Please sign in to comment.