threefive3 3.0.15__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.15/threefive3.egg-info → threefive3-3.0.17}/PKG-INFO +12 -6
  2. {threefive3-3.0.15 → threefive3-3.0.17}/README.md +11 -5
  3. {threefive3-3.0.15 → threefive3-3.0.17}/setup.py +0 -2
  4. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/__init__.py +19 -1
  5. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/base.py +16 -12
  6. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/bitn.py +5 -5
  7. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/commands.py +4 -3
  8. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/cue.py +36 -9
  9. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/descriptors.py +13 -7
  10. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/hls.py +28 -39
  11. threefive3-3.0.17/threefive3/hlstags.py +171 -0
  12. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/iframes.py +1 -1
  13. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/section.py +15 -14
  14. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/sixfix.py +15 -11
  15. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/stream.py +22 -18
  16. threefive3-3.0.17/threefive3/stuff.py +26 -0
  17. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/upids.py +7 -6
  18. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/version.py +1 -1
  19. {threefive3-3.0.15 → threefive3-3.0.17/threefive3.egg-info}/PKG-INFO +12 -6
  20. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3.egg-info/SOURCES.txt +2 -1
  21. threefive3-3.0.17/threefive3.egg-info/requires.txt +1 -0
  22. threefive3-3.0.15/threefive3/spare.py +0 -12
  23. threefive3-3.0.15/threefive3.egg-info/requires.txt +0 -3
  24. {threefive3-3.0.15 → threefive3-3.0.17}/LICENSE +0 -0
  25. {threefive3-3.0.15 → threefive3-3.0.17}/bin/threefive3 +0 -0
  26. {threefive3-3.0.15 → threefive3-3.0.17}/setup.cfg +0 -0
  27. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/crc.py +0 -0
  28. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/new_reader.py +0 -0
  29. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/packetdata.py +0 -0
  30. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/segment.py +0 -0
  31. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/segmentation.py +0 -0
  32. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/streamtypes.py +0 -0
  33. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/sxp.py +0 -0
  34. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/x2c.py +0 -0
  35. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3/xml.py +0 -0
  36. {threefive3-3.0.15 → threefive3-3.0.17}/threefive3.egg-info/dependency_links.txt +0 -0
  37. {threefive3-3.0.15 → 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.15
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
@@ -19,9 +19,6 @@ Requires-Python: >=3.6
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
 
22
- [Install](#install) |[SCTE-35 Cli](#the-cli-tool) |[SCTE-35 Xml ](https://github.com/superkabuki/threefive3/blob/main/xml.md) | [Cue Class](https://github.com/superkabuki/threefive3/blob/main/cue.md) | [Stream Class](https://github.com/superkabuki/threefive3/blob/main/stream.md) | [Online SCTE-35 Parser](https://iodisco.com/scte35) | [Encode SCTE-35](https://github.com/superkabuki/threefive3/blob/main/encode.md) [FFmpeg SCTE35](https://github.com/superkabuki/FFmpeg_SCTE35)
23
-
24
-
25
22
  # threefive3 SCTE-35 cli tool and python3 library.
26
23
 
27
24
  ✅ SCTE-35 Parser ✅ SCTE-35 Encoder ✅ SCTE-35 HLS ✅ SCTE-35 Xml ✅ SCTE-35 Cli ✅ SCTE-35 library
@@ -32,6 +29,14 @@ License-File: LICENSE
32
29
  * Automatic AES decryption for HLS.
33
30
  * All HLS SCTE-35 Tags are Supported
34
31
  ___
32
+ * [Install](#install)
33
+ * [SCTE-35 Cli](#the-cli-tool)
34
+ * [SCTE-35 Xml ](https://github.com/superkabuki/threefive3/blob/main/xml.md)
35
+ * [Cue Class](https://github.com/superkabuki/threefive3/blob/main/cue.md)
36
+ * [Stream Class](https://github.com/superkabuki/threefive3/blob/main/stream.md)
37
+ * [Online SCTE-35 Parser](https://iodisco.com/scte35)
38
+ * [Encode SCTE-35](https://github.com/superkabuki/threefive3/blob/main/encode.md)
39
+ * [FFmpeg SCTE35](https://github.com/superkabuki/FFmpeg_SCTE35)
35
40
 
36
41
  ## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
37
42
 
@@ -41,7 +46,7 @@ Python 3.9.16 (7.3.11+dfsg-2+deb12u3, Dec 30 2024, 22:36:23)
41
46
  [PyPy 7.3.11 with GCC 12.2.0] on linux
42
47
  Type "help", "copyright", "credits" or "license" for more information.
43
48
 
44
- >>>> from threefive import Stream
49
+ >>>> from threefive3 import Stream
45
50
 
46
51
  >>>> strm=Stream('https://futzu.com/xaa.ts')
47
52
 
@@ -63,11 +68,12 @@ pypy3 -mpip install threefive3
63
68
  * from the git repo
64
69
  ```rebol
65
70
  git clone https://github.com/superkabuki/scte35.git
66
- cd scte35
71
+ cd threefive3
67
72
  make install
68
73
  ```
69
74
  ___
70
75
 
76
+
71
77
  # `The Cli tool`
72
78
 
73
79
 
@@ -1,6 +1,3 @@
1
- [Install](#install) |[SCTE-35 Cli](#the-cli-tool) |[SCTE-35 Xml ](https://github.com/superkabuki/threefive3/blob/main/xml.md) | [Cue Class](https://github.com/superkabuki/threefive3/blob/main/cue.md) | [Stream Class](https://github.com/superkabuki/threefive3/blob/main/stream.md) | [Online SCTE-35 Parser](https://iodisco.com/scte35) | [Encode SCTE-35](https://github.com/superkabuki/threefive3/blob/main/encode.md) [FFmpeg SCTE35](https://github.com/superkabuki/FFmpeg_SCTE35)
2
-
3
-
4
1
  # threefive3 SCTE-35 cli tool and python3 library.
5
2
 
6
3
  ✅ SCTE-35 Parser ✅ SCTE-35 Encoder ✅ SCTE-35 HLS ✅ SCTE-35 Xml ✅ SCTE-35 Cli ✅ SCTE-35 library
@@ -11,6 +8,14 @@
11
8
  * Automatic AES decryption for HLS.
12
9
  * All HLS SCTE-35 Tags are Supported
13
10
  ___
11
+ * [Install](#install)
12
+ * [SCTE-35 Cli](#the-cli-tool)
13
+ * [SCTE-35 Xml ](https://github.com/superkabuki/threefive3/blob/main/xml.md)
14
+ * [Cue Class](https://github.com/superkabuki/threefive3/blob/main/cue.md)
15
+ * [Stream Class](https://github.com/superkabuki/threefive3/blob/main/stream.md)
16
+ * [Online SCTE-35 Parser](https://iodisco.com/scte35)
17
+ * [Encode SCTE-35](https://github.com/superkabuki/threefive3/blob/main/encode.md)
18
+ * [FFmpeg SCTE35](https://github.com/superkabuki/FFmpeg_SCTE35)
14
19
 
15
20
  ## MPEGTS streams can be parsed for SCTE-35 with three lines of code.
16
21
 
@@ -20,7 +25,7 @@ Python 3.9.16 (7.3.11+dfsg-2+deb12u3, Dec 30 2024, 22:36:23)
20
25
  [PyPy 7.3.11 with GCC 12.2.0] on linux
21
26
  Type "help", "copyright", "credits" or "license" for more information.
22
27
 
23
- >>>> from threefive import Stream
28
+ >>>> from threefive3 import Stream
24
29
 
25
30
  >>>> strm=Stream('https://futzu.com/xaa.ts')
26
31
 
@@ -42,11 +47,12 @@ pypy3 -mpip install threefive3
42
47
  * from the git repo
43
48
  ```rebol
44
49
  git clone https://github.com/superkabuki/scte35.git
45
- cd scte35
50
+ cd threefive3
46
51
  make install
47
52
  ```
48
53
  ___
49
54
 
55
+
50
56
  # `The Cli tool`
51
57
 
52
58
 
@@ -18,8 +18,6 @@ setuptools.setup(
18
18
  long_description_content_type="text/markdown",
19
19
  url="https://github.com/superkabuki/scte35",
20
20
  install_requires=[
21
- 'm3ufu >= 0.0.89',
22
- 'sideways >= 0.0.23',
23
21
  "pyaes",
24
22
  ],
25
23
 
@@ -2,26 +2,44 @@
2
2
  scte35.__init__.py
3
3
  """
4
4
 
5
- from .spare import print2
5
+
6
6
  from .cue import Cue
7
7
  from .section import SpliceInfoSection
8
8
  from .segment import Segment
9
9
  from .stream import Stream
10
+ from .stuff import print2
10
11
  from .version import version
11
12
 
12
13
  from .commands import (
14
+ SpliceCommand,
13
15
  TimeSignal,
14
16
  SpliceInsert,
15
17
  SpliceNull,
16
18
  PrivateCommand,
17
19
  BandwidthReservation,
20
+ command_map,
18
21
  )
19
22
 
20
23
  from .descriptors import (
24
+ k_by_v,
21
25
  AvailDescriptor,
22
26
  DVBDASDescriptor,
23
27
  DtmfDescriptor,
24
28
  SegmentationDescriptor,
25
29
  SpliceDescriptor,
26
30
  TimeDescriptor,
31
+ descriptor_map,
32
+ )
33
+
34
+ from .upids import (
35
+ Upid,
36
+ NoUpid,
37
+ AirId,
38
+ Atsc,
39
+ Eidr,
40
+ Isan,
41
+ Mid,
42
+ Mpu,
43
+ Umid,
44
+ upid_map,
27
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
 
@@ -17,6 +17,9 @@ class SCTE35Base:
17
17
 
18
18
  ROLLOVER = 8589934591
19
19
 
20
+ def __init__(self):
21
+ self.errors = []
22
+
20
23
  def __repr__(self):
21
24
  return str(self.__dict__)
22
25
 
@@ -27,8 +30,9 @@ class SCTE35Base:
27
30
  return nbin
28
31
 
29
32
  def _err2(self, var_name, var_value, bit_count, var_type):
30
- err_mesg = f"\033[1;41m !! \033[0m \033[1;41m {var_name}\033[0m is \033[1;41m {var_value} \033[0m, it should be type {var_type}, {bit_count} bit(s) long.\n "
31
- print2(err_mesg)
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."
35
+ self.errors.append(err_mesg)
32
36
 
33
37
  def _bool_int(self, var_name, var_value, bit_count, var_type):
34
38
  if var_type == int:
@@ -104,14 +108,6 @@ class SCTE35Base:
104
108
  """
105
109
  if hasattr(self, what):
106
110
  return vars(self)[what]
107
- return False
108
-
109
- def hasis(self, what):
110
- """
111
- hasis obj "has" a what and what "is" returned.
112
- """
113
- if self.has(what):
114
- return vars(self)[what]
115
111
  return None
116
112
 
117
113
  @staticmethod
@@ -150,7 +146,15 @@ class SCTE35Base:
150
146
  val = list(val)
151
147
  return val
152
148
 
153
- return {k: b2l(v) for k, v in vars(self).items() if v is not None}
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 []
154
158
 
155
159
  def _json2dict(self, gonzo):
156
160
  if isinstance(gonzo, str):
@@ -1,11 +1,11 @@
1
1
  """
2
- The bitn.BitBin and bitn.NBin classes
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
- class BitBin:
8
+ class Bitn:
9
9
  """
10
10
  bitn.Bitbin takes a byte string and
11
11
  converts it to a integer, a very large integer
@@ -19,7 +19,7 @@ class BitBin:
19
19
  self.bits = int.from_bytes(bites, byteorder="big")
20
20
 
21
21
  def __repr__(self):
22
- return str(vars(self))
22
+ return str(vars(self))
23
23
 
24
24
  def as_90k(self, num_bits):
25
25
  """
@@ -96,7 +96,7 @@ class BitBin:
96
96
  class NBin:
97
97
  """
98
98
  bitn.NBin is
99
- the reverse BitBin.
99
+ the reverse Bitn.
100
100
  Encodes data to integers
101
101
  and then bytes
102
102
  """
@@ -2,7 +2,7 @@
2
2
  SCTE35 Splice Commands
3
3
  """
4
4
 
5
- from .bitn import BitBin
5
+ from .bitn import Bitn
6
6
  from .base import SCTE35Base
7
7
  from .xml import Node
8
8
 
@@ -13,6 +13,7 @@ class SpliceCommand(SCTE35Base):
13
13
  """
14
14
 
15
15
  def __init__(self, bites=None):
16
+ super().__init__()
16
17
  self.command_length = 0
17
18
  self.command_type = None
18
19
  self.name = None
@@ -130,7 +131,7 @@ class TimeSignal(SpliceCommand):
130
131
  """
131
132
  TimeSignal.decode method
132
133
  """
133
- bitbin = BitBin(self.bites)
134
+ bitbin = Bitn(self.bites)
134
135
  start = bitbin.idx
135
136
  self._splice_time(bitbin)
136
137
  self._set_len(start, bitbin.idx)
@@ -224,7 +225,7 @@ class SpliceInsert(TimeSignal):
224
225
  """
225
226
  decode SpliceInsert
226
227
  """
227
- bitbin = BitBin(self.bites)
228
+ bitbin = Bitn(self.bites)
228
229
  start = bitbin.idx
229
230
  self.splice_event_id = bitbin.as_int(32)
230
231
  self.splice_event_cancel_indicator = bitbin.as_flag(1)
@@ -4,11 +4,11 @@ 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
11
- from .commands import command_map
11
+ from .commands import command_map, SpliceCommand
12
12
  from .descriptors import splice_descriptor, descriptor_map
13
13
  from .crc import crc32
14
14
  from .xml import Node
@@ -47,18 +47,33 @@ 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
51
  self.command = None
51
52
  self.descriptors = []
52
53
  self.info_section = SpliceInfoSection()
53
54
  self.bites = None
54
55
  if data:
55
56
  self.bites = self._mk_bits(data)
57
+ self.decode()
56
58
  self.packet_data = packet_data
57
59
  self.dash_data = None
60
+ self.decode()
58
61
 
59
62
  def __repr__(self):
60
63
  return str(self.__dict__)
61
64
 
65
+ def errs(self):
66
+ """
67
+ errs show encoding errors.
68
+ """
69
+ e = {"cue.errors": self.errors}
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
74
+ e["descriptor_errors"] = [d.errors for d in self.descriptors]
75
+ return e
76
+
62
77
  def decode(self):
63
78
  """
64
79
  Cue.decode() parses for SCTE35 data
@@ -116,6 +131,7 @@ class Cue(SCTE35Base):
116
131
  scte35_data = self._get_dash_data(scte35_data)
117
132
  scte35_data = self._get_packet_data(scte35_data)
118
133
  return scte35_data
134
+ self.errors.append("command or info section not found")
119
135
  return False
120
136
 
121
137
  def get_descriptors(self):
@@ -131,11 +147,12 @@ class Cue(SCTE35Base):
131
147
  """
132
148
  return self.bites
133
149
 
134
- @staticmethod
135
- def fix_bad_b64(data):
150
+ def fix_bad_b64(self, data):
136
151
  """
137
152
  fix_bad_b64 fixes bad padding on Base64
138
153
  """
154
+ if len(data) % 4 != 0:
155
+ self.errors.append("fixed bad base64 length ")
139
156
  while len(data) % 4 != 0:
140
157
  data = data + "="
141
158
  return data
@@ -238,12 +255,12 @@ class Cue(SCTE35Base):
238
255
  """
239
256
  sct = self.info_section.splice_command_type
240
257
  if sct not in command_map:
258
+ self.errors.append(f"Splice Command type {sct} not recognized")
241
259
  return False
242
260
  iscl = self.info_section.splice_command_length
243
261
  cmd_bites = bites[:iscl]
244
262
  self.command = command_map[sct](cmd_bites)
245
263
  self.command.command_length = iscl
246
-
247
264
  self.command.decode()
248
265
  del self.command.bites
249
266
  return bites[iscl:]
@@ -251,9 +268,13 @@ class Cue(SCTE35Base):
251
268
  # encode related
252
269
 
253
270
  def _assemble(self):
271
+ for d in self.descriptors:
272
+ d.errors = []
254
273
  dscptr_bites = self._unloop_descriptors()
255
274
  dll = len(dscptr_bites)
256
275
  self.info_section.descriptor_loop_length = dll
276
+ self.info_section.errors = []
277
+ self.command.errors = []
257
278
  cmd_bites = self.command.encode()
258
279
  cmdl = self.command.command_length = len(cmd_bites)
259
280
  self.info_section.splice_command_length = cmdl
@@ -277,6 +298,7 @@ class Cue(SCTE35Base):
277
298
  self._assemble()
278
299
  self._encode_crc()
279
300
  return b64encode(self.bites).decode()
301
+ self._no_cmd()
280
302
  return False
281
303
 
282
304
  def encode(self):
@@ -366,7 +388,9 @@ class Cue(SCTE35Base):
366
388
  """
367
389
  _no_cmd raises an exception if no splice command.
368
390
  """
369
- raise Exception("\033[7mA splice command is required\033[27m")
391
+ self.errors.append("A splice command is required")
392
+
393
+ # raise Exception("\033[7mA splice command is required\033[27m")
370
394
 
371
395
  def load(self, gonzo):
372
396
  """
@@ -424,9 +448,12 @@ class Cue(SCTE35Base):
424
448
  _mk_descriptor_xml make xml nodes for descriptors.
425
449
  """
426
450
  for d in self.descriptors:
427
- if d.has("segmentation_type_id") and d.segmentation_type_id in table22:
428
- comment = f"{table22[d.segmentation_type_id]}"
429
- sis.add_comment(comment)
451
+ if d.has("segmentation_type_id"):
452
+ if d.segmentation_type_id in table22:
453
+ comment = f"{table22[d.segmentation_type_id]}"
454
+ sis.add_comment(comment)
455
+ else:
456
+ d.errors.append("Segmentation type id not in table 22")
430
457
  sis.add_child(d.xml(ns=ns))
431
458
  return sis
432
459
 
@@ -2,7 +2,7 @@
2
2
  SCTE35 Splice Descriptors
3
3
  """
4
4
 
5
- from .bitn import BitBin
5
+ 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
@@ -25,7 +25,7 @@ class SpliceDescriptor(SCTE35Base):
25
25
  """
26
26
 
27
27
  def __init__(self, bites=None):
28
-
28
+ super().__init__()
29
29
  self.tag = None
30
30
  self.identifier = "CUEI"
31
31
  self.name = None
@@ -110,7 +110,7 @@ class DVBDASDescriptor(SpliceDescriptor):
110
110
  """
111
111
  Decode DVB DAS Descriptor
112
112
  """
113
- bitbin = BitBin(self.bites)
113
+ bitbin = Bitn(self.bites)
114
114
  self.break_num = bitbin.as_int(8)
115
115
  self.breaks_expected = bitbin.as_int(8)
116
116
  bitbin.forward(4)
@@ -152,7 +152,7 @@ class AvailDescriptor(SpliceDescriptor):
152
152
  """
153
153
  decode SCTE35 Avail Descriptor
154
154
  """
155
- bitbin = BitBin(self.bites)
155
+ bitbin = Bitn(self.bites)
156
156
  self.provider_avail_id = bitbin.as_int(32)
157
157
 
158
158
  def encode(self, nbin=None):
@@ -251,7 +251,7 @@ class TimeDescriptor(SpliceDescriptor):
251
251
  """
252
252
  decode SCTE35 Time Descriptor
253
253
  """
254
- bitbin = BitBin(self.bites)
254
+ bitbin = Bitn(self.bites)
255
255
  self.tai_seconds = bitbin.as_int(48)
256
256
  self.tai_ns = bitbin.as_int(32)
257
257
  self.utc_offset = bitbin.as_int(16)
@@ -328,7 +328,7 @@ class SegmentationDescriptor(SpliceDescriptor):
328
328
  """
329
329
  decode a segmentation descriptor
330
330
  """
331
- bitbin = BitBin(self.bites)
331
+ bitbin = Bitn(self.bites)
332
332
  self.segmentation_event_id = bitbin.as_hex(32)
333
333
  self.segmentation_event_cancel_indicator = bitbin.as_flag(1)
334
334
  self.segmentation_event_id_compliance_indicator = bitbin.as_flag(1)
@@ -421,6 +421,7 @@ class SegmentationDescriptor(SpliceDescriptor):
421
421
  """
422
422
  upid_type = self.segmentation_upid_type
423
423
  if upid_type not in upid_map:
424
+ self.errors.append("Unknown upid type , setting to 0xFD")
424
425
  upid_type = 0xFD
425
426
  the_upid = upid_map[upid_type][1](
426
427
  bitbin, upid_type, self.segmentation_upid_length
@@ -435,6 +436,7 @@ class SegmentationDescriptor(SpliceDescriptor):
435
436
  upid_type = self.segmentation_upid_type
436
437
  if upid_type not in upid_map:
437
438
  upid_type = 0xFD
439
+ self.errors.append("Unknown upid type , setting to 0xFD")
438
440
  the_upid = upid_map[upid_type][1](
439
441
  None, upid_type, self.segmentation_upid_length
440
442
  )
@@ -459,6 +461,9 @@ class SegmentationDescriptor(SpliceDescriptor):
459
461
  self._chk_var(int, nbin.add_int, "sub_segment_num", 8)
460
462
  self._chk_var(int, nbin.add_int, "sub_segments_expected", 8)
461
463
  except:
464
+ self.errors.append(
465
+ "Adding sub_segment_num and sub_segments_expected. setting to 0, 0"
466
+ )
462
467
  nbin.add_int(0, 8)
463
468
  nbin.add_int(0, 8)
464
469
 
@@ -524,7 +529,7 @@ class SegmentationDescriptor(SpliceDescriptor):
524
529
  bites = bytes.fromhex(seg_upid)
525
530
  except ValueError:
526
531
  bites = seg_upid.encode()
527
- bitbin = BitBin(bites)
532
+ bitbin = Bitn(bites)
528
533
  self.segmentation_upid_length = len(bites)
529
534
  the_upid = self.mk_the_upid(bitbin=bitbin)
530
535
  self.segmentation_upid_type_name, self.segmentation_upid = the_upid.decode()
@@ -550,5 +555,6 @@ def splice_descriptor(bites):
550
555
  spliced = descriptor_map[tag](bites)
551
556
  else:
552
557
  spliced = SpliceDescriptor(bites)
558
+ spliced.errors.append(f"tag not in descriptor map. 0,1,2,3, 240 are valid tags")
553
559
  spliced.decode()
554
560
  return spliced
@@ -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
@@ -153,9 +153,9 @@ class Scte35Profile:
153
153
 
154
154
  @staticmethod
155
155
  def _clean(line):
156
- '''
156
+ """
157
157
  remove whitespace and quotes
158
- '''
158
+ """
159
159
  translate_map = {34: 94, 10: 94, 9: 94, 32: 94, 39: 94}
160
160
  return line.translate(translate_map).replace("^", "")
161
161
 
@@ -230,7 +230,7 @@ class Scte35Profile:
230
230
 
231
231
  def _chk_pts(self, cue):
232
232
  pts = None
233
- if cue.command.hasis("pts_time"):
233
+ if cue.command.has("pts_time"):
234
234
  pts = self.set_pts(cue)
235
235
  return pts
236
236
 
@@ -265,7 +265,7 @@ class Scte35Profile:
265
265
  def _is_splice_insert_cueout(self, cue):
266
266
  line = None
267
267
  if cue.command.out_of_network_indicator:
268
- if cue.command.hasis("break_duration"):
268
+ if cue.command.has("break_duration"):
269
269
  duration = cue.command.break_duration
270
270
  line = f"#EXT-X-CUE-OUT:{duration}\n"
271
271
  return line
@@ -282,7 +282,7 @@ class Scte35Profile:
282
282
  def _is_dscptr_cueout(self, dscptr, line):
283
283
  if dscptr.segmentation_type_id in self.starts:
284
284
  self.seg_type = dscptr.segmentation_type_id + 1
285
- if dscptr.hasis("segmentation_duration"):
285
+ if dscptr.has("segmentation_duration"):
286
286
  duration = dscptr.segmentation_duration
287
287
  line = f"#EXT-X-CUE-OUT:{duration}\n"
288
288
  return line
@@ -808,7 +808,7 @@ class CuePuller:
808
808
  found in a segment.
809
809
  """
810
810
  for cue in seg.cues:
811
- if cue.hasis("packet_data"):
811
+ if cue.has("packet_data"):
812
812
  self.pts = cue.packet_data.pts
813
813
  if cue.encode() != self.last_cue:
814
814
  self.last_cue = cue.encode()
@@ -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