threefive3 3.0.16__tar.gz → 3.0.17__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.16/threefive3.egg-info → threefive3-3.0.17}/PKG-INFO +3 -3
  2. {threefive3-3.0.16 → threefive3-3.0.17}/README.md +2 -2
  3. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/__init__.py +3 -4
  4. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/base.py +12 -4
  5. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/bitn.py +1 -1
  6. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/cue.py +17 -16
  7. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/descriptors.py +3 -1
  8. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/hls.py +22 -33
  9. threefive3-3.0.17/threefive3/hlstags.py +171 -0
  10. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/iframes.py +1 -1
  11. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/sixfix.py +15 -11
  12. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/stream.py +22 -18
  13. threefive3-3.0.17/threefive3/stuff.py +26 -0
  14. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/upids.py +4 -3
  15. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/version.py +1 -1
  16. {threefive3-3.0.16 → threefive3-3.0.17/threefive3.egg-info}/PKG-INFO +3 -3
  17. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3.egg-info/SOURCES.txt +2 -2
  18. threefive3-3.0.16/threefive3/m3ufu.py +0 -663
  19. threefive3-3.0.16/threefive3/spare.py +0 -12
  20. {threefive3-3.0.16 → threefive3-3.0.17}/LICENSE +0 -0
  21. {threefive3-3.0.16 → threefive3-3.0.17}/bin/threefive3 +0 -0
  22. {threefive3-3.0.16 → threefive3-3.0.17}/setup.cfg +0 -0
  23. {threefive3-3.0.16 → threefive3-3.0.17}/setup.py +0 -0
  24. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/commands.py +0 -0
  25. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/crc.py +0 -0
  26. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/new_reader.py +0 -0
  27. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/packetdata.py +0 -0
  28. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/section.py +0 -0
  29. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/segment.py +0 -0
  30. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/segmentation.py +0 -0
  31. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/streamtypes.py +0 -0
  32. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/sxp.py +0 -0
  33. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/x2c.py +0 -0
  34. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3/xml.py +0 -0
  35. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3.egg-info/dependency_links.txt +0 -0
  36. {threefive3-3.0.16 → threefive3-3.0.17}/threefive3.egg-info/requires.txt +0 -0
  37. {threefive3-3.0.16 → threefive3-3.0.17}/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.16
3
+ Version: 3.0.17
4
4
  Summary: threefive continued.
5
5
  Home-page: https://github.com/superkabuki/scte35
6
6
  Author: Adrian of Doom
@@ -46,7 +46,7 @@ Python 3.9.16 (7.3.11+dfsg-2+deb12u3, Dec 30 2024, 22:36:23)
46
46
  [PyPy 7.3.11 with GCC 12.2.0] on linux
47
47
  Type "help", "copyright", "credits" or "license" for more information.
48
48
 
49
- >>>> from threefive import Stream
49
+ >>>> from threefive3 import Stream
50
50
 
51
51
  >>>> strm=Stream('https://futzu.com/xaa.ts')
52
52
 
@@ -68,7 +68,7 @@ pypy3 -mpip install threefive3
68
68
  * from the git repo
69
69
  ```rebol
70
70
  git clone https://github.com/superkabuki/scte35.git
71
- cd scte35
71
+ cd threefive3
72
72
  make install
73
73
  ```
74
74
  ___
@@ -25,7 +25,7 @@ Python 3.9.16 (7.3.11+dfsg-2+deb12u3, Dec 30 2024, 22:36:23)
25
25
  [PyPy 7.3.11 with GCC 12.2.0] on linux
26
26
  Type "help", "copyright", "credits" or "license" for more information.
27
27
 
28
- >>>> from threefive import Stream
28
+ >>>> from threefive3 import Stream
29
29
 
30
30
  >>>> strm=Stream('https://futzu.com/xaa.ts')
31
31
 
@@ -47,7 +47,7 @@ pypy3 -mpip install threefive3
47
47
  * from the git repo
48
48
  ```rebol
49
49
  git clone https://github.com/superkabuki/scte35.git
50
- cd scte35
50
+ cd threefive3
51
51
  make install
52
52
  ```
53
53
  ___
@@ -2,12 +2,12 @@
2
2
  scte35.__init__.py
