From aa22ab989a3fe32a973d6fed919075480c36b233 Mon Sep 17 00:00:00 2001 From: Marmous Date: Tue, 15 Aug 2023 23:37:39 +0200 Subject: [PATCH] Init --- README.md | 32 +++++++++++++++++++++++++++++++- cue2txt.py | 34 ++++++++++++++++++++++++++++++++++ example.cue | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 cue2txt.py create mode 100644 example.cue diff --git a/README.md b/README.md index d839661..b7add20 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ # cue2txt -Python script to convert a cue sheet file (.cue tracklist) in a text file more comfortably readable by humans. \ No newline at end of file +Python script to convert a cue sheet file (.cue tracklist) in a text file more comfortably readable by humans. +## Installation +```bash +git clone https://forge.chalec.org/Marmous/cue2txt.git +``` +## Usage +``` +usage: cue2txt.py \[-h\] \[-s\] \[-o OUTPUT\] file + +Let's convert a cue sheet file (.cue tracklist) in a text file more comfortably readable by humans. + +positional arguments: + file                  path to cue file + +options: + -h, --help            show this help message and exit + -s, --show            show results + -o OUTPUT, --output OUTPUT +                       path to output txt file +``` +### Linux +```bash +python3 cue2txt.py FILEPATH +``` +### Windows +```bash +python cue2txt.py FILEPATH +``` + +## References +- _example.cue_ comes from [the Cue sheet Wikipedia article](https://en.wikipedia.org/wiki/Cue_sheet_(computing)?oldformat=true#Examples) \ No newline at end of file diff --git a/cue2txt.py b/cue2txt.py new file mode 100644 index 0000000..bdd8487 --- /dev/null +++ b/cue2txt.py @@ -0,0 +1,34 @@ +import argparse +import re + +# Command arguments +parser = argparse.ArgumentParser( + description="Let's convert a cue sheet file (.cue tracklist) in a text file more comfortably readable by humans.", +) +parser.add_argument("file", type=str, help="path to cue file") +parser.add_argument("-s", "--show", action="store_true", help="show results") +parser.add_argument("-o", "--output", type=str, help="path to output txt file") + +args = parser.parse_args() +filepath = args.file +show_state = args.show +if args.output != None: # output filepath is optional + new_filepath = args.output +else: + new_filepath = re.findall(r"(.*)(?:\.cue)", filepath)[0]+".txt" + +# Parsing +with open(filepath,"r") as content, open(new_filepath,"w") as tracklist : + line = content.readline() + track_tab = {} + + while line != "": + line = content.readline() + if "TRACK" in line: + title = re.findall(r"(?:TITLE\s\")(.*)(?:\")", content.readline())[0] + performer = re.findall(r"(?:PERFORMER\s\")(.*)(?:\")", content.readline())[0] + time = re.findall(r"(?:INDEX\s\d+\s)(.*)(?:\:\d+)", content.readline())[0] + track_string = time+" - "+performer+" - "+title+"\n" # makes a text line for any track + if show_state: # prints result if requested + print(track_string) + tracklist.write(track_string) # writes the line in the .txt file \ No newline at end of file diff --git a/example.cue b/example.cue new file mode 100644 index 0000000..08b6b1c --- /dev/null +++ b/example.cue @@ -0,0 +1,37 @@ +REM GENRE Electronica +REM DATE 1998 +PERFORMER "Faithless" +TITLE "Live in Berlin" +FILE "Faithless - Live in Berlin.mp3" MP3 + TRACK 01 AUDIO + TITLE "Reverence" + PERFORMER "Faithless" + INDEX 01 00:00:00 + TRACK 02 AUDIO + TITLE "She's My Baby" + PERFORMER "Faithless" + INDEX 01 06:42:00 + TRACK 03 AUDIO + TITLE "Take the Long Way Home" + PERFORMER "Faithless" + INDEX 01 10:54:00 + TRACK 04 AUDIO + TITLE "Insomnia" + PERFORMER "Faithless" + INDEX 01 17:04:00 + TRACK 05 AUDIO + TITLE "Bring the Family Back" + PERFORMER "Faithless" + INDEX 01 25:44:00 + TRACK 06 AUDIO + TITLE "Salva Mea" + PERFORMER "Faithless" + INDEX 01 30:50:00 + TRACK 07 AUDIO + TITLE "Dirty Old Man" + PERFORMER "Faithless" + INDEX 01 38:24:00 + TRACK 08 AUDIO + TITLE "God Is a DJ" + PERFORMER "Faithless" + INDEX 01 42:35:00 \ No newline at end of file