threefive3 3.0.29__tar.gz → 3.0.31__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {threefive3-3.0.29/threefive3.egg-info → threefive3-3.0.31}/PKG-INFO +1 -1
  2. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/bitn.py +1 -1
  3. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/commands.py +1 -0
  4. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/cue.py +10 -21
  5. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/descriptors.py +1 -2
  6. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/gums.py +9 -13
  7. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/hls.py +5 -5
  8. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/hlstags.py +1 -13
  9. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/new_reader.py +9 -3
  10. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/stream.py +90 -89
  11. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/stuff.py +8 -0
  12. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/version.py +1 -1
  13. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/words.py +6 -0
  14. {threefive3-3.0.29 → threefive3-3.0.31/threefive3.egg-info}/PKG-INFO +1 -1
  15. {threefive3-3.0.29 → threefive3-3.0.31}/LICENSE +0 -0
  16. {threefive3-3.0.29 → threefive3-3.0.31}/README.md +0 -0
  17. {threefive3-3.0.29 → threefive3-3.0.31}/bin/threefive3 +0 -0
  18. {threefive3-3.0.29 → threefive3-3.0.31}/setup.cfg +0 -0
  19. {threefive3-3.0.29 → threefive3-3.0.31}/setup.py +0 -0
  20. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/__init__.py +0 -0
  21. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/aac.py +1 -1
  22. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/base.py +0 -0
  23. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/crc.py +0 -0
  24. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/encode.py +0 -0
  25. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/iframes.py +0 -0
  26. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/packetdata.py +0 -0
  27. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/section.py +0 -0
  28. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/segment.py +0 -0
  29. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/segmentation.py +0 -0
  30. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/sixfix.py +0 -0
  31. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/streamtypes.py +0 -0
  32. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/superkabuki.py +0 -0
  33. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3/upids.py +0 -0
  34. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3.egg-info/SOURCES.txt +0 -0
  35. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3.egg-info/dependency_links.txt +0 -0
  36. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3.egg-info/requires.txt +0 -0
  37. {threefive3-3.0.29 → threefive3-3.0.31}/threefive3.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: threefive3
3
- Version: 3.0.29
3
+ Version: 3.0.31
4
4
  Summary: SCTE-35 decoder and encoder with MPEGTS and HLS and XML support.
5
5
  Home-page: https://github.com/superkabuki/threefive3
6
6
  Author: Adrian of Doom
@@ -157,7 +157,7 @@ class NBin:
157
157
  and appends it to self.nbits
158
158
  via self.add_int
159
159
  """
160
- dehexed=False
160
+ dehexed = False
161
161
  if isinstance(hex_str, str):
162
162
  dehexed = int(hex_str, 16)
163
163
  # just in case hex_str is an int....
@@ -84,6 +84,7 @@ class PrivateCommand(SpliceCommand):
84
84
  nbin.add_bites(self.private_bytes)
85
85
  return nbin.bites
86
86
 
87
+
87
88
  class SpliceNull(SpliceCommand):
88
89
  """
89
90
  Table 8 - splice_null()
@@ -12,19 +12,7 @@ from .commands import command_map, SpliceCommand
12
12
  from .descriptors import splice_descriptor, descriptor_map
13
13
  from .crc import crc32
14
14
  from .segmentation import table22
15
- from .words import (
16
- minusone,
17
- zero,
18
- one,
19
- two,
20
- three,
21
- four,
22
- eight,
23
- eleven,
24
- fourteen,
25
- sixteen,
26
- equalsign,
27
- )
15
+ from .words import *
28
16
 
29
17
 
30
18
  class Cue(SCTE35Base):
@@ -436,23 +424,24 @@ class Cue(SCTE35Base):
436
424
  """
437
425
 
438
426
  if isinstance(
439
- gonzo, bytes
427
+ gonzo, str
440
428
  ): # a string is returned for Binary xml tag, make sense?
441
- if '<scte35:Binary>' in gonzo:
442
- dat = gonzo.split('<scte35:Binary>')[1].split('</scte35:Binary>')[0]
429
+ if "<scte35:Binary>" in gonzo:
430
+ dat = gonzo.split("<scte35:Binary>")[1].split("</scte35:Binary>")[0]
443
431
  self.bites = self._mk_bits(dat)
444
432
  self.decode()
433
+ else:
434
+ blue("Only xml+binary format supported ")
445
435
  else:
446
- blue('Only xml+binary format supported ')
447
-
436
+ blue("xmlbin data needs to be str instance")
448
437
 
449
438
  def xmlbin(self, ns="scte35"):
450
439
  """