3
3
  """
4
4
 
5
- from .spare import print2
6
5
 
7
6
  from .cue import Cue
8
7
  from .section import SpliceInfoSection
9
8
  from .segment import Segment
10
9
  from .stream import Stream
10
+ from .stuff import print2
11
11
  from .version import version
12
12
 
13
13
  from .commands import (
@@ -29,10 +29,9 @@ from .descriptors import (
29
29
  SpliceDescriptor,
30
30
  TimeDescriptor,
31
31
  descriptor_map,
32
-
33
32
  )
34
33
 
35
- from .upids import(
34
+ from .upids import (
36
35
  Upid,
37
36
  NoUpid,
38
37
  AirId,
@@ -43,4 +42,4 @@ from .upids import(
43
42
  Mpu,
44
43
  Umid,
45
44
  upid_map,
46
- )
45
+ )
@@ -5,7 +5,7 @@ the class SCTE35Base.
5
5
 
6
6
  import json
7
7
  from .bitn import NBin
8
- from .spare import print2
8
+ from .stuff import print2
9
9
  from .xml import Node
10
10
 
11
11
 
@@ -18,7 +18,7 @@ class SCTE35Base:
18
18
  ROLLOVER = 8589934591
19
19
 
20
20
  def __init__(self):
21
- self.errors=[]
21
+ self.errors = []
22
22
 
23
23
  def __repr__(self):
24
24
  return str(self.__dict__)
@@ -31,7 +31,7 @@ class SCTE35Base:
31
31
 
32
32
  def _err2(self, var_name, var_value, bit_count, var_type):
33
33
  var_type = str(var_type).split("'")[1]
34
- err_mesg = f'{var_name} is {var_value} , it should be type {var_type}, {bit_count} bit(s) long.'
34
+ err_mesg = f"{var_name} is {var_value} , it should be type {var_type}, {bit_count} bit(s) long."
35
35
  self.errors.append(err_mesg)
36
36
 
37
37
  def _bool_int(self, var_name, var_value, bit_count, var_type):
@@ -146,7 +146,15 @@ class SCTE35Base:
146
146
  val = list(val)
147
147
  return val
148
148
 
149
- return {k: b2l(v) for k, v in vars(self).items() if v not in [None,[],] } # added empty list []
149
+ return {
150
+ k: b2l(v)
151
+ for k, v in vars(self).items()
152
+ if v
153
+ not in [
154
+ None,
155
+ [],
156
+ ]
157
+ } # added empty list []
150
158
 
151
159
  def _json2dict(self, gonzo):
152
160
  if isinstance(gonzo, str):
@@ -2,7 +2,7 @@
2
2
  The bitn.Bitn and bitn.NBin classes
3
3
  """
4
4
 
5
- from .spare import print2
5
+ from .stuff import print2
6
6
 
7
7
 
8
8
  class Bitn:
@@ -4,7 +4,7 @@ scte35.Cue Class
4
4
 
5
5
  from base64 import b64decode, b64encode
6
6
  import json
7
- from .spare import print2
7
+ from .stuff import print2
8
8
  from .bitn import NBin
9
9
  from .base import SCTE35Base
10
10
  from .section import SpliceInfoSection
@@ -47,7 +47,7 @@ class Cue(SCTE35Base):
47
47
  data may be packet bites or encoded string
48
48
  packet_data is a instance passed from a Stream instance
49
49
  """
50
- self.errors=[]
50
+ self.errors = []
51
51
  self.command = None
52
52
  self.descriptors = []
53
53
  self.info_section = SpliceInfoSection()
@@ -65,15 +65,15 @@ class Cue(SCTE35Base):
65
65
  def errs(self):
66
66
  """
67
67
  errs show encoding errors.
68
- """
69
- e= {"cue.errors": self.errors}
68
+ """
69
+ e = {"cue.errors": self.errors}
70
70
  if self.info_section:
71
- e["info_section_errors"] = self.info_section.has("errors")
72
- if isinstance(self.command, SpliceCommand):
73
- e["command_errors"]= self.command.errors
71
+ e["info_section_errors"] = self.info_section.has("errors")
72
+ if isinstance(self.command, SpliceCommand):
73
+ e["command_errors"] = self.command.errors
74
74
  e["descriptor_errors"] = [d.errors for d in self.descriptors]
75
75
  return e
76
-
76
+
77
77
  def decode(self):
78
78
  """
79
79
  Cue.decode() parses for SCTE35 data
@@ -147,12 +147,12 @@ class Cue(SCTE35Base):
147
147
  """
