Skip to content

Commit

Permalink
script to split squashed t42 file into a directory of separate t42 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXGuesser committed Dec 23, 2018
1 parent dbd2b51 commit 3340a89
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 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.