451
440
  xml returns a threefive3.Node instance
452
441
  which can be edited as needed or printed.
453
442
  xmlbin
454
-
443
+
455
444
  """
456
- return f'''<scte35:Signal xmlns:scte35="https://scte.org/schemas/35">
445
+ return f"""<scte35:Signal xmlns:scte35="https://scte.org/schemas/35">
457
446
  <scte35:Binary>{self.base64()}</scte35:Binary>
458
- </scte35:Signal>'''
447
+ </scte35:Signal>"""
@@ -6,7 +6,7 @@ from .bitn import Bitn
6
6
  from .base import SCTE35Base
7
7
  from .segmentation import table20, table22, dvb_table2
8
8
  from .upids import upid_map
9
- from .stuff import red,blue
9
+ from .stuff import red, blue
10
10
 
11
11
 
12
12
  def k_by_v(adict, avalue):
@@ -419,7 +419,6 @@ class SegmentationDescriptor(SpliceDescriptor):
419
419
  nbin.add_int(0, 8)
420
420
 
421
421
 
422
-
423
422
  # map of known descriptors and associated classes
424
423
  descriptor_map = {
425
424
  0: AvailDescriptor,
@@ -13,7 +13,7 @@ import sys
13
13
  import time
14
14
  from functools import partial
15
15
  from .new_reader import reader
16
- from .stuff import blue
16
+ from .stuff import blue, reblue, print2
17
17
 
18
18
 
19
19
  DGRAM_SIZE = 1316
@@ -58,7 +58,7 @@ class GumS:
58
58
  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
59
59
  sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
60
60
  if hasattr(socket, "SO_REUSEPORT"):
61
- blue('setting SO_REUSEPORT')
61
+ blue("setting SO_REUSEPORT")
62
62
  sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
63
63
  return sock
64
64
 
@@ -78,11 +78,9 @@ class GumS:
78
78
  total_bytes += len(dgram)
79
79
  elapsed = now() - start_time
80
80
  rate = (total_bytes / million) / elapsed
81
- mb=total_bytes/million
82
- print(
83
- f"\t{mb:0.2f} MB sent in {elapsed:5.2f} seconds. {rate:3.2f} MB/Sec",
84
- end="\r",
85
- file=sys.stderr,
81
+ mb = total_bytes / million
82
+ reblue(
83
+ f"\t{mb:0.2f} MB sent in {elapsed:5.2f} seconds. {rate:3.2f} MB/Sec"
86
84
  )
87
85
  print("\n", file=sys.stderr)
88
86
 
@@ -100,11 +98,8 @@ class GumS:
100
98
  proto = proto + "@"
101
99
  pre = "Multicast"
102
100
  src_ip, src_port = self.sock.getsockname()
103
- print(
104
- f"\n\t{pre} Stream\n\t{proto}{self.dest_ip}:{self.dest_port}",
105
- file=sys.stderr,
106
- )
107
- print(f"\n\tSource\n\t{src_ip}:{src_port}\n", file=sys.stderr)
101
+ print2(f"\n\t{pre} Stream\n\t{proto}{self.dest_ip}:{self.dest_port}")
102
+ print2(f"\n\tSource\n\t{src_ip}:{src_port}\n")
108
103
 
109
104
  self.iter_dgrams(vid)
110
105
  self.sock.close()
@@ -165,6 +160,7 @@ def fork():
165
160
  def daemonize():
166
161
  """
167
162
  The Steven's double fork
163
+ detach process from controling tty
168
164
  """
169
165
 
170
166
  fork()
@@ -189,7 +185,7 @@ def cli():
189
185
  """
190
186
 
191
187
  args = parse_args()
192
- # daemonize()
188
+ # daemonize()
193
189
  ttl = int(args.ttl).to_bytes(1, byteorder="big")
194
190
  dest_addr = args.addr
195
191
  gummie = GumS(dest_addr, ttl, args.bind_addr)
@@ -389,7 +389,7 @@ class HlsParser:
389
389
  for sidef in [self.sidecar, self.dumpfile, self.flat, self.m3u8]:
390
390
  with open(sidef, "w+", encoding="utf-8") as side_file: # touch
391
391
  side_file.close()
392
- # pass
392
+ # pass
393
393
 
394
394
  def chk_aes(self, line):
395
395
  """
@@ -416,7 +416,7 @@ class HlsParser:
416
416
  """
417
417
  to_dump copies all SCTE-35 lines to self.dumpfile.
418
418
  """
419
- with open(self.dumpfile, "a",encoding ="utf-8") as dump:
419
+ with open(self.dumpfile, "a", encoding="utf-8") as dump:
420
420
  dump_line = f"{pts},{line}\n"
421
421
  if dump_line != self.last_dump_line:
422
422
  dump.write(dump_line)
@@ -890,7 +890,7 @@ class HlsParser:
890
890
  write_flat flatten out the sliding window
891
891
  and write all data to flat.m3u8.
892
892
  """
893
- with open(self.flat, "a",encoding ="utf-8") as flat:
893
+ with open(self.flat, "a", encoding="utf-8") as flat:
894
894
  if self.first_segment:
895
895
  flat.write("#EXTM3U\n")
896
896
  for header in self.headers:
@@ -904,7 +904,7 @@ class HlsParser:
904
904
  write_manifest write data to sc.m3u8
905
905
  with profile rules applied.
906
906
  """
907
- with open(self.m3u8, "w",encoding ="utf-8") as out:
907
+ with open(self.m3u8, "w", encoding="utf-8") as out:
908
908
  out.write("#EXTM3U\n")
909
909
  out.write("".join(self.headers))
910
910
  out.write(self.sliding_window.all_panes())
@@ -965,7 +965,7 @@ class HlsParser:
965
965
  self.sliding_window = SlidingWindow()
966
966
  while self.reload:
967
967
  self._parse_manifest()
968
- with open(self.flat, "a",encoding ="utf-8") as flat:
968
+ with open(self.flat, "a", encoding="utf-8") as flat:
969
969
  flat.write("#EXT-X-ENDLIST\n")
970
970
 
971
971
  def pick_one(self, lines, uri):
@@ -4,19 +4,7 @@ hlstags.py
4
4
  """
5
5
 
6
6
  from .stuff import atohif
7
- from .words import (
8
- minusone,
9
- zero,
10
- one,
11
- two,
12
- equalsign,
13
- comma,
14
- colon,
15
- space,
16
- nothing,
17
- dblquote,
18
- octothorpe,
19
- )
7
+ from .words import *
20
8
 
21
9
  BASIC_TAGS = (
22
10
  "#EXTM3U",
@@ -79,17 +79,19 @@ def lshiftbuf(socked):
79
79
  socked.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, rcvbuf_size)
80
80
  blue(f" socket.SO_RCVBUF set to {rcvbuf_size}")
81
81
  except:
82
- blue("Unable to left shift socket.SO_RCVBUF")
82
+ blue(" Unable to left shift socket.SO_RCVBUF")
83
83
 
84
84
 
85
85
  def _mk_socked():
86
86
  socked = Socked(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
87
87
  lshiftbuf(socked)
88
88
  socked.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
89
+ blue(" setting socket.SO_REUSEADDR")
89
90
  if hasattr(socket, "SO_REUSEPORT"):
90
- blue('setting SO_REUSEPORT')
91
+ blue(" setting socket.SO_REUSEPORT")
91
92
  socked.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
92
93
  socked.settimeout(TIMEOUT)
94
+ blue(f" setting socket timeout to {TIMEOUT}")
93
95
  return socked
94
96
 
95
97
 
@@ -97,6 +99,7 @@ def _mk_udp_sock(udp_ip, udp_port):
97
99
  """
98
100
  udp socket setup
99
101
  """
102
+ blue(" Opening UDP Unicast socket")
100
103
  udp_sock = _mk_socked()
101
104
  udp_sock.bind((udp_ip, udp_port))
102
105
  return udp_sock
@@ -115,11 +118,14 @@ def _open_mcast(uri):
115
118
  """
116
119
  udp://@227.1.3.10:4310
117
120
  """
121
+ blue(" Opening Multicast socket")
122
+ TTL = 32
118
123
  interface_ip = "0.0.0.0"
119
124
  multicast_group, port = (uri.split("udp://@")[1]).rsplit(":", 1)
120
125
  multicast_port = int(port)
121
126
  socked = _mk_socked()
122
- socked.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", 32))
127
+ socked.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", TTL))
128
+ blue(f" TTL set to {TTL}")
123
129
  socked.bind(("", multicast_port))
124
130
  socked.setsockopt(
125
131
  socket.SOL_IP,
@@ -10,7 +10,9 @@ from .stuff import print2, blue
10
10
  from .cue import Cue
11
11
  from .packetdata import PacketData
12
12
  from .streamtypes import streamtype_map
13
- #from .iframes import IFramer
13
+ from .words import *
14
+
15
+ # from .iframes import IFramer
14
16
 
15
17
 
16
18
  def no_op(cue):
@@ -52,7 +54,7 @@ class ProgramInfo:
52
54
  self.streams = {} # pid to stream_type mapping
53
55
 
54
56
  def _mk_vee(self, k):
55
- vee = int(self.streams[k], base=16)
57
+ vee = int(self.streams[k], base=sixteen)
56
58
  if vee in streamtype_map:
57
59
  vee = f"{hex(vee)}\t{streamtype_map[vee]}"
58
60
  else:
@@ -84,8 +86,8 @@ class Pids:
84
86
  Pids holds sets of pids for pat,pcr,pmt, and scte35
85
87
  """
86
88
 
87
- SDT_PID = 0x11
88
- PAT_PID = 0x00
89
+ SDT_PID = eleven
90
+ PAT_PID = zero
89
91
 
90
92
  def __init__(self):
91
93
  self.pcr = set()
@@ -160,7 +162,7 @@ class Stream:
160
162
  self.the_scte35_pids = []
161
163
  self.pids = Pids()
162
164
  self.maps = Maps()
163
- # self.iframer = IFramer(shush=True)
165
+ # self.iframer = IFramer(shush=True)
164
166
  self.pmt_payloads = set()
165
167
  self.pmt_count = 0
166
168
 
@@ -172,42 +174,42 @@ class Stream:
172
174
  """
173
175
  as_90k returns ticks as 90k clock time
174
176
  """
175
- return round((ticks / 90000.0), 6)
177
+ return round((ticks / 90000.0), six)
176
178
 
177
179
  @staticmethod
178
180
  def _pusi_flag(pkt):
179
- return pkt[1] & 0x40
181
+ return pkt[one] & sixtyfour
180
182
 
181
183
  @staticmethod
182
184
  def _afc_flag(pkt3):
183
- return pkt3 & 0x20
185
+ return pkt3 & thirtytwo
184
186
 
185
187
  @staticmethod
186
188
  def _pcr_flag(pkt):
187
- return pkt[5] & 0x10
189
+ return pkt[five] & sixteen
188
190
 
189
191
  @staticmethod
190
192
  def _spi_flag(pkt):
191
- return pkt[5] & 0x20
193
+ return pkt[five] & thirtytwo
192
194
 
193
195
  @staticmethod
194
196
  def _pts_flag(pay):
195
197
  # uses pay not pkt
196
- return pay[7] & 0x80
198
+ return pay[seven] & onetwentyeight
197
199
 
198
200
  @staticmethod
199
201
  def _parse_length(byte1, byte2):
200
202
  """
201
203
  parse a 12 bit length value
202
204
  """
203
- return (byte1 & 0xF) << 8 | byte2
205
+ return (byte1 & fifteen) << eight | byte2
204
206
 
205
207
  @staticmethod
206
208
  def _parse_pid(byte1, byte2):
207
209
  """
208
210
  parse a 13 bit pid value
209
211
  """
210
- pid = (byte1 & 0x1F) << 8 | byte2
212
+ pid = (byte1 & fifteen) << eight | byte2
211
213
  return pid
212
214
 
213
215
  @staticmethod
@@ -215,7 +217,7 @@ class Stream:
215
217
  """
216
218
  parse a 16 bit program number value
217
219
  """
218
- return (byte1 << 8) | byte2
220
+ return (byte1 << eight) | byte2
219
221
 
220
222
  @staticmethod
221
223
  def _split_by_idx(pay, marker):
@@ -231,16 +233,16 @@ class Stream:
231
233
  if SYNC_BYTE is found.
232
234
  """
233
235
  while self._tsdata:
234
- one = self._tsdata.read(1)
235
- if one:
236
- if one[0] == self.SYNC_BYTE:
237
- tail = self._tsdata.read(self.PACKET_SIZE - 1)
238
- self._parse(one + tail)
236
+ bite = self._tsdata.read(one)
237
+ if bite:
238
+ if bite[zero] == self.SYNC_BYTE:
239
+ tail = self._tsdata.read(self.PACKET_SIZE - one)
240
+ self._parse(bite + tail)
239
241
  return True
240
242
  print2("No Stream Found\n")
241
243
  return False
242
244
 
243
- def iter_pkts(self, num_pkts=1):
245
+ def iter_pkts(self, num_pkts=one):
244
246
  """
245
247
  iter_pkts iterates a mpegts stream into packets
246
248
  """
@@ -293,8 +295,8 @@ class Stream:
293
295
  decode_start_time
294
296
  """
295
297
  self.decode(func=no_op)
296
- if len(self.start.values()) > 0:
297
- return self.start.popitem()[1]
298
+ if len(self.start.values()) > zero:
299
+ return self.start.popitem()[one]
298
300
  return False
299
301
 
300
302
  def proxy(self, func=show_cue_stderr):
@@ -317,8 +319,8 @@ class Stream:
317
319
  self.info = True
318
320
  for pkt in self.iter_pkts():
319
321
  self._parse(pkt)
320
- if self.pmt_count > len(self.pmt_payloads) << 1:
321
- blue(f'PMT Count: {self.pmt_count}')
322
+ if self.pmt_count > len(self.pmt_payloads) << one:
323
+ blue(f"PMT Count: {self.pmt_count}")
322
324
  break
323
325
  if self.maps.prgm.keys():
324
326
  sopro = sorted(self.maps.prgm.items())
@@ -354,7 +356,7 @@ class Stream:
354
356
  pid2prgm takes a pid,
355
357
  returns the program
356
358
  """
357
- prgm = 1
359
+ prgm = one
358
360
  if pid in self.maps.pid_prgm:
359
361
  return self.maps.pid_prgm[pid]
360
362
  return False
@@ -380,18 +382,17 @@ class Stream:
380
382
  return False
381
383
 
382
384
  def _unpad(self, bites):
383
- pad = 255
384
- one = 1
385
+ pad = twofiftyfive
385
386
  if not bites:
386
387
  return b""
387
- while bites[0] == pad:
388
- bites = bites[1:]
388
+ while bites[zero] == pad:
389
+ bites = bites[one:]
389
390
  return self._unpad2(bites)
390
391
 
391
392
  def _unpad2(self, bites):
392
- pad = 255
393
- while bites[-1] == pad:
394
- bites = bites[:-1]
393
+ pad = twofiftyfive
394
+ while bites[minusone] == pad:
395
+ bites = bites[:minusone]
395
396
  return bites
396
397
 
397
398
  def _mk_packet_data(self, pid):
@@ -403,10 +404,10 @@ class Stream:
403
404
 
404
405
  def _parse_cc(self, pkt, pid):
405
406
  last_cc = None
406
- c_c = pkt[3] & 0xF
407
+ c_c = pkt[three] & fifteen
407
408
  if pid in self.maps.pid_cc:
408
409
  last_cc = self.maps.pid_cc[pid]
409
- good = (last_cc, ((last_cc + 1) % 16))
410
+ good = (last_cc, ((last_cc + one) % sixteen))
410
411
  if c_c not in good:
411
412
  print2(f" # BAD --> pid:\t{hex(pid)}\tlast cc:\t{last_cc}\tcc:\t{c_c}")
412
413
  self.maps.pid_cc[pid] = c_c
@@ -420,25 +421,25 @@ class Stream:
420
421
  ## idx = pkt.index(b"\x00\x00\x01")
421
422
  ## if pkt[idx + 3 : idx + 4] in [b"\xe0", b"\xc0", b"\xbd"]:
422
423
  payload = self._parse_payload(pkt)
423
- if len(payload) > 13:
424
+ if len(payload) > thirteen:
424
425
  if self._pts_flag(payload):
425
- pts = (payload[9] & 14) << 29
426
- pts |= payload[10] << 22
427
- pts |= (payload[11] >> 1) << 15
428
- pts |= payload[12] << 7
429
- pts |= payload[13] >> 1
426
+ pts = (payload[nine] & fourteen) << twentynine
427
+ pts |= payload[ten] << twentytwo
428
+ pts |= (payload[eleven] >> one) << fifteen
429
+ pts |= payload[twelve] << seven
430
+ pts |= payload[thirteen] >> one
430
431
  prgm = self.pid2prgm(pid)
431
432
  self.maps.prgm_pts[prgm] = pts
432
433
  if prgm not in self.start:
433
434
  self.start[prgm] = pts
434
435
 
435
436
  def _parse_pcr(self, pkt, pid):
436
- if self._afc_flag(pkt[3]):
437
- pcr = pkt[6] << 25
438
- pcr |= pkt[7] << 17
439
- pcr |= pkt[8] << 9
440
- pcr |= pkt[9] << 1
441
- pcr |= pkt[10] >> 7
437
+ if self._afc_flag(pkt[three]):
438
+ pcr = pkt[six] << twentyfive
439
+ pcr |= pkt[seven] << seventeen
440
+ pcr |= pkt[eight] << nine
441
+ pcr |= pkt[nine] << one
442
+ pcr |= pkt[ten] >> seven
442
443
  prgm = self.pid2prgm(pid)
443
444
  self.maps.prgm_pcr[prgm] = pcr
444
445
 
@@ -446,17 +447,17 @@ class Stream:
446
447
  """
447
448
  _parse_payload returns the packet payload
448
449
  """
449
- head_size = 4
450
- if self._afc_flag(pkt[3]):
451
- pkt = pkt[:4] + self._unpad(pkt[4:])
452
- afl = pkt[4]
453
- head_size += afl + 1 # +1 for afl byte
450
+ head_size = four
451
+ if self._afc_flag(pkt[three]):
452
+ pkt = pkt[:four] + self._unpad(pkt[four:])
453
+ afl = pkt[four]
454
+ head_size += afl + one # +1 for afl byte
454
455
  return pkt[head_size:]
455
456
 
456
457
  def _pmt_pid(self, pay, pid):
457
- self.pmt_count += 1
458
+ self.pmt_count += one
458
459
  if pay in self.pmt_payloads:
459
- if self.pmt_count > len(self.pmt_payloads) << 1:
460
+ if self.pmt_count > len(self.pmt_payloads) << one:
460
461
  return
461
462
  self.pmt_payloads.add(pay)
462
463
  self._parse_pmt(pay, pid)
@@ -488,7 +489,7 @@ class Stream:
488
489
  _parse_info parses the packet for tables
489
490
  and returns the pid
490
491
  """
491
- pid = self._parse_pid(pkt[1], pkt[2])
492
+ pid = self._parse_pid(pkt[one], pkt[two])
492
493
  if pid in self.pids.tables:
493
494
  self._parse_tables(pkt, pid)
494
495
  return pid
@@ -534,9 +535,9 @@ class Stream:
534
535
 
535
536
  def _section_incomplete(self, pay, pid, seclen):
536
537
  # + 3 for the bytes before section starts
537
- if len(pay) > (seclen + 3):
538
+ if len(pay) > (seclen + three):
538
539
  return False
539
- if (seclen + 3) > len(pay):
540
+ if (seclen + three) > len(pay):
540
541
  self.maps.partial[pid] = pay
541
542
  return True
542
543
 
@@ -551,8 +552,8 @@ class Stream:
551
552
  def _strip_scte35_pes(self, pkt):
552
553
  pay = self._parse_payload(pkt)
553
554
  if self.SCTE35_PES_START in pay:
554
- pay = pay.split(self.SCTE35_PES_START, 1)[-1]
555
- peslen = pay[4] + 5 # PES header length
555
+ pay = pay.split(self.SCTE35_PES_START, 1)[minusone]
556
+ peslen = pay[four] + five # PES header length
556
557
  pay = pay[peslen:]
557
558
  return pay
558
559
 
@@ -565,7 +566,7 @@ class Stream:
565
566
  if not pay:
566
567
  self._pop_maybe_pid(pid)
567
568
  return False
568
- if pay[13] == self.show_null:
569
+ if pay[thirteen] == self.show_null:
569
570
  return False
570
571
  return pay
571
572
 
@@ -582,10 +583,10 @@ class Stream:
582
583
  pay = self._mk_scte35_payload(pkt, pid)
583
584
  if not pay:
584
585
  return False
585
- seclen = self._parse_length(pay[1], pay[2])
586
+ seclen = self._parse_length(pay[one], pay[two])
586
587
  if self._section_incomplete(pay, pid, seclen):
587
588
  return False
588
- pay = pay[: seclen + 3]
589
+ pay = pay[: seclen + three]
589
590
  cue = self._parse_cue(pay, pid)
590
591
  return cue
591
592
 
@@ -603,25 +604,25 @@ class Stream:
603
604
  pay = self._chk_partial(pay, self.pids.SDT_PID, self.SDT_TID)
604
605
  if not pay:
605
606
  return False
606
- seclen = self._parse_length(pay[1], pay[2])
607
+ seclen = self._parse_length(pay[one], pay[two])
607
608
  if self._section_incomplete(pay, self.pids.SDT_PID, seclen):
608
609
  return False
609
610
  idx = 11
610
- while idx < seclen + 3:
611
- service_id = self._parse_program(pay[idx], pay[idx + 1])
612
- idx += 3
613
- dloop_len = self._parse_length(pay[idx], pay[idx + 1])
614
- idx += 2
615
- i = 0
611
+ while idx < seclen + three:
612
+ service_id = self._parse_program(pay[idx], pay[idx + one])
613
+ idx += three
614
+ dloop_len = self._parse_length(pay[idx], pay[idx + one])
615
+ idx += two
616
+ i = zero
616
617
  while i < dloop_len:
617
618
  if pay[idx] == 0x48:
618
- i += 3
619
+ i += three
619
620
  spnl = pay[idx + i]
620
- i += 1
621
+ i += one
621
622
  provider_name = pay[idx + i : idx + i + spnl]
622
623
  i += spnl
623
624
  snl = pay[idx + i]
624
- i += 1
625
+ i += one
625
626
  service_name = pay[idx + i : idx + i + snl]
626
627
  i += snl
627
628
  self._mk_pinfo(service_id, provider_name, service_name)
@@ -636,16 +637,16 @@ class Stream:
636
637
  for program to pmt_pid mappings.
637
638
  """
638
639
  pay = self._chk_partial(pay, self.pids.PAT_PID, b"")
639
- seclen = self._parse_length(pay[2], pay[3])
640
+ seclen = self._parse_length(pay[two], pay[three])
640
641
  if self._section_incomplete(pay, self.pids.PAT_PID, seclen):
641
642
  return False
642
- seclen -= 5 # pay bytes 4,5,6,7,8
643
- idx = 9
644
- chunk_size = 4
645
- while seclen > 4: # 4 bytes for crc
646
- program_number = self._parse_program(pay[idx], pay[idx + 1])
647
- if program_number > 0:
648
- pmt_pid = self._parse_pid(pay[idx + 2], pay[idx + 3])
643
+ seclen -= five # pay bytes 4,5,6,7,8
644
+ idx = nine
645
+ chunk_size = four
646
+ while seclen > four: # 4 bytes for crc
647
+ program_number = self._parse_program(pay[idx], pay[idx + one])
648
+ if program_number > zero:
649
+ pmt_pid = self._parse_pid(pay[idx + two], pay[idx + three])
649
650
  self.pids.pmt.add(pmt_pid)
650
651
  self.pids.tables.add(pmt_pid)
651
652
  seclen -= chunk_size
@@ -659,13 +660,13 @@ class Stream:
659
660
  pay = self._chk_partial(pay, pid, self.PMT_TID)
660
661
  if not pay:
661
662
  return False
662
- seclen = self._parse_length(pay[1], pay[2])
663
+ seclen = self._parse_length(pay[one], pay[two])
663
664
  if self._section_incomplete(pay, pid, seclen):
664
665
  return False
665
- program_number = self._parse_program(pay[3], pay[4])
666
+ program_number = self._parse_program(pay[three], pay[four])
666
667
  if not program_number:
667
668
  return False
668
- pcr_pid = self._parse_pid(pay[8], pay[9])
669
+ pcr_pid = self._parse_pid(pay[eight], pay[nine])
669
670
  if program_number not in self.maps.prgm:
670
671
  self.maps.prgm[program_number] = ProgramInfo()
671
672
  pinfo = self.maps.prgm[program_number]
@@ -673,9 +674,9 @@ class Stream:
673
674
  pinfo.pcr_pid = pcr_pid
674
675
  self.pids.pcr.add(pcr_pid)
675
676
  self.maps.pid_prgm[pcr_pid] = program_number
676
- proginfolen = self._parse_length(pay[10], pay[11])
677
- idx = 12 + proginfolen
678
- si_len = seclen - (9 + proginfolen)
677
+ proginfolen = self._parse_length(pay[ten], pay[eleven])
678
+ idx = twelve + proginfolen
679
+ si_len = seclen - (nine + proginfolen)
679
680
  self._parse_program_streams(si_len, pay, idx, program_number)
680
681
  return True
681
682
 
@@ -685,8 +686,8 @@ class Stream:
685
686
  from a program
686
687
  """
687
688
  # 5 bytes for stream_type info
688
- chunk_size = 5
689
- end_idx = (idx + si_len) - 4
689
+ chunk_size = five
690
+ end_idx = (idx + si_len) - four
690
691
  while end_idx - chunk_size >= idx:
691
692
  stream_type, pid, ei_len = self._parse_stream_type(pay, idx)
692
693
  pinfo = self.maps.prgm[program_number]
@@ -699,8 +700,8 @@ class Stream:
699
700
  extract stream pid and type
700
701
  """
701
702
  stream_type = hex(pay[idx])
702
- el_pid = self._parse_pid(pay[idx + 1], pay[idx + 2])
703
- ei_len = self._parse_length(pay[idx + 3], pay[idx + 4])
703
+ el_pid = self._parse_pid(pay[idx + one], pay[idx + two])
704
+ ei_len = self._parse_length(pay[idx + three], pay[idx + four])
704
705
  self._set_scte35_pids(el_pid, stream_type)
705
706
  return stream_type, el_pid, ei_len
706
707
 
@@ -62,3 +62,11 @@ def blue(message):
62
62
  """
63
63
  mesg = f"\033[;107m\033[44m{message} \033[0m"
64
64
  print2(mesg)
65
+
66
+
67
+ def reblue(message):
68
+ """
69
+ reblue overwrites the last line in place
70
+ """
71
+ mesg = f"\033[;107m\033[44m{message} \033[0m"
72
+ print(mesg, end="\r", file=stderr, flush=True)
@@ -5,6 +5,6 @@ from the cli tool run: threefive3 version
5
5
 
6
6
  major = 3
7
7
  minor = 0
8
- maintenance = 29
8
+ maintenance = 31
9
9
 
10
10
  version = f"{major}.{minor}.{maintenance}"
@@ -23,8 +23,14 @@ thirteen = 0xD
23
23
  fourteen = 0xE
24
24
  fifteen = 0xF
25
25
  sixteen = 0x10
26
+ twentyone = 0x15
27
+ twentytwo = 0x16
26
28
  twentyfour = 0x18
29
+ twentynine = 0x1D
27
30
  thirtytwo = 0x20
31
+ thirtythree = 0x21
32
+ sixtyfour = 0x40
33
+ onetwentyeight = 0x80
28
34
  twofiftyfive = 0xFF
29
35
  twofiftysix = 0x100
30
36
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: threefive3
3
- Version: 3.0.29
3
+ Version: 3.0.31
4
4
  Summary: SCTE-35 decoder and encoder with MPEGTS and HLS and XML support.
5
5
  Home-page: https://github.com/superkabuki/threefive3
6
6
  Author: Adrian of Doom
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -2,6 +2,7 @@
2
2
  aac.py
3
3
  home of the AacParser for audio only hls renditions
4
4
  """
5
+
5
6
  from .new_reader import reader
6
7
 
7
8
 
@@ -59,4 +60,3 @@ class AacParser:
59
60
  except:
60
61
  pts = self.syncsafe5(data.split(self.applehead)[1][:9])
61
62
  return round((pts % ROLLOVER), 6)
62
-