148
148
  return self.bites
149
149
 
150
- def fix_bad_b64(self,data):
150
+ def fix_bad_b64(self, data):
151
151
  """
152
152
  fix_bad_b64 fixes bad padding on Base64
153
153
  """
154
- if len(data) %4!=0:
155
- self.errors.append('fixed bad base64 length ')
154
+ if len(data) % 4 != 0:
155
+ self.errors.append("fixed bad base64 length ")
156
156
  while len(data) % 4 != 0:
157
157
  data = data + "="
158
158
  return data
@@ -255,7 +255,7 @@ class Cue(SCTE35Base):
255
255
  """
256
256
  sct = self.info_section.splice_command_type
257
257
  if sct not in command_map:
258
- self.errors.append(f"Splice Command type {sct} not recognized")
258
+ self.errors.append(f"Splice Command type {sct} not recognized")
259
259
  return False
260
260
  iscl = self.info_section.splice_command_length
261
261
  cmd_bites = bites[:iscl]
@@ -269,12 +269,12 @@ class Cue(SCTE35Base):
269
269
 
270
270
  def _assemble(self):
271
271
  for d in self.descriptors:
272
- d.errors=[]
272
+ d.errors = []
273
273
  dscptr_bites = self._unloop_descriptors()
274
274
  dll = len(dscptr_bites)
275
275
  self.info_section.descriptor_loop_length = dll
276
- self.info_section.errors=[]
277
- self.command.errors=[]
276
+ self.info_section.errors = []
277
+ self.command.errors = []
278
278
  cmd_bites = self.command.encode()
279
279
  cmdl = self.command.command_length = len(cmd_bites)
280
280
  self.info_section.splice_command_length = cmdl
@@ -389,7 +389,8 @@ class Cue(SCTE35Base):
389
389
  _no_cmd raises an exception if no splice command.
390
390
  """
391
391
  self.errors.append("A splice command is required")
392
- # raise Exception("\033[7mA splice command is required\033[27m")
392
+
393
+ # raise Exception("\033[7mA splice command is required\033[27m")
393
394
 
394
395
  def load(self, gonzo):
395
396
  """
@@ -461,7 +461,9 @@ class SegmentationDescriptor(SpliceDescriptor):
461
461
  self._chk_var(int, nbin.add_int, "sub_segment_num", 8)
462
462
  self._chk_var(int, nbin.add_int, "sub_segments_expected", 8)
463
463
  except:
464
- self.errors.append("Adding sub_segment_num and sub_segments_expected. setting to 0, 0")
464
+ self.errors.append(
465
+ "Adding sub_segment_num and sub_segments_expected. setting to 0, 0"
466
+ )
465
467
  nbin.add_int(0, 8)
466
468
  nbin.add_int(0, 8)
467
469
 
@@ -10,7 +10,7 @@ import os
10
10
  import sys
11
11
  import time
12
12
  from collections import deque
13
- from .m3ufu import M3uFu, TagParser, HEADER_TAGS
13
+ from .hlstags import TagParser, HEADER_TAGS
14
14
  from .segment import Segment
15
15
  from .cue import Cue
16
16
  from .new_reader import reader
@@ -1054,34 +1054,29 @@ def precheck():
1054
1054
  _chk_profile()
1055
1055
 
1056
1056
 
1057
- def _segments_to_playlist():
1058
- fumo = M3uFu()
1059
- fumo.m3u8 = sys.argv[1]
1060
- fumo.decode()
1061
- return [segment for segment in fumo.segments if "#EXT-X-STREAM-INF" in segment.tags]
1062
-
1063
-
1064
- def _mk_playlist(renditions):
1065
- playlist = False
1066
- if renditions:
1067
- playlist = _segments_to_playlist()
1068
- return playlist
1069
-
1070
-
1071
- def _mk_renditions(arg):
1072
- return [line for line in arg if b"#EXT-X-STREAM-INF" in line]
1073
-
1074
-
1075
- def _parse_renditions(arg):
1076
- return _mk_playlist(_mk_renditions(arg))
1057
+ def pick_one(lines, uri):
1058
+ """
1059
+ pick_one if lines come from a master.m3u8
1060
+ find the first rendition and make a uri or return uri.
1061
+ """
1062
+ for line in lines:
1063
+ if line.startswith(b"#EXT-X-STREAM-INF"):
1064
+ idx = lines.index(line) + 1
1065
+ line = lines[idx].decode("utf-8")
1066
+ base_url = uri.rsplit("/", 1)[0]
1067
+ uri = base_url + "/" + line
1068
+ uri.replace("\n", "")
1069
+ return uri
1077
1070
 
1078
1071
 
1079
1072
  def find_renditions():
1080
1073
  """
