tocparser 0.1.0__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.
- tocparser-0.1.0/LICENSE.txt +201 -0
- tocparser-0.1.0/PKG-INFO +205 -0
- tocparser-0.1.0/README.md +177 -0
- tocparser-0.1.0/pyproject.toml +119 -0
- tocparser-0.1.0/pyproject.toml.orig +116 -0
- tocparser-0.1.0/src/tocparser/__init__.py +88 -0
- tocparser-0.1.0/src/tocparser/errors.py +80 -0
- tocparser-0.1.0/src/tocparser/grammar.lark +89 -0
- tocparser-0.1.0/src/tocparser/models.py +739 -0
- tocparser-0.1.0/src/tocparser/parser.py +695 -0
- tocparser-0.1.0/src/tocparser/py.typed +0 -0
- tocparser-0.1.0/src/tocparser/serializer.py +243 -0
- tocparser-0.1.0/src/tocparser/times.py +92 -0
- tocparser-0.1.0/tests/__init__.py +0 -0
- tocparser-0.1.0/tests/conftest.py +46 -0
- tocparser-0.1.0/tests/corpus/00001.toc +10 -0
- tocparser-0.1.0/tests/corpus/00002.toc +562 -0
- tocparser-0.1.0/tests/corpus/00003.toc +58 -0
- tocparser-0.1.0/tests/corpus/00004.toc +50 -0
- tocparser-0.1.0/tests/corpus/00005.toc +66 -0
- tocparser-0.1.0/tests/corpus/00006.toc +67 -0
- tocparser-0.1.0/tests/corpus/00007.toc +92 -0
- tocparser-0.1.0/tests/corpus/00008.toc +10 -0
- tocparser-0.1.0/tests/corpus/00009.toc +51 -0
- tocparser-0.1.0/tests/corpus/00010.toc +148 -0
- tocparser-0.1.0/tests/corpus/00011.toc +92 -0
- tocparser-0.1.0/tests/corpus/00012.toc +100 -0
- tocparser-0.1.0/tests/corpus/00013.toc +123 -0
- tocparser-0.1.0/tests/corpus/00014.toc +110 -0
- tocparser-0.1.0/tests/corpus/00015.toc +110 -0
- tocparser-0.1.0/tests/corpus/00016.toc +120 -0
- tocparser-0.1.0/tests/corpus/00017.toc +39 -0
- tocparser-0.1.0/tests/corpus/00018.toc +146 -0
- tocparser-0.1.0/tests/corpus/00019.toc +115 -0
- tocparser-0.1.0/tests/corpus/00020.toc +43 -0
- tocparser-0.1.0/tests/corpus/00021.toc +87 -0
- tocparser-0.1.0/tests/corpus/00022.toc +91 -0
- tocparser-0.1.0/tests/corpus/00023.toc +46 -0
- tocparser-0.1.0/tests/corpus/00024.toc +164 -0
- tocparser-0.1.0/tests/corpus/00025.toc +124 -0
- tocparser-0.1.0/tests/corpus/00026.toc +115 -0
- tocparser-0.1.0/tests/corpus/00027.toc +242 -0
- tocparser-0.1.0/tests/corpus/00028.toc +117 -0
- tocparser-0.1.0/tests/corpus/00029.toc +93 -0
- tocparser-0.1.0/tests/corpus/00030.toc +109 -0
- tocparser-0.1.0/tests/corpus/00031.toc +19 -0
- tocparser-0.1.0/tests/corpus/00032.toc +124 -0
- tocparser-0.1.0/tests/corpus/00033.toc +129 -0
- tocparser-0.1.0/tests/corpus/00034.toc +34 -0
- tocparser-0.1.0/tests/corpus/00035.toc +211 -0
- tocparser-0.1.0/tests/corpus/00036.toc +41 -0
- tocparser-0.1.0/tests/corpus/00037.toc +29 -0
- tocparser-0.1.0/tests/corpus/00038.toc +119 -0
- tocparser-0.1.0/tests/corpus/00039.toc +150 -0
- tocparser-0.1.0/tests/corpus/00040.toc +103 -0
- tocparser-0.1.0/tests/corpus/00041.toc +146 -0
- tocparser-0.1.0/tests/corpus/00042.toc +240 -0
- tocparser-0.1.0/tests/corpus/00043.toc +13 -0
- tocparser-0.1.0/tests/corpus/00044.toc +11 -0
- tocparser-0.1.0/tests/corpus/00045.toc +184 -0
- tocparser-0.1.0/tests/corpus/00046.toc +122 -0
- tocparser-0.1.0/tests/corpus/00047.toc +138 -0
- tocparser-0.1.0/tests/corpus/00048.toc +139 -0
- tocparser-0.1.0/tests/corpus/00049.toc +172 -0
- tocparser-0.1.0/tests/corpus/00050.toc +58 -0
- tocparser-0.1.0/tests/corpus/00051.toc +122 -0
- tocparser-0.1.0/tests/corpus/00052.toc +146 -0
- tocparser-0.1.0/tests/corpus/00053.toc +112 -0
- tocparser-0.1.0/tests/corpus/00054.toc +77 -0
- tocparser-0.1.0/tests/corpus/00055.toc +66 -0
- tocparser-0.1.0/tests/corpus/00056.toc +138 -0
- tocparser-0.1.0/tests/corpus/00057.toc +139 -0
- tocparser-0.1.0/tests/corpus/00058.toc +73 -0
- tocparser-0.1.0/tests/corpus/00059.toc +98 -0
- tocparser-0.1.0/tests/corpus/00060.toc +148 -0
- tocparser-0.1.0/tests/corpus/00061.toc +132 -0
- tocparser-0.1.0/tests/corpus/00062.toc +141 -0
- tocparser-0.1.0/tests/corpus/00063.toc +126 -0
- tocparser-0.1.0/tests/corpus/00064.toc +170 -0
- tocparser-0.1.0/tests/corpus/00065.toc +128 -0
- tocparser-0.1.0/tests/corpus/00066.toc +130 -0
- tocparser-0.1.0/tests/corpus/00067.toc +40 -0
- tocparser-0.1.0/tests/corpus/00068.toc +32 -0
- tocparser-0.1.0/tests/corpus/00069.toc +32 -0
- tocparser-0.1.0/tests/corpus/00070.toc +31 -0
- tocparser-0.1.0/tests/corpus/00071.toc +175 -0
- tocparser-0.1.0/tests/corpus/00072.toc +168 -0
- tocparser-0.1.0/tests/corpus/00073.toc +62 -0
- tocparser-0.1.0/tests/corpus/00074.toc +91 -0
- tocparser-0.1.0/tests/corpus/00075.toc +8 -0
- tocparser-0.1.0/tests/corpus/00076.toc +172 -0
- tocparser-0.1.0/tests/corpus/00077.toc +159 -0
- tocparser-0.1.0/tests/corpus/00078.toc +144 -0
- tocparser-0.1.0/tests/corpus/00079.toc +144 -0
- tocparser-0.1.0/tests/corpus/00080.toc +140 -0
- tocparser-0.1.0/tests/corpus/00081.toc +117 -0
- tocparser-0.1.0/tests/corpus/00082.toc +41 -0
- tocparser-0.1.0/tests/corpus/00083.toc +43 -0
- tocparser-0.1.0/tests/corpus/00084.toc +86 -0
- tocparser-0.1.0/tests/corpus/00085.toc +113 -0
- tocparser-0.1.0/tests/corpus/00086.toc +129 -0
- tocparser-0.1.0/tests/corpus/00087.toc +119 -0
- tocparser-0.1.0/tests/corpus/00088.toc +50 -0
- tocparser-0.1.0/tests/corpus/00089.toc +10 -0
- tocparser-0.1.0/tests/corpus/00090.toc +222 -0
- tocparser-0.1.0/tests/corpus/00091.toc +98 -0
- tocparser-0.1.0/tests/corpus/00092.toc +8 -0
- tocparser-0.1.0/tests/corpus/00093.toc +51 -0
- tocparser-0.1.0/tests/corpus/00094.toc +130 -0
- tocparser-0.1.0/tests/corpus/00095.toc +8 -0
- tocparser-0.1.0/tests/corpus/00096.toc +149 -0
- tocparser-0.1.0/tests/corpus/00097.toc +175 -0
- tocparser-0.1.0/tests/corpus/00098.toc +147 -0
- tocparser-0.1.0/tests/corpus/00099.toc +146 -0
- tocparser-0.1.0/tests/corpus/00100.toc +72 -0
- tocparser-0.1.0/tests/corpus/00101.toc +72 -0
- tocparser-0.1.0/tests/corpus/00102.toc +110 -0
- tocparser-0.1.0/tests/corpus/00103.toc +123 -0
- tocparser-0.1.0/tests/corpus/00104.toc +127 -0
- tocparser-0.1.0/tests/corpus/00105.toc +127 -0
- tocparser-0.1.0/tests/corpus/00106.toc +98 -0
- tocparser-0.1.0/tests/corpus/00107.toc +9 -0
- tocparser-0.1.0/tests/corpus/00108.toc +8 -0
- tocparser-0.1.0/tests/corpus/00109.toc +145 -0
- tocparser-0.1.0/tests/corpus/00110.toc +8 -0
- tocparser-0.1.0/tests/corpus/00111.toc +152 -0
- tocparser-0.1.0/tests/corpus/00112.toc +124 -0
- tocparser-0.1.0/tests/corpus/00113.toc +130 -0
- tocparser-0.1.0/tests/corpus/00114.toc +114 -0
- tocparser-0.1.0/tests/corpus/00115.toc +794 -0
- tocparser-0.1.0/tests/corpus/00116.toc +106 -0
- tocparser-0.1.0/tests/corpus/00117.toc +98 -0
- tocparser-0.1.0/tests/corpus/00118.toc +116 -0
- tocparser-0.1.0/tests/corpus/00119.toc +110 -0
- tocparser-0.1.0/tests/corpus/00120.toc +118 -0
- tocparser-0.1.0/tests/corpus/00121.toc +37 -0
- tocparser-0.1.0/tests/corpus/00122.toc +75 -0
- tocparser-0.1.0/tests/corpus/00123.toc +102 -0
- tocparser-0.1.0/tests/corpus/00124.toc +99 -0
- tocparser-0.1.0/tests/corpus/00125.toc +144 -0
- tocparser-0.1.0/tests/corpus/00126.toc +91 -0
- tocparser-0.1.0/tests/corpus/00127.toc +120 -0
- tocparser-0.1.0/tests/corpus/00128.toc +145 -0
- tocparser-0.1.0/tests/corpus/00129.toc +176 -0
- tocparser-0.1.0/tests/corpus/00130.toc +64 -0
- tocparser-0.1.0/tests/corpus/00131.toc +107 -0
- tocparser-0.1.0/tests/corpus/00132.toc +132 -0
- tocparser-0.1.0/tests/corpus/00133.toc +107 -0
- tocparser-0.1.0/tests/corpus/00134.toc +94 -0
- tocparser-0.1.0/tests/corpus/00135.toc +89 -0
- tocparser-0.1.0/tests/corpus/00136.toc +30 -0
- tocparser-0.1.0/tests/corpus/00137.toc +76 -0
- tocparser-0.1.0/tests/corpus/00138.toc +37 -0
- tocparser-0.1.0/tests/corpus/00139.toc +57 -0
- tocparser-0.1.0/tests/corpus/00140.toc +65 -0
- tocparser-0.1.0/tests/corpus/00141.toc +65 -0
- tocparser-0.1.0/tests/corpus/00142.toc +50 -0
- tocparser-0.1.0/tests/corpus/00143.toc +78 -0
- tocparser-0.1.0/tests/corpus/00144.toc +60 -0
- tocparser-0.1.0/tests/corpus/00145.toc +165 -0
- tocparser-0.1.0/tests/corpus/00146.toc +127 -0
- tocparser-0.1.0/tests/corpus/00147.toc +157 -0
- tocparser-0.1.0/tests/corpus/00148.toc +113 -0
- tocparser-0.1.0/tests/corpus/00149.toc +278 -0
- tocparser-0.1.0/tests/corpus/00150.toc +119 -0
- tocparser-0.1.0/tests/corpus/00151.toc +120 -0
- tocparser-0.1.0/tests/corpus/00152.toc +110 -0
- tocparser-0.1.0/tests/corpus/00153.toc +91 -0
- tocparser-0.1.0/tests/corpus/00154.toc +79 -0
- tocparser-0.1.0/tests/corpus/00155.toc +108 -0
- tocparser-0.1.0/tests/corpus/00156.toc +102 -0
- tocparser-0.1.0/tests/corpus/00157.toc +113 -0
- tocparser-0.1.0/tests/corpus/00158.toc +44 -0
- tocparser-0.1.0/tests/corpus/00159.toc +51 -0
- tocparser-0.1.0/tests/corpus/00160.toc +42 -0
- tocparser-0.1.0/tests/corpus/00161.toc +66 -0
- tocparser-0.1.0/tests/corpus/00162.toc +8 -0
- tocparser-0.1.0/tests/corpus/00163.toc +52 -0
- tocparser-0.1.0/tests/corpus/00164.toc +9 -0
- tocparser-0.1.0/tests/corpus/00165.toc +176 -0
- tocparser-0.1.0/tests/corpus/00166.toc +133 -0
- tocparser-0.1.0/tests/corpus/00167.toc +133 -0
- tocparser-0.1.0/tests/corpus/00168.toc +180 -0
- tocparser-0.1.0/tests/corpus/00169.toc +225 -0
- tocparser-0.1.0/tests/corpus/00170.toc +212 -0
- tocparser-0.1.0/tests/corpus/00171.toc +180 -0
- tocparser-0.1.0/tests/corpus/00172.toc +168 -0
- tocparser-0.1.0/tests/corpus/00173.toc +164 -0
- tocparser-0.1.0/tests/corpus/00174.toc +129 -0
- tocparser-0.1.0/tests/corpus/00175.toc +141 -0
- tocparser-0.1.0/tests/corpus/00176.toc +43 -0
- tocparser-0.1.0/tests/corpus/00177.toc +111 -0
- tocparser-0.1.0/tests/corpus/00178.toc +93 -0
- tocparser-0.1.0/tests/corpus/00179.toc +61 -0
- tocparser-0.1.0/tests/corpus/00180.toc +69 -0
- tocparser-0.1.0/tests/corpus/00181.toc +138 -0
- tocparser-0.1.0/tests/corpus/00182.toc +50 -0
- tocparser-0.1.0/tests/corpus/00183.toc +78 -0
- tocparser-0.1.0/tests/corpus/00184.toc +132 -0
- tocparser-0.1.0/tests/corpus/00185.toc +92 -0
- tocparser-0.1.0/tests/corpus/00186.toc +116 -0
- tocparser-0.1.0/tests/corpus/00187.toc +124 -0
- tocparser-0.1.0/tests/corpus/00188.toc +110 -0
- tocparser-0.1.0/tests/corpus/00189.toc +55 -0
- tocparser-0.1.0/tests/corpus/00190.toc +109 -0
- tocparser-0.1.0/tests/corpus/00191.toc +93 -0
- tocparser-0.1.0/tests/corpus/00192.toc +92 -0
- tocparser-0.1.0/tests/corpus/00193.toc +84 -0
- tocparser-0.1.0/tests/corpus/00194.toc +84 -0
- tocparser-0.1.0/tests/corpus/00195.toc +108 -0
- tocparser-0.1.0/tests/corpus/00196.toc +98 -0
- tocparser-0.1.0/tests/corpus/00197.toc +91 -0
- tocparser-0.1.0/tests/corpus/00198.toc +83 -0
- tocparser-0.1.0/tests/corpus/00199.toc +76 -0
- tocparser-0.1.0/tests/corpus/00200.toc +126 -0
- tocparser-0.1.0/tests/corpus/README.md +43 -0
- tocparser-0.1.0/tests/corpus/cdrdao-versions.csv +201 -0
- tocparser-0.1.0/tests/fixtures/audiofile_swap_offset.toc +10 -0
- tocparser-0.1.0/tests/fixtures/cd_i_and_empty_binary.toc +13 -0
- tocparser-0.1.0/tests/fixtures/cd_text_full.toc +54 -0
- tocparser-0.1.0/tests/fixtures/empty_cd_text_strings.toc +31 -0
- tocparser-0.1.0/tests/fixtures/encodings.toc +24 -0
- tocparser-0.1.0/tests/fixtures/escapes.toc +14 -0
- tocparser-0.1.0/tests/fixtures/fifo_and_end.toc +7 -0
- tocparser-0.1.0/tests/fixtures/four_channel_and_flags.toc +16 -0
- tocparser-0.1.0/tests/fixtures/man_composed_track.toc +12 -0
- tocparser-0.1.0/tests/fixtures/man_minimal.toc +5 -0
- tocparser-0.1.0/tests/fixtures/man_mixed_mode.toc +14 -0
- tocparser-0.1.0/tests/fixtures/man_pregap_and_cd_text.toc +28 -0
- tocparser-0.1.0/tests/fixtures/man_start_with_position.toc +6 -0
- tocparser-0.1.0/tests/fixtures/mode_variants.toc +26 -0
- tocparser-0.1.0/tests/fixtures/repeated_disc_type.toc +5 -0
- tocparser-0.1.0/tests/fixtures/scalar_times.toc +7 -0
- tocparser-0.1.0/tests/fixtures/zero_modes.toc +13 -0
- tocparser-0.1.0/tests/paths.py +17 -0
- tocparser-0.1.0/tests/test_cdrdao_oracle.py +604 -0
- tocparser-0.1.0/tests/test_corpus.py +60 -0
- tocparser-0.1.0/tests/test_errors.py +437 -0
- tocparser-0.1.0/tests/test_models.py +314 -0
- tocparser-0.1.0/tests/test_parser.py +407 -0
- tocparser-0.1.0/tests/test_serializer.py +269 -0
- tocparser-0.1.0/tests/test_times.py +77 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Jean-Marc Fontaine
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
tocparser-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tocparser
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Parse, validate, and write cdrdao CD TOC files
|
|
5
|
+
Keywords: audio,cd,cd-text,cdrdao,parser,toc
|
|
6
|
+
Author: Jean-Marc Fontaine
|
|
7
|
+
Author-email: Jean-Marc Fontaine <jm@jmfontaine.net>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: CD Audio
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Dist: lark>=1.2
|
|
24
|
+
Requires-Dist: pydantic>=2.9
|
|
25
|
+
Requires-Dist: pydantic>=2.14.0b1,<2.15 ; python_full_version == '3.15.*'
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# tocparser
|
|
30
|
+
|
|
31
|
+
tocparser parses cdrdao's TOC files into Pydantic models and writes them back out.
|
|
32
|
+
|
|
33
|
+
- It supports the full TOC format. Older files mostly parse the same, with two
|
|
34
|
+
exceptions described below.
|
|
35
|
+
- It validates files like cdrdao, matching its error messages and line numbers. See
|
|
36
|
+
Limits for exceptions.
|
|
37
|
+
- Writing preserves every value. Unedited files usually serialize byte for byte
|
|
38
|
+
identically, though hand-written comments are dropped and some formatting is
|
|
39
|
+
normalized. See What Is Written Back for details.
|
|
40
|
+
- It is fully typed and depends only on `lark` and `pydantic`.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
uv add tocparser
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Requires Python 3.10 or newer.
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from tocparser import dump, parse_file
|
|
54
|
+
|
|
55
|
+
toc = parse_file("the_downward_spiral.toc")
|
|
56
|
+
|
|
57
|
+
toc.disc_type # <DiscType.CD_DA: 'CD_DA'>
|
|
58
|
+
toc.catalog # '0602498647295'
|
|
59
|
+
toc.cd_text[0].title # 'The Downward Spiral - Deluxe Edition [ Disc 1 ] '
|
|
60
|
+
toc.cd_text[0].performer # 'Nine Inch Nails'
|
|
61
|
+
|
|
62
|
+
track = toc.tracks[4]
|
|
63
|
+
track.mode # <TrackMode.AUDIO: 'AUDIO'>
|
|
64
|
+
track.isrc # 'USIR19400529'
|
|
65
|
+
track.cd_text[0].title # 'Closer'
|
|
66
|
+
track.content[0].start # Msf(minutes=15, seconds=47, frames=32)
|
|
67
|
+
track.content[0].length # Msf(minutes=6, seconds=13, frames=23)
|
|
68
|
+
|
|
69
|
+
# "The Becoming" starts with a 00:02:30 pre-gap: 2 seconds and 30 frames.
|
|
70
|
+
toc.tracks[6].start # Start(kind='start', position=Msf(minutes=0, seconds=2, frames=30))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Models are ordinary Pydantic models, so `model_dump()`, `model_dump_json()` and
|
|
74
|
+
`Toc.model_validate_json()` all work and preserve the parsed values.
|
|
75
|
+
|
|
76
|
+
### Times
|
|
77
|
+
|
|
78
|
+
A position or length can be written as `MM:SS:FF`, where frames are counted at 75 per
|
|
79
|
+
second, or as a bare integer representing samples on an audio track and bytes on a data
|
|
80
|
+
track. These formats are not interchangeable. If a sample count is not frame-aligned, it
|
|
81
|
+
has no `MM:SS:FF` equivalent, so tocparser preserves the format in which it was written.
|
|
82
|
+
Frame-based values become `Msf`, while bare integers remain `int`.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from tocparser import Msf
|
|
86
|
+
|
|
87
|
+
position = Msf(15, 47, 32) # where "Closer" starts
|
|
88
|
+
position.total_frames # 71057
|
|
89
|
+
position.to_samples() # 41781516
|
|
90
|
+
position.to_bytes(2352) # 167126064
|
|
91
|
+
str(position) # '15:47:32'
|
|
92
|
+
Msf.from_frames(71057) # Msf(minutes=15, seconds=47, frames=32)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`Msf` is ordered and hashable, so positions sort and can be used as keys.
|
|
96
|
+
|
|
97
|
+
### CD-TEXT
|
|
98
|
+
|
|
99
|
+
CD-TEXT values are `str`, or `list[int]` for binary packs. Each language block uses
|
|
100
|
+
ISO-8859-1 unless the disc's `CD_TEXT` specifies an `ENCODING_*` value. Track blocks
|
|
101
|
+
follow the disc block with the same number, as they do in cdrdao.
|
|
102
|
+
`toc.cd_text_encoding(n)` returns the encoding used for block `n`.
|
|
103
|
+
|
|
104
|
+
Strings follow cdrdao's rules. Non-ASCII text is UTF-8 and must fit the block's
|
|
105
|
+
encoding: `TITLE "日本"` requires `ENCODING_MS_JIS`, because ISO-8859-1 cannot represent
|
|
106
|
+
Japanese. Plain ASCII strings may contain `\NNN` octal escapes, which represent bytes in
|
|
107
|
+
the block's encoding. For example, `"caf\351"` decodes to `'café'`, and under
|
|
108
|
+
`ENCODING_MS_JIS`, `"\223\372\226\173"` decodes to `'日本'`.
|
|
109
|
+
|
|
110
|
+
cdrdao treats `UPC_EAN` and `ISRC` as the same pack, as well as `RESERVED4` and
|
|
111
|
+
`CLOSED`. A block retains the spelling written last, and `block.upc_ean` and
|
|
112
|
+
`block.isrc` both access it.
|
|
113
|
+
|
|
114
|
+
### Errors
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from tocparser import TocParseError, TocValidationError, parse
|
|
118
|
+
|
|
119
|
+
parse(
|
|
120
|
+
'CD_DA\nCATALOG "0602498647"\nTRACK AUDIO\nFILE "hurt.wav" 0\n',
|
|
121
|
+
filename="the_downward_spiral.toc",
|
|
122
|
+
)
|
|
123
|
+
# TocValidationError: the_downward_spiral.toc:2: Illegal catalog number: 0602498647.
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`TocParseError` covers syntax errors and `TocValidationError` covers input that parses
|
|
127
|
+
but breaks a rule cdrdao enforces. Both derive from `TocError` and carry `line`, and
|
|
128
|
+
`TocParseError` also carries `column`. `parse_file` reads files as UTF-8 and raises
|
|
129
|
+
`TocParseError` for bytes that do not decode; pass `encoding=` for other encodings.
|
|
130
|
+
|
|
131
|
+
The models enforce the same rules, so building one by hand that cdrdao would reject
|
|
132
|
+
raises `TocValidationError`, whose `loc` locates the problem inside that model, e.g.
|
|
133
|
+
`("statements", 2)`. A value cdrdao's syntax cannot express, such as a value of the
|
|
134
|
+
wrong type or a negative number, raises Pydantic's `ValidationError` instead. Models can
|
|
135
|
+
be changed after they are built, so `dumps` validates its argument again before writing
|
|
136
|
+
it.
|
|
137
|
+
|
|
138
|
+
## What Is Written Back
|
|
139
|
+
|
|
140
|
+
Serializing preserves meaning, though not always the exact bytes. In practice, the
|
|
141
|
+
output is usually byte-for-byte identical. Differences are limited to the following:
|
|
142
|
+
|
|
143
|
+
- Hand-written comments are dropped. cdrdao-generated comments—the `// Track N` headers
|
|
144
|
+
and the `// length in bytes:` annotations on data lengths—are regenerated.
|
|
145
|
+
- `MM:SS:FF` values are zero-padded: `0:10:0` becomes `00:10:00`. Bare integers remain
|
|
146
|
+
unchanged.
|
|
147
|
+
- When a CD-TEXT item appears more than once, only its last instance is written. An
|
|
148
|
+
empty string does not replace an earlier value because cdrdao drops it. Repeated
|
|
149
|
+
LANGUAGE blocks are merged into the first, as in cdrdao's output.
|
|
150
|
+
- Text is written as UTF-8, so `\NNN` escapes are replaced by the characters they
|
|
151
|
+
represent. A backslash followed by three digits is written as `\134`, because cdrdao
|
|
152
|
+
would interpret even an escaped backslash as an octal escape. cdrdao does not accept
|
|
153
|
+
escapes in non-ASCII text, so such text cannot contain that sequence; `dumps` raises
|
|
154
|
+
an error if it does.
|
|
155
|
+
- Unwritten flags are not added. A track without a `COPY` line keeps
|
|
156
|
+
`copy_permitted is None` and has no `COPY` line in the output. The effective values
|
|
157
|
+
are available through `is_copy_permitted`, `has_pre_emphasis`, and `channel_count`.
|
|
158
|
+
|
|
159
|
+
## Limits
|
|
160
|
+
|
|
161
|
+
tocparser follows cdrdao 1.2.6, but some checks require the audio and data files
|
|
162
|
+
referenced by a TOC file. Because tocparser reads only the TOC file, it cannot check the
|
|
163
|
+
four-second minimum track length, an `INDEX` beyond the track end, `START` or `END` past
|
|
164
|
+
the track end, an `END` within the pre-gap, or a requested length that exceeds the file.
|
|
165
|
+
It also skips the CD-TEXT completeness checks that cdrdao performs only before writing a
|
|
166
|
+
disc. tocparser checks everything else that `cdrdao show-toc` checks, with these
|
|
167
|
+
differences:
|
|
168
|
+
|
|
169
|
+
- If a file contains several errors, tocparser raises one, but not necessarily the one
|
|
170
|
+
cdrdao reports first.
|
|
171
|
+
- For two syntax errors—a `PREGAP` after track data and a `LANGUAGE_MAP` inside a
|
|
172
|
+
track's `CD_TEXT`—cdrdao's parser stops at a different token than tocparser does.
|
|
173
|
+
- cdrdao reports a `FIFO` that mixes audio and data on line 0; tocparser reports the
|
|
174
|
+
`FIFO`'s own line.
|
|
175
|
+
- tocparser rejects `\NNN` bytes that are not text in their block's encoding—for
|
|
176
|
+
example, a lone CP932 lead byte or a byte above 127 in an `ENCODING_ASCII` block.
|
|
177
|
+
cdrdao keeps these bytes, at most issuing a warning, but could not read back the text
|
|
178
|
+
it would write for them.
|
|
179
|
+
- cdrdao drops CD-TEXT items with empty strings. tocparser preserves an empty item when
|
|
180
|
+
no other value is provided and writes it back. Like cdrdao, it also allows a track to
|
|
181
|
+
contain an empty item that is valid only at the disc level.
|
|
182
|
+
- Escapes in file names are decoded like CD-TEXT (as ISO-8859-1) and written back as
|
|
183
|
+
UTF-8.
|
|
184
|
+
|
|
185
|
+
## TOC Files from Older cdrdao
|
|
186
|
+
|
|
187
|
+
Files written by cdrdao 1.2.2 through 1.2.4 are mostly read the same way, with two
|
|
188
|
+
exceptions that also apply to later releases. Releases before 1.2.2 were not checked.
|
|
189
|
+
|
|
190
|
+
- cdrdao 1.2.2 through 1.2.4 wrote backslashes in strings unchanged. Since 1.2.5, a
|
|
191
|
+
backslash must begin an escape, so `"AC\DC"` is rejected with `Illegal token: \`, and
|
|
192
|
+
`"C:\\x"` now reads as `C:\x`, with one backslash rather than two. This applies to all
|
|
193
|
+
strings, including file names.
|
|
194
|
+
- cdrdao 1.2.2 through 1.2.4 wrote bytes above 127 as octal escapes, at least under the
|
|
195
|
+
default C locale, and omitted `ENCODING_*`, so the text is read as ISO-8859-1. Latin
|
|
196
|
+
text remains intact, but text in another encoding, such as Japanese, does not.
|
|
197
|
+
|
|
198
|
+
## Contributing
|
|
199
|
+
|
|
200
|
+
Contributions are welcome. See CONTRIBUTING.md for development setup, test comparisons
|
|
201
|
+
between tocparser and cdrdao, and the pull request process.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
tocparser is licensed under the Apache License 2.0.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# tocparser
|
|
2
|
+
|
|
3
|
+
tocparser parses cdrdao's TOC files into Pydantic models and writes them back out.
|
|
4
|
+
|
|
5
|
+
- It supports the full TOC format. Older files mostly parse the same, with two
|
|
6
|
+
exceptions described below.
|
|
7
|
+
- It validates files like cdrdao, matching its error messages and line numbers. See
|
|
8
|
+
Limits for exceptions.
|
|
9
|
+
- Writing preserves every value. Unedited files usually serialize byte for byte
|
|
10
|
+
identically, though hand-written comments are dropped and some formatting is
|
|
11
|
+
normalized. See What Is Written Back for details.
|
|
12
|
+
- It is fully typed and depends only on `lark` and `pydantic`.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
uv add tocparser
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Python 3.10 or newer.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from tocparser import dump, parse_file
|
|
26
|
+
|
|
27
|
+
toc = parse_file("the_downward_spiral.toc")
|
|
28
|
+
|
|
29
|
+
toc.disc_type # <DiscType.CD_DA: 'CD_DA'>
|
|
30
|
+
toc.catalog # '0602498647295'
|
|
31
|
+
toc.cd_text[0].title # 'The Downward Spiral - Deluxe Edition [ Disc 1 ] '
|
|
32
|
+
toc.cd_text[0].performer # 'Nine Inch Nails'
|
|
33
|
+
|
|
34
|
+
track = toc.tracks[4]
|
|
35
|
+
track.mode # <TrackMode.AUDIO: 'AUDIO'>
|
|
36
|
+
track.isrc # 'USIR19400529'
|
|
37
|
+
track.cd_text[0].title # 'Closer'
|
|
38
|
+
track.content[0].start # Msf(minutes=15, seconds=47, frames=32)
|
|
39
|
+
track.content[0].length # Msf(minutes=6, seconds=13, frames=23)
|
|
40
|
+
|
|
41
|
+
# "The Becoming" starts with a 00:02:30 pre-gap: 2 seconds and 30 frames.
|
|
42
|
+
toc.tracks[6].start # Start(kind='start', position=Msf(minutes=0, seconds=2, frames=30))
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Models are ordinary Pydantic models, so `model_dump()`, `model_dump_json()` and
|
|
46
|
+
`Toc.model_validate_json()` all work and preserve the parsed values.
|
|
47
|
+
|
|
48
|
+
### Times
|
|
49
|
+
|
|
50
|
+
A position or length can be written as `MM:SS:FF`, where frames are counted at 75 per
|
|
51
|
+
second, or as a bare integer representing samples on an audio track and bytes on a data
|
|
52
|
+
track. These formats are not interchangeable. If a sample count is not frame-aligned, it
|
|
53
|
+
has no `MM:SS:FF` equivalent, so tocparser preserves the format in which it was written.
|
|
54
|
+
Frame-based values become `Msf`, while bare integers remain `int`.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from tocparser import Msf
|
|
58
|
+
|
|
59
|
+
position = Msf(15, 47, 32) # where "Closer" starts
|
|
60
|
+
position.total_frames # 71057
|
|
61
|
+
position.to_samples() # 41781516
|
|
62
|
+
position.to_bytes(2352) # 167126064
|
|
63
|
+
str(position) # '15:47:32'
|
|
64
|
+
Msf.from_frames(71057) # Msf(minutes=15, seconds=47, frames=32)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`Msf` is ordered and hashable, so positions sort and can be used as keys.
|
|
68
|
+
|
|
69
|
+
### CD-TEXT
|
|
70
|
+
|
|
71
|
+
CD-TEXT values are `str`, or `list[int]` for binary packs. Each language block uses
|
|
72
|
+
ISO-8859-1 unless the disc's `CD_TEXT` specifies an `ENCODING_*` value. Track blocks
|
|
73
|
+
follow the disc block with the same number, as they do in cdrdao.
|
|
74
|
+
`toc.cd_text_encoding(n)` returns the encoding used for block `n`.
|
|
75
|
+
|
|
76
|
+
Strings follow cdrdao's rules. Non-ASCII text is UTF-8 and must fit the block's
|
|
77
|
+
encoding: `TITLE "日本"` requires `ENCODING_MS_JIS`, because ISO-8859-1 cannot represent
|
|
78
|
+
Japanese. Plain ASCII strings may contain `\NNN` octal escapes, which represent bytes in
|
|
79
|
+
the block's encoding. For example, `"caf\351"` decodes to `'café'`, and under
|
|
80
|
+
`ENCODING_MS_JIS`, `"\223\372\226\173"` decodes to `'日本'`.
|
|
81
|
+
|
|
82
|
+
cdrdao treats `UPC_EAN` and `ISRC` as the same pack, as well as `RESERVED4` and
|
|
83
|
+
`CLOSED`. A block retains the spelling written last, and `block.upc_ean` and
|
|
84
|
+
`block.isrc` both access it.
|
|
85
|
+
|
|
86
|
+
### Errors
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from tocparser import TocParseError, TocValidationError, parse
|
|
90
|
+
|
|
91
|
+
parse(
|
|
92
|
+
'CD_DA\nCATALOG "0602498647"\nTRACK AUDIO\nFILE "hurt.wav" 0\n',
|
|
93
|
+
filename="the_downward_spiral.toc",
|
|
94
|
+
)
|
|
95
|
+
# TocValidationError: the_downward_spiral.toc:2: Illegal catalog number: 0602498647.
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`TocParseError` covers syntax errors and `TocValidationError` covers input that parses
|
|
99
|
+
but breaks a rule cdrdao enforces. Both derive from `TocError` and carry `line`, and
|
|
100
|
+
`TocParseError` also carries `column`. `parse_file` reads files as UTF-8 and raises
|
|
101
|
+
`TocParseError` for bytes that do not decode; pass `encoding=` for other encodings.
|
|
102
|
+
|
|
103
|
+
The models enforce the same rules, so building one by hand that cdrdao would reject
|
|
104
|
+
raises `TocValidationError`, whose `loc` locates the problem inside that model, e.g.
|
|
105
|
+
`("statements", 2)`. A value cdrdao's syntax cannot express, such as a value of the
|
|
106
|
+
wrong type or a negative number, raises Pydantic's `ValidationError` instead. Models can
|
|
107
|
+
be changed after they are built, so `dumps` validates its argument again before writing
|
|
108
|
+
it.
|
|
109
|
+
|
|
110
|
+
## What Is Written Back
|
|
111
|
+
|
|
112
|
+
Serializing preserves meaning, though not always the exact bytes. In practice, the
|
|
113
|
+
output is usually byte-for-byte identical. Differences are limited to the following:
|
|
114
|
+
|
|
115
|
+
- Hand-written comments are dropped. cdrdao-generated comments—the `// Track N` headers
|
|
116
|
+
and the `// length in bytes:` annotations on data lengths—are regenerated.
|
|
117
|
+
- `MM:SS:FF` values are zero-padded: `0:10:0` becomes `00:10:00`. Bare integers remain
|
|
118
|
+
unchanged.
|
|
119
|
+
- When a CD-TEXT item appears more than once, only its last instance is written. An
|
|
120
|
+
empty string does not replace an earlier value because cdrdao drops it. Repeated
|
|
121
|
+
LANGUAGE blocks are merged into the first, as in cdrdao's output.
|
|
122
|
+
- Text is written as UTF-8, so `\NNN` escapes are replaced by the characters they
|
|
123
|
+
represent. A backslash followed by three digits is written as `\134`, because cdrdao
|
|
124
|
+
would interpret even an escaped backslash as an octal escape. cdrdao does not accept
|
|
125
|
+
escapes in non-ASCII text, so such text cannot contain that sequence; `dumps` raises
|
|
126
|
+
an error if it does.
|
|
127
|
+
- Unwritten flags are not added. A track without a `COPY` line keeps
|
|
128
|
+
`copy_permitted is None` and has no `COPY` line in the output. The effective values
|
|
129
|
+
are available through `is_copy_permitted`, `has_pre_emphasis`, and `channel_count`.
|
|
130
|
+
|
|
131
|
+
## Limits
|
|
132
|
+
|
|
133
|
+
tocparser follows cdrdao 1.2.6, but some checks require the audio and data files
|
|
134
|
+
referenced by a TOC file. Because tocparser reads only the TOC file, it cannot check the
|
|
135
|
+
four-second minimum track length, an `INDEX` beyond the track end, `START` or `END` past
|
|
136
|
+
the track end, an `END` within the pre-gap, or a requested length that exceeds the file.
|
|
137
|
+
It also skips the CD-TEXT completeness checks that cdrdao performs only before writing a
|
|
138
|
+
disc. tocparser checks everything else that `cdrdao show-toc` checks, with these
|
|
139
|
+
differences:
|
|
140
|
+
|
|
141
|
+
- If a file contains several errors, tocparser raises one, but not necessarily the one
|
|
142
|
+
cdrdao reports first.
|
|
143
|
+
- For two syntax errors—a `PREGAP` after track data and a `LANGUAGE_MAP` inside a
|
|
144
|
+
track's `CD_TEXT`—cdrdao's parser stops at a different token than tocparser does.
|
|
145
|
+
- cdrdao reports a `FIFO` that mixes audio and data on line 0; tocparser reports the
|
|
146
|
+
`FIFO`'s own line.
|
|
147
|
+
- tocparser rejects `\NNN` bytes that are not text in their block's encoding—for
|
|
148
|
+
example, a lone CP932 lead byte or a byte above 127 in an `ENCODING_ASCII` block.
|
|
149
|
+
cdrdao keeps these bytes, at most issuing a warning, but could not read back the text
|
|
150
|
+
it would write for them.
|
|
151
|
+
- cdrdao drops CD-TEXT items with empty strings. tocparser preserves an empty item when
|
|
152
|
+
no other value is provided and writes it back. Like cdrdao, it also allows a track to
|
|
153
|
+
contain an empty item that is valid only at the disc level.
|
|
154
|
+
- Escapes in file names are decoded like CD-TEXT (as ISO-8859-1) and written back as
|
|
155
|
+
UTF-8.
|
|
156
|
+
|
|
157
|
+
## TOC Files from Older cdrdao
|
|
158
|
+
|
|
159
|
+
Files written by cdrdao 1.2.2 through 1.2.4 are mostly read the same way, with two
|
|
160
|
+
exceptions that also apply to later releases. Releases before 1.2.2 were not checked.
|
|
161
|
+
|
|
162
|
+
- cdrdao 1.2.2 through 1.2.4 wrote backslashes in strings unchanged. Since 1.2.5, a
|
|
163
|
+
backslash must begin an escape, so `"AC\DC"` is rejected with `Illegal token: \`, and
|
|
164
|
+
`"C:\\x"` now reads as `C:\x`, with one backslash rather than two. This applies to all
|
|
165
|
+
strings, including file names.
|
|
166
|
+
- cdrdao 1.2.2 through 1.2.4 wrote bytes above 127 as octal escapes, at least under the
|
|
167
|
+
default C locale, and omitted `ENCODING_*`, so the text is read as ISO-8859-1. Latin
|
|
168
|
+
text remains intact, but text in another encoding, such as Japanese, does not.
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
Contributions are welcome. See CONTRIBUTING.md for development setup, test comparisons
|
|
173
|
+
between tocparser and cdrdao, and the pull request process.
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
tocparser is licensed under the Apache License 2.0.
|