Permalink
Browse files

script to split squashed t42 file into a directory of separate t42 pages

  • Loading branch information...
ZXGuesser committed Dec 23, 2018
1 parent dbd2b51 commit 3340a896ff004dfa09e334e34f6dd38e5b9fa733
Showing with 26 additions and 0 deletions.
  1. +26 −0 t42split
@@ -0,0 +1,26 @@
#!/usr/bin/env python

import sys
import os

from teletext.t42.pipeline import reader, make_service
from teletext.t42.packet import Packet

if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

service = make_service(reader(open(sys.argv[1], 'rb')))

for magazineno,magazine in service.magazines.iteritems():
for pageno,page in magazine.pages.iteritems():
for subpageno,subpage in page.subpages.iteritems():
if magazineno == 0:
mag = 8
else:
mag = magazineno
outfile = open(os.path.join(sys.argv[2], 'P%d%02X-%04X.t42' % (mag, pageno, subpageno)), 'wb')
subpagepackets = subpage.to_packets(magazineno, pageno, subpageno, magazine.header(magazineno, subpage))
for i in subpagepackets:
outfile.write(i.to_bytes())
outfile.close()

0 comments on commit 3340a89

Please sign in to comment.