1081
1074
  find_renditions search master.m3u8 for playable renditions.
1082
1075
  """
1083
- with reader(sys.argv[1]) as arg:
1084
- return _parse_renditions(arg)
1076
+ uri = sys.argv[1]
1077
+ with reader(uri) as arg:
1078
+ lines = arg.readlines()
1079
+ return pick_one(lines, uri)
1085
1080
 
1086
1081
 
1087
1082
  def cli():
@@ -1098,17 +1093,11 @@ def cli():
1098
1093
 
1099
1094
  is all that's required.
1100
1095
  """
1101
- playlists = None
1102
- m3u8 = None
1103
1096
  precheck()
1104
- playlists = find_renditions()
1105
- if playlists:
1106
- m3u8 = playlists[0].media
1107
- else:
1108
- m3u8 = sys.argv[1]
1109
- cpulr = CuePuller()
1110
- cpulr.pull(m3u8)
1111
- print()
1097
+ playlist = find_renditions()
1098
+ if playlist:
1099
+ cpulr = CuePuller()
1100
+ cpulr.pull(playlist)
1112
1101
  sys.exit()
1113
1102
 
1114
1103
 
@@ -0,0 +1,171 @@
1
+ """
2
+ hlstags.py
3
+
4
+ """
5
+ from .stuff import atoif
6
+
7
+
8
+ BASIC_TAGS = (
9
+ "#EXTM3U",
10
+ "#EXT-X-VERSION",
11
+ "#EXT-X-ALLOW-CACHE",
12
+ )
13
+
14
+ MULTI_TAGS = (
15
+ "#EXT-X-INDEPENDENT-SEGMENTS",
16
+ "#EXT-X-START",
17
+ "#EXT-X-DEFINE",
18
+ )
19
+
20
+ MEDIA_TAGS = (
21
+ "#EXT-X-TARGETDURATION",
22
+ "#EXT-X-MEDIA-SEQUENCE",
23
+ "#EXT-X-DISCONTINUITY-SEQUENCE",
24
+ "#EXT-X-PLAYLIST-TYPE",
25
+ "#EXT-X-I-FRAMES-ONLY",
26
+ "#EXT-X-PART-INF",
27
+ "EXT-X-SERVER-CONTROL",
28
+ )
29
+
30
+ SEGMENT_TAGS = (
31
+ "#EXT-X-PUBLISHED-TIME",
32
+ "#EXT-X-PROGRAM-DATE-TIME",
33
+ )
34
+
35
+ HEADER_TAGS = BASIC_TAGS + MULTI_TAGS + MEDIA_TAGS # + SEGMENT_TAGS
36
+
37
+
38
+
39
+ class TagParser:
40
+ """
41
+ TagParser parses all HLS Tags as of the latest RFC.
42
+ Custom tags will also be parsed if possible.
43
+ Parsed tags are stored in the Dict TagParser.tags.
44
+ TagParser is used by the Segment class.
45
+
46
+
47
+ Example 1:
48
+
49
+ #EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=2030321,BANDWIDTH=2127786,CODECS="avc1.4D401F,mp4a.40.2",RESOLUTION=768x432,CLOSED-CAPTIONS="text"
50
+
51
+ TagParser.tags["#EXT-X-STREAM-INF"]= { "CLOSED-CAPTIONS": "text",
52
+ "RESOLUTION": "768x432",
53
+ "CODECS": "avc1.4D401F,mp4a.40.2",
54
+ "BANDWIDTH": 2127786,
55
+ "AVERAGE-BANDWIDTH": 2030321}
56
+ Example 2:
57
+
58
+ #EXT-X-CUE-OUT-CONT:ElapsedTime=21.000,Duration=30,SCTE35=/DAnAAAAAAAAAP/wBQb+AGb/MAARAg9DVUVJAAAAAn+HCQA0AALMua1L
59
+
60
+ TagParser.tags["#EXT-X-CUE-OUT-CONT"] = { "SCTE35": "/DAnAAAAAAAAAP/wBQb+AGb/MAARAg9DVUVJAAAAAn+HCQA0AALMua1L",
61
+ "Duration": 30,
62
+ "ElapsedTime": 21.0}
63
+ """
64
+
65
+ def __init__(self, lines=None):
66
+ self.tags = {}
67
+ for line in lines:
68
+ self._parse_tags(line)
69
+
70
+ @staticmethod
71
+ def _strip_last_comma(tail):
72
+ if tail.endswith(","):
73
+ tail = tail[:-1]
74
+ return tail
75
+
76
+ def _oated(self, tag, line):
77
+ vee = line.split(",", 1)[0]
78
+ self.tags[tag] = vee
79
+
80
+ def _parse_tags(self, line):
81
+ """
82
+ _parse_tags parses tags and
83
+ associated attributes
84
+ """
85
+ line = line.replace(" ", "")
86
+ if not line:
87
+ return
88
+ if line[0] != "#":
89
+ return
90
+ if ":" not in line:
91
+ self.tags[line] = None
92
+ return
93
+ tag, tail = line.split(":", 1)
94
+ self.tags[tag] = {}
95
+ if tag == "#EXT-OATCLS-SCTE35":
96
+ self._oated(tag, tail)
97
+ return
98
+ self._split_tail(tag, tail)
99
+
100
+ def _split_tail(self, tag, tail):
101
+ """
102
+ _split_tail splits key=value pairs from tail.
103
+ """
104
+ while tail:
105
+ tail = self._strip_last_comma(tail)
106
+ if "=" not in tail:
107
+ self.tags[tag] = atoif(tail)
108
+ return
109
+ tail, value = self._split_value(tag, tail)
110
+ tail = self._split_key(tail, tag, value)
111
+ return
112
+
113
+ def _split_key(self, tail, tag, value):
114
+ """
115
+ _split_key splits off the last attribute key
116
+ """
117
+ if not tail:
118
+ return
119
+ splitup = tail.rsplit(",", 1)
120
+ if len(splitup) == 2:
121
+ tail, key = splitup
122
+ else:
123
+ key = splitup[0]
124
+ tail = None
125
+ if "=" in key:
126
+ key, value = key.split("=", 1)
127
+ self.tags[tag][key] = value
128
+ return tail
129
+
130
+ def _split_value(self, tag, tail):
131
+ """
132
+ _split_value does a right split
133
+ off tail for the value in a key=value pair.
134
+ """
135
+ if tail[-1:] == '"':
136
+ tail, value = self._quoted(tag, tail)
137
+ else:
138
+ tail, value = self._unquoted(tag, tail)
139
+ return tail, value
140
+
141
+ def _quoted(self, tag, tail):
142
+ """
143
+ _quoted handles quoted attributes
144
+ """
145
+ value = None
146
+ try:
147
+ tail, value = tail[:-1].rsplit('="', 1)
148
+ except:
149
+ self.tags[tag]
150
+ value = tail.replace('"', "")
151
+ tail = None
152
+ return tail, value
153
+
154
+ def _unquoted(self, tag, tail):
155
+ """
156
+ _unquoted handles unquoted attributes
157
+ """
158
+ value = None
159
+ hold = ""
160
+ # = is only allowed as a suffix in base64
161
+ while tail.endswith("="):
162
+ hold += tail[-1]
163
+ tail = tail[:-1]
164
+ try:
165
+ tail, value = tail.rsplit("=", 1)
166
+ value += hold
167
+ value = atoif(value)
168
+ except:
169
+ tail = None
170
+ return tail, value
171
+
@@ -6,7 +6,7 @@ threefive3.iframes
6
6
  import sys
