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
*
*
* Version 0.1 and 100 - 110 are XML based and loaded through the XmlSerializer .
* 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" ;
public string FileFilter = > "*.bin;*.xml" ;
public SerializerBase CreateSerializer ( string inputFile )
{
int majorVersion = int . MinValue ;
var filename = Path . GetFileName ( inputFile ) . ToLower ( ) ;
if ( Regex . IsMatch ( filename , @"^CM_.*\.(?:bin|xml)$" , RegexOptions . IgnoreCase ) )
majorVersion = 0 ;
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 ) ;
break ;
}
var dirName = Path . GetFileName ( dir ) . ToLower ( ) ;
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 ;
}
}
}
if ( majorVersion = = 0 | | majorVersion > = 100 & & majorVersion < = 110 )
return new XmlSerializer ( inputFile ) ;
2021-04-11 12:08:47 +02:00
if ( majorVersion = = 1 | | 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-01-17 15:44:45 +01:00
throw new FileLoadException ( $"Philips ChannelMap format version {majorVersion} is not supported." ) ;
2021-01-09 12:06:32 +01:00
}
}
}