2021-01-09 12:06:32 +01:00
using System ;
using System.IO ;
using System.Text.RegularExpressions ;
using ChanSort.Api ;
namespace ChanSort.Loader.Philips
{
2021-01-23 14:22:18 +01:00
public class PhilipsPlugin : ISerializerPlugin
2021-01-09 12:06:32 +01:00
{
/ *
* Philips has a whole lot of completely incompatible channel list file formats with different folder structures .
* Most formats have a chanLst . bin file , which contains a minor and major version number in the header and CRC16 checksums for various other files .
* ( first word is the minor , second word the major )
*
* version - 1 ( not an official number ) :
* Repair \ mgr_chan_dvbt . db ( binary file , not a SQLite database )
* Repair \ FLASH_ *
* no chanLst . bin
*
* version 0 ( not an official number ) :
* Repair \ CM_ * _LA_CK . BIN ( + a hidden . xml file with the actual channel list )
* e . g . 47 PFL5008K
* no chanLst . bin
*
* version 1.1
* Repair \ ChannelList \ chanLst . bin
* Repair \ ChannelList \ channellib \ CableDigSrvTable
* Repair \ ChannelList \ s2channellib \ service . dat
* e . g . 32 PFL5806K / 02 , 42 PFL7656K / 02
*
* version 1.2
2021-01-17 15:44:45 +01:00
* same as version 1.1 for most parts , but different tuneinfo . dat format
2021-01-09 12:06:32 +01:00
* e . g . 32 PFL5507K / 12 , 42 PFL4317K / 12 , 32 PFL5507K / 12
*
* version 11.1
* PhilipsChannelMaps \ ChannelMap_11 \ ChannelList \ chanLst . bin
* PhilipsChannelMaps \ ChannelMap_11 \ ChannelList \ channelLib \ * Table ( as with 1.1 )
* PhilipsChannelMaps \ ChannelMap_11 \ ChannelList \ s2channellib \ * . dat ( as with 1.1 )
* PhilipsChannelMaps \ ChannelMap_11 \ ChannelList \ s2channellib \ Satellite * Table ( new here )
* e . g . 55 PFL8008S / 12
*
2021-04-11 12:08:47 +02:00
* version 30.1
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ chanLst . bin
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ list . db ( for each of the input sources Sat / Cable / Terr 4 separate fav lists )
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ tv . db ( contains channels from all sources )
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ channellib \ * ChannelMaps . db ( separate files for Cable and Terrestrial )
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ channellib \ * Db . bin ( separate files for Cable and Terrestrial )
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ s2channellib \ SatelliteChannelMaps . db
* PhilipsChannelMaps \ ChannelMap_30 \ ChannelList \ s2channellib \ SatelliteDb . bin
* e . g . 40 PUK6400 / 12
*
2021-01-09 12:06:32 +01:00
* version 45.1
* PhilipsChannelMaps \ ChannelMap_45 \ ChannelList \ chanLst . bin
2021-04-11 12:08:47 +02:00
* PhilipsChannelMaps \ ChannelMap_45 \ ChannelList \ list . db ( favorite lists for all sources )
* PhilipsChannelMaps \ ChannelMap_45 \ ChannelList \ tv . db ( SQLite database including all channels - maybe just for EPG ? )
2021-01-09 12:06:32 +01:00
* PhilipsChannelMaps \ ChannelMap_45 \ ChannelList \ channelLib \ * Db . bin
* PhilipsChannelMaps \ ChannelMap_45 \ ChannelList \ s2channellib \ * Db . bin
* e . g . 65 PUS7601 / 12 , 55 PUS6581 / 12 , 43 PUS6401 / 12 , 55 PUS8601 / 12
*
* version 100.0
* PhilipsChannelMaps \ ChannelMap_100 \ ChannelList \ chanLst . bin
* PhilipsChannelMaps \ ChannelMap_100 \ ChannelList \ channellib \ DVB * . xml
* PhilipsChannelMaps \ ChannelMap_100 \ ChannelList \ s2channellib \ DVBS . xml
* e . g . 65 PUS6754 / 12 , 24 PFT4022 / 12
*
* version 105.0
* PhilipsChannelMaps \ ChannelMap_105 \ Favorite . xml
* rest like 100.0
* e . g . 43 PUS7307 / 12 , 49 PUS8303 / 12 , 65 PUS8503 / 12 , 55 OLED803 / 12
*
* version 110.0
* same as 105.0
* e . g . 65 PUS8535 / 12 , 55 PUS7334 / 12
*
2021-09-19 20:28:57 +02:00
* version 115.0
2023-11-03 17:40:43 +01:00
* same as 105.0
*
* version 120.0
* same as 105 plus additional ChannelList \ MtkChannelList . xml
2024-10-01 10:05:48 +02:00
*
* version 125.0
* same as 120
2021-01-09 12:06:32 +01:00
*
2023-11-03 17:40:43 +01:00
* Version 0.1 and 100 - 120 are XML based and loaded through the XmlSerializer .
2021-01-09 12:06:32 +01:00
* Version 1.1 and 1.2 are loaded through the BinSerializer .
* Version 0.0 , 11.1 and 45.1 are not supported yet .
* /
public string DllName { get ; set ; }
public string PluginName = > "Philips" ;
2021-08-24 19:41:31 +02:00
public string FileFilter = > "*.bin;*.xml;*.db" ;
2021-01-09 12:06:32 +01:00
public SerializerBase CreateSerializer ( string inputFile )
{
int majorVersion = int . MinValue ;
2025-01-28 21:26:53 +01:00
int minorVersion = int . MinValue ;
2021-08-31 22:13:28 +02:00
var filename = Path . GetFileName ( inputFile ) . ToLowerInvariant ( ) ;
2021-01-09 12:06:32 +01:00
if ( Regex . IsMatch ( filename , @"^CM_.*\.(?:bin|xml)$" , RegexOptions . IgnoreCase ) )
majorVersion = 0 ;
2024-08-18 17:41:46 +02:00
else if ( filename . ToLowerInvariant ( ) = = "__chtb_do_not_delete_.xml" ) // Tornado 32ES1500E format
majorVersion = 0 ;
2021-01-09 12:06:32 +01:00
else
{
// allow the user to pick pretty much any file within a Repair\ChannelList or PhilipsChannelMaps\ChannelMap_xxx\ChannelList structure to find a chanLst.bin
var dir = Path . GetDirectoryName ( inputFile ) ;
while ( true )
{
var path = Path . Combine ( dir , "chanLst.bin" ) ;
if ( File . Exists ( path ) )
{
inputFile = path ;
var data = File . ReadAllBytes ( inputFile ) ;
majorVersion = BitConverter . ToInt16 ( data , 2 ) ;
2025-01-28 21:26:53 +01:00
minorVersion = BitConverter . ToInt16 ( data , 4 ) ;
2021-01-09 12:06:32 +01:00
break ;
}
2021-08-24 19:41:31 +02:00
path = Path . Combine ( dir , "channel_db_ver.db" ) ;
if ( File . Exists ( path ) )
{
inputFile = path ;
majorVersion = - 1 ;
break ;
}
2021-08-31 22:13:28 +02:00
var dirName = Path . GetFileName ( dir ) . ToLowerInvariant ( ) ;
2021-01-09 12:06:32 +01:00
if ( dirName = = "channellib" | | dirName = = "s2channellib" )
dir = Path . GetDirectoryName ( dir ) ;
else if ( Directory . Exists ( Path . Combine ( dir , "PhilipsChannelMaps" ) ) )
dir = Path . Combine ( dir , "PhilipsChannelMaps" ) ;
else if ( Directory . Exists ( Path . Combine ( dir , "ChannelList" ) ) )
dir = Path . Combine ( dir , "ChannelList" ) ;
else
{
var maps = Directory . GetDirectories ( dir , "ChannelMap_*" ) ;
if ( maps . Length > 0 )
dir = maps [ 0 ] ;
else
break ;
}
}
}
2025-01-28 21:26:53 +01:00
if ( majorVersion = = 0 & & minorVersion ! = 0 | | majorVersion > = 100 & & majorVersion < = 125 )
2021-01-09 12:06:32 +01:00
return new XmlSerializer ( inputFile ) ;
2025-01-28 21:26:53 +01:00
if ( majorVersion is > = 0 and < = 2 | | majorVersion = = 30 | | majorVersion = = 45 ) // || majorVersion == 11 // format version 11 is similar to 1.x, but not (yet) supported
2021-01-09 12:06:32 +01:00
return new BinarySerializer ( inputFile ) ;
2021-08-24 19:41:31 +02:00
if ( majorVersion = = - 1 )
return new DbSerializer ( inputFile ) ;
2021-01-09 12:06:32 +01:00
2022-12-04 18:18:52 +01:00
if ( majorVersion ! = int . MinValue )
throw LoaderException . Fail ( $"Philips ChannelMap format version {majorVersion} is not supported (yet)." ) ;
throw LoaderException . TryNext ( SerializerBase . ERR_UnknownFormat ) ;
2021-01-09 12:06:32 +01:00
}
}
}