7
7
  from functools import partial
8
8
  from .new_reader import reader
9
- from .spare import print2
9
+ from .stuff import print2
10
10
 
11
11
 
12
12
  PKT_SIZE = 188
@@ -6,7 +6,7 @@ import io
6
6
  import sys
7
7
  from .crc import crc32
8
8
  from .bitn import NBin
9
- from .spare import print2
9
+ from .stuff import print2
10
10
  from .stream import Stream
11
11
 
12
12
  fixme = []
@@ -45,8 +45,8 @@ class SixFix(Stream):
45
45
 
46
46
  def __init__(self, tsdata=None):
47
47
  super().__init__(tsdata)
48
- self.pmt_payloads = {}
49
- self.pid_prog={}
48
+ self.pmt_pays = {}
49
+ self.pid_prog = {}
50
50
  self.con_pids = set()
51
51
  self.out_file = "sixfixed-" + tsdata.rsplit("/")[-1]
52
52
  self.in_file = sys.stdin.buffer
@@ -55,9 +55,9 @@ class SixFix(Stream):
55
55
  if pid in self.pids.tables:
56
56
  self._parse_tables(pkt, pid)
57
57
  if pid in self.pids.pmt:
58
- prgm=self.pid2prgm(pid)
59
- if prgm in self.pmt_payloads:
60
- pkt = pkt[:4] + self.pmt_payloads[prgm]
58
+ prgm = self.pid2prgm(pid)
59
+ if prgm in self.pmt_pays:
60
+ pkt = pkt[:4] + self.pmt_pays[prgm]
61
61
  return pkt
