Add typing annotations, fix problems they revealed
This commit is contained in:
+12
-10
@@ -23,16 +23,17 @@
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import io
|
||||
import re
|
||||
|
||||
import click
|
||||
|
||||
|
||||
def cue_to_meta(cuefile, metafile):
|
||||
def cue_to_meta(cuefile: io.StringIO, metafile: io.StringIO) -> None:
|
||||
"""Convert CUE to META."""
|
||||
title = None
|
||||
performer = None
|
||||
timestamp = None
|
||||
title = ""
|
||||
performer = ""
|
||||
timestamp = ""
|
||||
|
||||
for line in cuefile.readlines():
|
||||
title_re = re.search(r'^ TITLE "(.*)"$', line)
|
||||
@@ -44,17 +45,18 @@ def cue_to_meta(cuefile, metafile):
|
||||
performer = performer_re[1]
|
||||
if index_re:
|
||||
time_re = re.search(r"^(..):(..):..$", index_re[1])
|
||||
timestamp = f"00{time_re[1]}{time_re[2]}"
|
||||
if title and performer and timestamp:
|
||||
if time_re:
|
||||
timestamp = f"00{time_re[1]}{time_re[2]}"
|
||||
if title != "" and performer != "" and timestamp != "":
|
||||
metafile.write(f"{timestamp}:{performer} - {title}\n")
|
||||
title = None
|
||||
performer = None
|
||||
timestamp = None
|
||||
title = ""
|
||||
performer = ""
|
||||
timestamp = ""
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("cuefile", type=click.File("r"))
|
||||
@click.argument("metafile", type=click.File("w"))
|
||||
def cli(cuefile, metafile):
|
||||
def cli(cuefile: io.StringIO, metafile: io.StringIO) -> None:
|
||||
"""Convert CUEFILE to meta format as METAFILE."""
|
||||
cue_to_meta(cuefile, metafile)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import io
|
||||
import cue_to_meta
|
||||
|
||||
|
||||
def test_cue_to_meta():
|
||||
def test_cue_to_meta() -> None:
|
||||
"""Test CUE to META conversion."""
|
||||
cue_text = """PERFORMER "mcornick"
|
||||
TITLE "Luv'n Time International"
|
||||
|
||||
Reference in New Issue
Block a user