Guest User

convert mst40 to text file

a guest
May 31st, 2014
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. ==============
  3. (©) by Michael Slomski
  4. ==============
  5.  
  6. This stuff will read  a ".mst40" File from Metz-TV and a write some of the content to a pure text file.
  7. User of your own risk!
  8.  
  9. For every Questions write to alex.in.muc at web dot de
  10.  
  11. *)
  12.  
  13. property unsigned : false --    0..255 oder 0..65553
  14. property signed : true --       -127..127 oder -31xxx..31xxx
  15.  
  16. global rawData
  17.  
  18.  
  19.  
  20. (* ====================================================== *)
  21. to data_to_string(d)
  22.     try
  23.         d as text
  24.     on error m
  25.     end try
  26.     set o1 to offset of "«" in m
  27.     set o2 to offset of "»" in m
  28.     {m's text (o1 + 6) thru (o1 + 9), m's text (o1 + 10) thru (o2 - 1)}
  29. end data_to_string
  30.  
  31.  
  32. on Hex2String(inData)
  33.     set theString to ""
  34.     repeat with i from 1 to count inData by 2
  35.         set theString to theString & character id hexToNum((item i of inData & item (i + 1) of inData), unsigned)
  36.     end repeat
  37.     return theString
  38. end Hex2String
  39.  
  40.  
  41. on hexToNum(inVal, myParam)
  42.     script o
  43.         property hexChrs : "0123456789abcdef" as Unicode text -- TIDs obey AppleScript's case attribute with Unicode.
  44.        
  45.         on getHexVal(c)
  46.             set AppleScript's text item delimiters to c
  47.             set v to (count text item 1 of hexChrs)
  48.             if (v is 16) then error "Non-hex character(s)."
  49.            
  50.             return v
  51.         end getHexVal
  52.     end script
  53.    
  54.     set astid to AppleScript's text item delimiters
  55.     try
  56.         set inVal to inVal as Unicode text -- Speeds up use of TIDs with Unicode 'hexChrs' in o.
  57.         tell o to set n to getHexVal(character 1 of inVal)
  58.         if myParam and (n > 7) then set n to n - 16
  59.        
  60.         repeat with i from 2 to (count inVal)
  61.             tell o to set n to n * 16 + getHexVal(character i of inVal)
  62.         end repeat
  63.     on error msg number errNum
  64.         set AppleScript's text item delimiters to astid
  65.         log inVal
  66.         error "hexToNum handler: " & msg number errNum
  67.     end try
  68.     set AppleScript's text item delimiters to astid
  69.    
  70.     return n
  71. end hexToNum
  72.  
  73.  
  74. on getN_Bytes(theOff, theLen)
  75.     set h to theOff * 2 - 1
  76.     set inData to text h thru (h + theLen * 2 - 1) of rawData
  77.     set theAscii to ""
  78.     repeat with i from 1 to count inData by 2
  79.         set theAscii to theAscii & " " & (item i of inData & item (i + 1) of inData)
  80.     end repeat
  81.     return {theOff + theLen, theAscii}
  82. end getN_Bytes
  83.  
  84.  
  85. on getInt16(theOff, mySign)
  86.     set h to theOff * 2 - 1
  87.    
  88.     set hexStr to text (h + 2) thru (h + 3) of rawData & text h thru (h + 1) of rawData
  89.     return {theOff + 2, hexToNum(hexStr, mySign)}
  90. end getInt16
  91.  
  92.  
  93. on getInt32(theOff, mySign)
  94.     set h to theOff * 2 - 1
  95.     set hexStr to text (h + 6) thru (h + 7) of rawData & text (h + 4) thru (h + 5) of rawData & text (h + 2) thru (h + 3) of rawData & text h thru (h + 1) of rawData
  96.     return {theOff + 4, hexToNum(hexStr, mySign)} -- newOff, value
  97. end getInt32
  98.  
  99.  
  100. on getByte(theOff, mySign)
  101.     set h to theOff * 2 - 1
  102.     set hexStr to text h thru (h + 1) of rawData
  103.    
  104.     if mySign = 1 then
  105.         -- Wertebereich immer nur 0..9
  106.         set retval to hexStr as number
  107.     else
  108.         set retval to hexToNum(hexStr, mySign)
  109.     end if
  110.     return {theOff + 1, retval}
  111. end getByte
  112.  
  113.  
  114. on getBool(theOff)
  115.     set {nextPos, nHex} to getByte(theOff, unsigned)
  116.     return {nextPos, item (nHex + 1) of {false, true}}
  117. end getBool
  118.  
  119.  
  120. on getFreq(theOff)
  121.     set {h, a} to getByte(theOff, unsigned)
  122.     set {h, b} to getByte(theOff + 1, unsigned)
  123.     --log {a, b, (a / 16) + (b * 16)}
  124.    
  125.     return {theOff + 2, (a / 16) + (b * 16)}
  126. end getFreq
  127.  
  128.  
  129. on get2ByteHex(theOff)
  130.     set h to theOff * 2 - 1
  131.     set hexStr to text (h + 2) thru (h + 3) of rawData & text h thru (h + 1) of rawData
  132.    
  133.     return {theOff + 2, hexStr} -- newOff, value
  134. end get2ByteHex
  135.  
  136.  
  137. on get3ByteHex(theOff)
  138.     set h to theOff * 2 - 1
  139.     set hexStr to text (h + 4) thru (h + 5) of rawData & text (h + 2) thru (h + 3) of rawData & text h thru (h + 1) of rawData
  140.     return {theOff + 3, hexStr} -- newOff, value
  141. end get3ByteHex
  142.  
  143.  
  144. on doShowTvList(tvList)
  145.    
  146.     try
  147.         set exFile to (choose file name with prompt "Senderliste speichern" default name "Senderliste.txt") as text
  148.         if exFile does not end with ".txt" then set exFile to exFile & ".txt"
  149.        
  150.         set exFileRef to (open for access exFile with write permission)
  151.         set fileOpen to true
  152.         set AppleScript's text item delimiters to tab
  153.     on error
  154.         set fileOpen to false
  155.         log "Fehler 1"
  156.     end try
  157.    
  158.    
  159.     try
  160.         repeat with aItem in tvList
  161.             log aItem
  162.             if fileOpen then
  163.                 write (aItem as text) to exFileRef
  164.                 write return to exFileRef
  165.             end if
  166.         end repeat
  167.        
  168.     on error
  169.         if fileOpen = true then close exFileRef
  170.         set fileOpen to false
  171.         log "Fehler 2"
  172.         set AppleScript's text item delimiters to ""
  173.     end try
  174.    
  175.     if fileOpen = true then
  176.         close exFileRef
  177.         set AppleScript's text item delimiters to ""
  178.     end if
  179. end doShowTvList
  180.  
  181.  
  182. on getText(theOff, theLen)
  183.     --log {theOff, theLen}
  184.     set h to theOff * 2 - 1
  185.     set hexStr to text h thru (h + theLen * 2 - 1) of rawData
  186.     return Hex2String(hexStr)
  187. end getText
  188.  
  189. (* ====================================================== *)
  190.  
  191.  
  192.  
  193. (* ====================================================== *)
  194. on getAllgemein(someOffset, blockSize)
  195.     --set {h, sData} to (getN_Bytes(someOffset, blockSize))
  196.     --log {someOffset, h, sData}
  197.     set aLen to 0
  198.     set aName to ""
  199.     set aDecoder to false
  200.     set aKlang to "generell"
  201.     set aKlangKorr to 0
  202.     set aEPG to false
  203.    
  204.    
  205.     -- charCodeTable
  206.     set {h, aCharCodeTable} to getByte(someOffset, unsigned) -- wirklich true, d.h immer < 10?
  207.     --log {h, aCharCodeTable}
  208.    
  209.     -- Decoder (yes/no) {0=off, 1 = on}
  210.     set {h, aDecoder} to getBool(someOffset + 1)
  211.     --log {h, "Decoder: ", aDecoder}
  212.    
  213.     -- Klangeinstellung (generell / Sprache / Normal)   { 0,1,2}
  214.     set {h, aKlang} to getByte(someOffset + 2, unsigned)
  215.     set aKlang to item (aKlang + 1) of {"generell", "Sprache", "Normal"}
  216.     --log {h, "Klang: ", aKlang}
  217.    
  218.     -- Lautstärkeeinstellung (-30..30)
  219.     set {h, aKlangKorr} to getByte(someOffset + 3, unsigned)
  220.     --log {h, aKlangKorr}
  221.    
  222.     -- in EPG anzeigen (true / false) {0=off, 1 = on}
  223.     set {h, aEPG} to getBool(someOffset + 4)
  224.     --log {h, aEPG}
  225.    
  226.    
  227.     return {aCharCodeTable, aDecoder, aKlang, aKlangKorr, aEPG}
  228. end getAllgemein
  229.  
  230.  
  231.  
  232. on getTV(someOffset)
  233.     set aCNI to "0000"
  234.     set aFarbKorr to 0
  235.     set aKontrastKorr to 0
  236.     set aBildKorr to 0
  237.     set aRauschRed to 0
  238.     set aCTI to 0
  239.     set aKammfilter to 0
  240.     set aFarbversatz to 0
  241.     set aBildformat to 0
  242.     set aVideoprofil to 0
  243.    
  244.    
  245.     -- CNI-Daten { 0x0000 }
  246.     set {h, aCNI} to get2ByteHex(someOffset)
  247.     --log {h, "aCNI : 0x" & aCNI}
  248.    
  249.    
  250.     -- Farbstärke-Korr {-30..30}
  251.     set {h, aFarbKorr} to getByte(someOffset + 2, unsigned)
  252.     --log {h, "aFarbKorr : ", aFarbKorr}
  253.    
  254.     -- Kontrast-Korr {-30..30}
  255.     set {h, aKontrastKorr} to getByte(someOffset + 3, unsigned)
  256.     --log {h, "aKontrastKorr : ", aKontrastKorr}
  257.    
  258.     -- Bildschärfe-Korr {generell, 1..5}
  259.     set {h, aBildKorr} to getByte(someOffset + 4, unsigned)
  260.     --log {h, "aBildKorr : ", aBildKorr}
  261.     set aBildKorr to item (aBildKorr + 1) of {"generell", 1, 2, 3, 4, 5}
  262.    
  263.     -- Rauschreduktion {0..5}
  264.     set {h, aRauschRed} to getByte(someOffset + 5, unsigned)
  265.     --log {h, "aRauschRed : ", aRauschRed}
  266.    
  267.     -- CTI  {"generell", "aus", "an"}
  268.     set {h, aCTI} to getByte(someOffset + 6, unsigned)
  269.     --log {h, "aCTI : ", aCTI}
  270.     set aCTI to item (aCTI + 1) of {"generell", "aus", "an"}
  271.    
  272.     -- Kammfilter {"generell", "aus", "an"}
  273.     set {h, aKammfilter} to getByte(someOffset + 7, unsigned)
  274.     --log {h, "aKammfilter : ", aKammfilter}
  275.     set aKammfilter to item (aKammfilter + 1) of {"generell", "aus", "an"}
  276.     --log {h, "aKammfilter : ", aKammfilter}
  277.    
  278.     -- Farbversatz {-3..3}
  279.     set {h, aFarbversatz} to getByte(someOffset + 8, unsigned)
  280.     --log {h, "aFarbversatz : ", aFarbversatz}
  281.    
  282.     -- Bildformat
  283.     set {h, aBildformat} to getByte(someOffset + 9, unsigned)
  284.     --log {h, "aBildformat : ", aBildformat}
  285.     set aBildformat to item (aBildformat + 1) of {"4:3", "16:9", "Automatik", "Original"}
  286.     --log {h, 4, aBildformat}
  287.    
  288.     -- Videoprofil {}
  289.     set {h, aVideoprofil} to getByte(someOffset + 10, unsigned)
  290.     --log {h, "aVideoprofil : ", aVideoprofil}
  291.     set aVideoprofil to item (aVideoprofil + 1) of {"Standard", "Sport", "Brillant", "Spiele", "PC_Monitor", "Benutzer", "undefiniert", "generell"}
  292.     --log {h, "aVideoprofil : ", aVideoprofil}
  293.    
  294.    
  295.     return {aCNI, aFarbKorr, aKontrastKorr, aBildKorr, aRauschRed, aCTI, aKammfilter, aFarbversatz, aBildformat, aVideoprofil}
  296. end getTV
  297.  
  298.  
  299. (* DVB *)
  300. on getDVB(someOffset, blkSize, isRadio)
  301.     set aServiceID to 0
  302.     set aIsCryped to false
  303.     set aCaNr to 0
  304.     set aVideoDecoder to 0
  305.     set aSubAudio to false
  306.     set aAudioTag to 0
  307.     set aVideoFormat to 0
  308.     set aAudioFormat to 0
  309.     set aCaSystemPIDs to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} --    16 HexWerte á 2 Byte
  310.     set pIDs to {0, 0, 0, 0}
  311.    
  312.    
  313.     set {h, aServiceID} to getInt16(someOffset + 6, unsigned)
  314.     --log {"aserviceID : ", aserviceID}
  315.    
  316.     set aCaSystemPIDs to {}
  317.     repeat with i from 0 to 15 --16x2Byte
  318.         --set h to (someOffset + 8) + i * 2
  319.         set {h, aPID} to get2ByteHex(h)
  320.         set aCaSystemPIDs to aCaSystemPIDs & aPID
  321.     end repeat
  322.     log {h, "aCaSystemPIDs : ", aCaSystemPIDs}
  323.    
  324.     set {h, aIsCryped} to getBool(someOffset + 40)
  325.     --log {h, "aIsCryped : ", aIsCryped}
  326.    
  327.     set {h, aCaNr} to getByte(someOffset + 41, unsigned)
  328.     set aCaNr to item (aCaNr + 1) of {"kein", "1", "2", "auto"}
  329.     --log {h, "aCaNr : ", aCaNr}
  330.    
  331.     set {h, aVideoDecoder} to getByte(someOffset + 42, unsigned)
  332.     set aVideoDecoder to item (aVideoDecoder + 1) of {"SD", "HD", "kein"}
  333.     --log {h, "aVideoDecoder : ", aVideoDecoder}
  334.    
  335.     set {h, aSubAudio} to getBool(someOffset + 43)
  336.     --log {h, "aSubAudio : ", aSubAudio}
  337.    
  338.     set {h, aAudioTag} to getByte(someOffset + 44, unsigned)
  339.     --log {h, "aAudioTag : ", aAudioTag}
  340.    
  341.     set {h, aVideoFormat} to getByte(someOffset + 45, unsigned)
  342.     set aVideoFormat to item (aVideoFormat + 1) of {"SD", "HD-MPEG2", "HD-MPEG4", "SD-MPEG4"}
  343.     --log {h, "aVideoFormat : ", aVideoFormat}
  344.    
  345.     if not isRadio then
  346.         set {h, aPID_PCR} to getInt16(someOffset + 46, unsigned)
  347.         set {h, aPID_Audio} to getInt16(someOffset + 48, unsigned)
  348.         set {h, aPID_TTX} to getInt16(someOffset + 50, unsigned)
  349.         set {h, aPID_Video} to getInt16(someOffset + 52, unsigned)
  350.         set pIDs to {aPID_Audio, aPID_Video, aPID_PCR, aPID_TTX}
  351.     else
  352.         set pIDs to {aPID_PCR, aPID_Audio}
  353.     end if
  354.     --log {h, "pIDs : ", pIDs}
  355.    
  356.     set {h, aAudioFormat} to getByte(someOffset + blkSize + 18, unsigned) -- ACHTUNG, der liegt meilenweit weg vom Rest!
  357.     --log {h, "aAudioFormat : ", aAudioFormat}
  358.     set aAudioFormat to item (aAudioFormat + 1) of {"MPEG", "AC3", "EnhAC3", "AAC", "HE-AAC"}
  359.     --log {h, "aAudioFormat : ", aAudioFormat}
  360.    
  361.    
  362.     return {aServiceID, aIsCryped, aCaNr, aVideoDecoder, aSubAudio, aAudioTag, aVideoFormat, aAudioFormat, aCaSystemPIDs, pIDs}
  363. end getDVB
  364.  
  365.  
  366. (* KnotenAllgm *)
  367. on getKnotenAllgm(someOffset, isRadio)
  368.     set aNetzwerkTyp to "---"
  369.     set aTransportStreamID to 0
  370.     set aOriginalNetworkID to 0
  371.     set aFreq to 0
  372.     set aSymbolrate to 0
  373.    
  374.    
  375.     -- aNetzwerkTyp {}
  376.     set {h, aNetzwerkTyp} to getByte(someOffset, unsigned)
  377.     set aNetzwerkTyp to item (aNetzwerkTyp + 1) of {"unbekannt", "DVB-C", "DVB-S", "DVB-T", "DVB-C2", "DVB-S2", "DVB-T2", "Analog"}
  378.     --log {h, "aNetzwerkTyp : ", aNetzwerkTyp}
  379.    
  380.     -- aTransportStreamID {}
  381.     set {h, aTransportStreamID} to getInt16(someOffset + 1, unsigned)
  382.     --log {h, "aTransportStreamID : ", aTransportStreamID}
  383.    
  384.     -- aOriginalNetworkID {}
  385.     set {h, aOriginalNetworkID} to getInt16(someOffset + 3, unsigned) -- Bereich?
  386.     --log {h, "aOriginalNetworkID : ", aOriginalNetworkID}
  387.    
  388.     -- aSymbolrate {}
  389.     set {h, aSymbolrate} to getInt16(someOffset + 5, unsigned)
  390.     --log {h, "aSymbolrate : ", aSymbolrate}
  391.    
  392.     -- aFreq {}
  393.     set {h, aFreq} to getInt32(someOffset + 7, unsigned)
  394.     log {h, "aFreq : ", aFreq}
  395.    
  396.    
  397.     return {aNetzwerkTyp, aTransportStreamID, aOriginalNetworkID, aFreq, aSymbolrate}
  398. end getKnotenAllgm
  399.  
  400.  
  401. (* Terrestische Programmplatzdaten (ANALOG)*)
  402. on getTerrestrisch(someOffset)
  403.     set aFreq to 0
  404.     set aVCR to 0
  405.     set aZMono to false
  406.     set aFarbnorm to 0
  407.     set aTVStd to 0
  408.    
  409.    
  410.     -- Freq.
  411.     set {h, aFreq} to getFreq(someOffset) --    ??? Real wie 479,25 2 Byte
  412.     log {"aCNI : ", aFreq}
  413.    
  414.     -- VCR (aus / Opt.1 / Opt.2)
  415.     set {h, aVCR} to getByte(someOffset + 2, unsigned)
  416.     set aVCR to item (aVCR + 1) of {"aus", "Opt.1", "Opt.2"}
  417.     --log {"aVCR : ", aVCR}
  418.    
  419.     -- Zwangsmono (ein / aus)
  420.     set {h, aZMono} to getByte(someOffset + 3, unsigned) --  5 = on; 6 = off
  421.     set aZMono to item (aZMono - 4) of {true, false}
  422.     --log {"aZMono : ", aZMono}
  423.    
  424.     -- Farbnorm (Automatik / PAL / SECAM / NTSC / NTSC44 / PAL60 / PAL M / PAL N)
  425.     set {h, aFarbnorm} to getByte(someOffset + 4, unsigned)
  426.     set aFarbnorm to item (aFarbnorm + 1) of {"Automatik", "PAL", "SECAM", "NTSC", "NTSC44", "PAL60", "PAL M", "PAL N"}
  427.     --log {"aFarbnorm : ", aFarbnorm}
  428.    
  429.     -- TV-Standard (B/G, D/K, I, L, M/N)
  430.     set {h, aTVStd} to getByte(someOffset + 5, unsigned)
  431.     set aTVStd to item (aTVStd + 1) of {"B/G", "D/K", "I", "L", "M/N"}
  432.     --log {"aTVStd : ", aTVStd}
  433.    
  434.    
  435.     return {aFreq, aVCR, aZMono, aFarbnorm, aTVStd}
  436. end getTerrestrisch
  437.  
  438.  
  439. (* Knoten DVB-S *)
  440. on getDVB_S(someOffset)
  441.     set aPolarisation to "hor"
  442.     set aSatellit to "---"
  443.     set aDVB_System to "---"
  444.     set aRollOff to "---"
  445.     set aFEC to "---"
  446.    
  447.    
  448.     -- Polarisation {}
  449.     set {h, b} to getBool(someOffset, unsigned)
  450.     if b then set aPolarisation to "vert"
  451.     --log {h, "aPolarisation : ", aPolarisation}
  452.    
  453.     -- Satellit {}
  454.     set {h, aSatellit} to getByte(someOffset + 1, unsigned)
  455.     set aSatellit to item (aSatellit + 1) of {"A", "B", "C", "D"}
  456.     --log {h, "aSatellit : ", aSatellit}
  457.    
  458.     -- RollOff {}
  459.     set {h, aRollOff} to getByte(someOffset + 4, unsigned) --???
  460.     set aRollOff to item (aRollOff + 1) of {"0.35", "0.25", "0.20"}
  461.     --log {h, "aRollOff : ", aRollOff}
  462.    
  463.     -- Modulations-Typ {}
  464.     set {h, aModTyp} to getByte(someOffset + 8, unsigned)
  465.     set aModTyp to item (aModTyp + 1) of {"auto", "QPSK", "8PSK", "16QAM"}
  466.     --log {h, "aModTyp : ", aModTyp}
  467.    
  468.     -- DVB_System {}
  469.     set {h, aDVB_System} to getByte(someOffset + 9, unsigned)
  470.     set aDVB_System to item (aDVB_System + 1) of {"DVB-S", "DVB-S2"}
  471.     --log {h, "aDVB_System : ", aDVB_System}
  472.    
  473.     -- FEC {}
  474.     set {h, aFEC} to getByte(someOffset + 11, unsigned)
  475.     set aFEC to item (aFEC + 1) of {"undef", "1/2", "2/3", "3/4", "5/6", "7/8", "8/9", "3/5", "4/5", "9/10"}
  476.     --log {h, "aFEC : ", aFEC}
  477.    
  478.    
  479.     return {aPolarisation, aSatellit, aDVB_System, aModTyp, aRollOff, aFEC}
  480. end getDVB_S
  481.  
  482.  
  483. (* Knoten DVB-T *)
  484. on getDVB_T(someOffset)
  485.     set aConstellation to "---"
  486.     set aCodeRateHP to "---"
  487.     set aTransMode to "---"
  488.     set aGuardIntervall to "---"
  489.    
  490.    
  491.     -- Constellation {}
  492.     set {h, aConstellation} to getByte(someOffset + 3, unsigned)
  493.     --log {h, aConstellation}
  494.     set aConstellation to item (aConstellation + 1) of {"QPSK", "16QAM", "64QAM"}
  495.     --log {h, "aConstellation : ", aConstellation}
  496.    
  497.     -- Code-Rate-HP {}
  498.     set {h, aCodeRateHP} to getByte(someOffset + 4, unsigned)
  499.     set aCodeRateHP to item (aCodeRateHP + 1) of {"1/2", "2/3", "3/4", "5/6", "7/8"}
  500.     --log {h, "aCodeRateHP : ", aCodeRateHP}
  501.    
  502.     -- aTransmission-Mode {}
  503.     set {h, aTransMode} to getByte(someOffset + 5, unsigned)
  504.     set aTransMode to item (aTransMode + 1) of {"2k", "4k", "8k"}
  505.     --log {h, "aTransMode : ", aTransMode}
  506.    
  507.     -- aGuardIntervall {}
  508.     set {h, aGuardIntervall} to getByte(someOffset + 6, unsigned)
  509.     set aGuardIntervall to item (aGuardIntervall + 1) of {"1/32", "1/16", "1/8", "1/4"}
  510.     --log {h, "aGuardIntervall : ", aGuardIntervall}
  511.    
  512.    
  513.     return {aConstellation, aCodeRateHP, aTransMode, aGuardIntervall}
  514. end getDVB_T
  515.  
  516.  
  517. (* Knoten DVB-C *)
  518. on getDVB_C(someOffset)
  519.     set aModulation to "---"
  520.    
  521.    
  522.     -- Modulation {}
  523.     set {h, aModulation} to getByte(someOffset + 2, unsigned)
  524.     --log {h, "aModulation : ", aModulation}
  525.     set aModulation to item (aModulation + 1) of {"AutoQAUM", "16QAM", "32QAM", "64QAM", "128QAM", "256QAM", "QPSK"}
  526.     log {h, "aModulation : ", aModulation}
  527.    
  528.     -- in +6 steht auch noch was drin!
  529.     return {aModulation}
  530. end getDVB_C
  531. (* ====================================================== *)
  532. (* ====================================================== *)
  533.  
  534.  
  535.  
  536. (* ==== File auswählen ==== *)
  537. (* ================== *)
  538. set thefile to choose file of type {"mst40"}
  539. set filecontent to read thefile as data
  540. close thefile
  541.  
  542.  
  543. -- fileData in Text wandeln
  544. set rawData to item 2 of data_to_string(filecontent)
  545.  
  546.  
  547. log (" ---------------------------")
  548. set myOff to 1
  549. set {h, sData} to getN_Bytes(myOff, 2)
  550. log {tab & tab, myOff, 2, tab & tab & sData}
  551. set myOff to h
  552.  
  553. set {h, sData} to getN_Bytes(myOff, 2)
  554. log {tab & tab, myOff, 2, tab & tab & sData}
  555. log (" ---------------------------")
  556.  
  557. (* ==== auf richtige Dateiversion testen ==== *)
  558. (* =========================== *)
  559. if text 1 thru 4 of rawData ≠ "0004" then
  560.     display dialog "Sorry, unbekanntes Dateiformat. Es wird nur das 4er mit der Dateiendung '.mst40' unterstützt"
  561.     -- und raus bist du
  562.     return -128
  563. end if
  564. set myOff to 3
  565.  
  566.  
  567. -- jetzt die Anzahl der TV-Kanäle bestimmen
  568. -- TV Sender (kommen wohl immer zuerst)
  569. set {myOff, tvCount} to (getInt16(myOff, signed))
  570.  
  571.  
  572.  
  573. set blockSize to 4
  574. set {h, sData} to (getN_Bytes(myOff, blockSize)) -- unbekannt, 67 Bytes überspringen
  575. log {tab & tab, myOff, blockSize, tab & sData}
  576. set myOff to h
  577.  
  578.  
  579. set tvList to {}
  580. repeat with i from 1 to tvCount
  581.     log {"Nr.: " & i & " ", myOff, blockSize, tab & sData}
  582.     set myOff to h
  583.    
  584.    
  585.     set {h, aProgTyp} to getByte(myOff, unsigned)
  586.    
  587.    
  588.     if aProgTyp = 0 then
  589.         -- undefined, wieviel überspringen bis zum nächsten?
  590.         set blockSize to 99
  591.         set {h, sData} to (getN_Bytes(myOff, blockSize))
  592.         log {tab & tab, myOff, blockSize, tab & sData}
  593.         set myOff to h
  594.         set tvList to tvList & {{"Nr.: " & i, "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---"}}
  595.        
  596.     end if
  597.    
  598.     if {1, 3, 4, 5, 8, 9, 10} contains aProgTyp then
  599.         -- allgm lesen
  600.         set {h, aLen} to getByte(myOff + 1, unsigned)
  601.         set channelName to getText(h, aLen)
  602.         --log {myOff + 1 + h, aLen, aName}
  603.         set h2 to 1 + (aLen + 1)
  604.         set blockSize to h2 + 5 + 2 -- Füllbytes "von unten"
  605.         set {h, sData} to getN_Bytes(myOff, blockSize)
  606.         log {tab & tab, myOff, blockSize, tab & sData, tab & channelName}
  607.        
  608.         set {charCodeTable, decoder, klang, lautKorr, inEPG} to getAllgemein(myOff + h2, blockSize - aLen - 2)
  609.         log {"Nr.: " & i, channelName, charCodeTable, decoder, klang, lautKorr, inEPG}
  610.         set myOff to myOff + blockSize
  611.        
  612.         --if progType = 2 then break
  613.        
  614.         if {1, 3, 4, 5} contains aProgTyp then
  615.             (*  werden derzeit bei 1. Block mitgelesen
  616.             set blockSize to 2
  617.             set {h, sData} to (getN_Bytes(myOff, blockSize)) -- unbekannt, 2 Bytes überspringen
  618.             log {tab & tab, myOff, blockSize, tab & sData}
  619.             set myOff to h
  620. *)
  621.             -- Block TV lesen
  622.             set blockSize to 11
  623.             set {h, sData} to getN_Bytes(myOff, blockSize)
  624.             log {tab & tab, myOff, blockSize, tab & sData}
  625.            
  626.             set {cni, farbKorr, kontkorr, bildKorr, rauschRed, cti, kammfilter, farbversatz, bildformat, videoprofil} to getTV(myOff)
  627.             log {"0x" & cni, farbKorr, kontkorr, bildKorr, rauschRed, cti, kammfilter, farbversatz, bildformat, videoprofil}
  628.             log
  629.             set myOff to h
  630.         end if
  631.        
  632.         if aProgTyp = 1 then
  633.             -- Terrestrisch (Analog)
  634.             set blockSize to 12
  635.             set {h, sData} to getN_Bytes(myOff, blockSize)
  636.             log {tab & tab, myOff, blockSize, tab & sData}
  637.            
  638.             set {freq, vcr, zMono, farbnorm, tvStd} to getTerrestrisch(myOff)
  639.             log {freq, vcr, zMono, farbnorm, tvStd}
  640.             set tvList to tvList & {{"Nr.: " & i, channelName, inEPG, "0x" & cni, freq, "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---", "---"}}
  641.             set myOff to h
  642.            
  643.            
  644.             set blockSize to 67
  645.             set {h, sData} to (getN_Bytes(myOff, blockSize)) -- unbekannt, 67 Bytes überspringen
  646.             log {tab & tab, myOff, blockSize, tab & sData}
  647.             set myOff to h
  648.         end if
  649.        
  650.         if {3, 4, 5} contains aProgTyp then
  651.             -- Block DVB lesen
  652.             set blockSize to 54
  653.             set {h, sData} to getN_Bytes(myOff, blockSize)
  654.             log {tab & tab, myOff, blockSize, tab & sData}
  655.            
  656.             set {serviceID, isCryped, caNr, videoDecoder, subAudio, audioTag, videoFormat, audioFormat, caSystemPIDs, pIDs} to getDVB(myOff, blockSize, false) -- false = TV, true = Radio
  657.             log {serviceID, isCryped, caNr, videoDecoder, subAudio, audioTag, videoFormat, audioFormat, caSystemPIDs, pIDs}
  658.             log
  659.             set myOff to h
  660.            
  661.             -- Block Knoten allgm. lesen
  662.             set blockSize to 11
  663.             set {h, sData} to getN_Bytes(myOff, blockSize)
  664.             log {tab & tab, myOff, blockSize, tab & sData}
  665.            
  666.             set {netzwerkTyp, transportStreamID, originalNetworkID, freq, symbolrate} to getKnotenAllgm(myOff, false) -- false = TV, true = Radio
  667.             log {netzwerkTyp, transportStreamID, originalNetworkID, freq, symbolrate}
  668.             log
  669.             set myOff to h
  670.            
  671.             if aProgTyp = 3 then
  672.                 -- Block DVB-S lesen
  673.                 set blockSize to 14
  674.                 set {h, sData} to getN_Bytes(myOff, blockSize)
  675.                 log {tab & tab, myOff, blockSize, tab & sData}
  676.                
  677.                 set {polarisation, satellit, dvbSystem, modTyp, rollOff, fec} to getDVB_S(myOff)
  678.                 log {polarisation, satellit, dvbSystem, modTyp, rollOff, fec}
  679.                 set tvList to tvList & {{"Nr.: " & i, channelName, inEPG, "0x" & cni, freq, isCryped, pIDs, netzwerkTyp, serviceID, transportStreamID, originalNetworkID, symbolrate, Modulation, polarisation, "---", "---", "---", videoFormat, audioFormat}}
  680.                 log
  681.                 set myOff to h
  682.             end if
  683.            
  684.             if aProgTyp = 4 then
  685.                 -- Block DVB-T lesen
  686.                 set blockSize to 7 + 7
  687.                 set {h, sData} to getN_Bytes(myOff, blockSize)
  688.                 log {tab & tab, myOff, blockSize, tab & sData}
  689.                
  690.                 set {constellation, codeRateHP, transMode, guardIntervall} to getDVB_T(myOff)
  691.                 log {constellation, codeRateHP, transMode, guardIntervall}
  692.                 log
  693.                 set tvList to tvList & {{"Nr.: " & i, channelName, inEPG, "0x" & cni, freq, isCryped, pIDs, netzwerkTyp, serviceID, transportStreamID, originalNetworkID, symbolrate, Modulation, "---", codeRateHP, transMode, guardIntervall, videoFormat, audioFormat}}
  694.                 set myOff to myOff + h
  695.             end if
  696.            
  697.             if aProgTyp = 5 then
  698.                 -- Block DVB-C lesen
  699.                 set blockSize to 14 --  mit viel Luft!!!
  700.                 set {h, sData} to getN_Bytes(myOff, blockSize)
  701.                 log
  702.                 log {tab & tab, myOff, blockSize, tab & sData}
  703.                
  704.                 set Modulation to getDVB_C(myOff)
  705.                 log (Modulation)
  706.                 log
  707.                 set tvList to tvList & {{"Nr.: " & i, channelName, inEPG, "0x" & cni, freq, isCryped, pIDs, netzwerkTyp, serviceID, transportStreamID, originalNetworkID, symbolrate, Modulation, "---", "---", "---", "---", videoFormat, audioFormat}}
  708.                 set myOff to h
  709.             end if
  710.         end if
  711.     end if
  712.    
  713.     --return
  714.     log ("------------------------------------------------------------------------------------------------------------")
  715. end repeat
  716. (* ====================================================== *)
  717.  
  718. doShowTvList(tvList, true)
Advertisement
Add Comment
Please, Sign In to add comment