62
62
 
63
63
  def _parse_pkts(self, out_file):
@@ -84,7 +84,9 @@ class SixFix(Stream):
84
84
  with open(self.out_file, "wb") as out_file:
85
85
  self._parse_pkts(out_file)
86
86
 
87
- def _regen_pmt(self,prgm, n_seclen, pcr_pid, n_proginfolen, n_info_bites, n_streams):
87
+ def _regen_pmt(
88
+ self, prgm, n_seclen, pcr_pid, n_proginfolen, n_info_bites, n_streams
89
+ ):
88
90
  nbin = NBin()
89
91
  nbin.add_int(2, 8) # 0x02
90
92
  nbin.add_int(1, 1) # section Syntax indicator
@@ -106,11 +108,11 @@ class SixFix(Stream):
106
108
  a_crc = crc32(nbin.bites)
107
109
  nbin.add_int(a_crc, 32)
108
110
  pointer_field = b"\x00"
109
- n_payload = pointer_field +nbin.bites
110
- pad =184 -len(n_payload)
111
+ n_payload = pointer_field + nbin.bites
112
+ pad = 184 - len(n_payload)
111
113
  if pad > 0:
112
114
  n_payload = n_payload + (b"\xff" * pad)
113
- self.pmt_payloads[prgm] = n_payload
115
+ self.pmt_pays[prgm] = n_payload
114
116
 
115
117
  def _chk_payload(self, pay, pid):
116
118
  pay = self._chk_partial(pay, pid, self._PMT_TID)
@@ -149,7 +151,9 @@ class SixFix(Stream):
149
151
  si_len = seclen - 9
150
152
  si_len -= proginfolen
151
153
  n_streams = self._parse_program_streams(si_len, pay, idx, program_number)
152
- self._regen_pmt(program_number,n_seclen, pcr_pid, n_proginfolen, n_info_bites, n_streams)
154
+ self._regen_pmt(
155
+ program_number, n_seclen, pcr_pid, n_proginfolen, n_info_bites, n_streams
156
+ )
153
157
  return True
154
158
 
155
159
  def _parse_program_streams(self, si_len, pay, idx, program_number):
@@ -6,7 +6,7 @@ import sys
6
6
 
7
7
  from functools import partial
8
8
  from .new_reader import reader
9
- from .spare import print2
9
+ from .stuff import print2
10
10
  from .cue import Cue
11
11
  from .packetdata import PacketData
12
12
  from .streamtypes import streamtype_map
@@ -161,6 +161,8 @@ class Stream:
161
161
  self.pids = Pids()
162
162
  self.maps = Maps()
163
163
  self.iframer = IFramer(shush=True)
164
+ self.pmt_payloads = set()
165
+ self.pmt_count = 0
164
166
 
165
167
  def __repr__(self):
166
168
  return str(self.__dict__)
@@ -261,7 +263,7 @@ class Stream:
261
263
  func can be set to a custom function that accepts
262
264
  a threefive3.Cue instance as it's only argument.
263
265
  """
264
- num_pkts = 112
266
+ num_pkts = 1400
265
267
  for chunk in self.iter_pkts(num_pkts=num_pkts):
266
268
  self._decode2cues(chunk, func)
267
269
  return False
@@ -316,13 +318,15 @@ class Stream:
316
318
  self.info = True
317
319
  for pkt in self.iter_pkts():
318
320
  self._parse(pkt)
321
+ if self.pmt_count > 20:
322
+ break
319
323
  if self.maps.prgm.keys():
320
324
  sopro = sorted(self.maps.prgm.items())
321
325
  for k, vee in sopro:
322
326
  # if len(vee.streams.items()) > 0:
323
327
  print2(f"\nProgram: {k}")
324
328
  vee.show()
325
- return True
329
+ return True
326
330
 
327
331
  def show_pts(self):
328
332
  """
@@ -376,11 +380,6 @@ class Stream:
376
380
  return self.as_90k(self.maps.prgm_pcr[prgm])
377
381
  return False
378
382
 
379
- def _unpad_afc(self, pkt):
380
- if self._afc_flag(pkt[3]):
381
- pkt = pkt[:4] + self._unpad(pkt[4:])
382
- return pkt
383
-
384
383
  def _unpad(self, bites):
385
384
  pad = 255
386
385
  one = 1
@@ -388,7 +387,7 @@ class Stream:
388
387
  return b""
389
388
  while bites[0] == pad:
390
389
  bites = bites[1:]
391
- return self._unpad2(bites)
390
+ return self._unpad2(bites)
392
391
 
393
392
  def _unpad2(self, bites):
394
393
  pad = 255
@@ -441,20 +440,25 @@ class Stream:
441
440
  """
442
441
  head_size = 4
443
442
  if self._afc_flag(pkt[3]):
444
- pkt = self._unpad_afc(pkt)
443
+ pkt=pkt[:4] + self._unpad(pkt[4:])
445
444
  afl = pkt[4]
446
445
  head_size += afl + 1 # +1 for afl byte
447
446
  return pkt[head_size:]
448
447
 
449
448
  def _pmt_pid(self, pay, pid):
450
449
  if pid in self.pids.pmt:
450
+ self.pmt_count += 1
451
+ if pay in self.pmt_payloads:
452
+ if self.pmt_count > 3:
453
+ return
454
+ self.pmt_payloads.add(pay)
451
455
  self._parse_pmt(pay, pid)
452
456
 
453
457
  def _pat_pid(self, pay, pid):
454
458
  if pid == self.pids.PAT_PID:
455
459
  self._parse_pat(pay)
456
460
 
457
- def _sdt_pid(self,pay,pid):
461
+ def _sdt_pid(self, pay, pid):
458
462
  if pid == self.pids.SDT_PID:
459
463
  self._parse_sdt(pay)
460
464
 
@@ -465,8 +469,8 @@ class Stream:
465
469
  based on pid of the pkt
466
470
  """
467
471
  pay = self._parse_payload(pkt)
472
+ self._pmt_pid(pay, pid)
468
473
  if not self._same_as_last(pay, pid):
469
- self._pmt_pid(pay,pid)
470
474
  self._pat_pid(pay, pid)
471
475
  self._sdt_pid(pay, pid)
472
476
 
@@ -497,15 +501,15 @@ class Stream:
497
501
  def _parse(self, pkt):
498
502
  pid = self._parse_info(pkt)
499
503
  if pid in self.pids.pcr:
500
- self._chk_pcr(pkt, pid)
501
- self._chk_pts(pkt, pid)
504
+ # self._chk_pcr(pkt, pid)
505
+ self._chk_pts(pkt, pid)
502
506
  return self._chk_scte35(pkt, pid)
503
507
 
504
508
  def _pid_has_scte35(self, pid):
505
- # return pid in self.pids.scte35.union(self.pids.maybe_scte35) # 4 Slowest. (union sucks)
506
- # return (pid in self.pids.scte35 or pid in self.pids.maybe_scte35) #2 Fast
507
- return pid in (self.pids.scte35 or self.pids.maybe_scte35) # 1 Fastest
508
- # return pid in (self.pids.scte35|self.pids.maybe_scte35) #3 Slow. (I thought this would be fastest)
509
+ # return pid in self.pids.scte35.union(self.pids.maybe_scte35) # union sucks. 4.47 secs
510
+ # return (pid in self.pids.scte35 or pid in self.pids.maybe_scte35) # 3.37 secs
511
+ return pid in (self.pids.scte35 or self.pids.maybe_scte35) # 3.326 secs
512
+ # return pid in (self.pids.scte35|self.pids.maybe_scte35) # wtf? 4.128 secs
509
513
 
510
514
  def _chk_partial(self, pay, pid, sep):
511
515
  if pid in self.maps.partial: