tralph3 / Cue-Maker

A simple and easy to use program that fetches original cue files for your roms.
GNU General Public License v3.0
28 stars 7 forks source link

M3U files have directory included in text generated and shouldn't. #9

Closed birdybro closed 4 years ago

birdybro commented 4 years ago

I could have sworn I tested this after your M3U release, but looks like I dropped the ball on that. The M3U files that are generated have the directory in them still. It's somewhere in here but I don't know enough to make the change myself adequately.

def createM3u(cueFiles):
    global m3uWriteCounter

    print("\n\u001b[1;32mCreating .m3u...\u001b[0m\n")
    for file in cueFiles:
        if file.rfind("/") != -1:
            fileDirectory = file[0:file.rfind("/") + 1]
            fileName = file[file.rfind("/") + 1:len(file)]
        else:
            fileDirectory = ""
            fileName = file

        if fileName.lower().find(" (disc") != -1 or fileName.lower().find("_(disc") != -1:
            print("Found file: \"\u001b[1;33m" + fileName + "\u001b[0m\"")
            discWordIndex = fileName.lower().index(" (disc")
            discEndIndex = fileName.find(")", discWordIndex) + 1
            m3uFilePath = fileDirectory + fileName.replace(fileName[discWordIndex:discEndIndex], "").replace(fileName[-4:], ".m3u")
            m3u = open(m3uFilePath, "a+")
            m3u.seek(0)
            if m3u.read().find(fileName) == -1:
                m3u.write(fileName + "\n")
                print("\u001b[36mWrote \"\u001b[1;34m" + fileName + "\u001b[36m\" to \"\u001b[1;33m" + fileName[0:discWordIndex] + ".m3u\u001b[36m\"\u001b[0m\n--------")
                m3uWriteCounter += 1
            else:
                print("\u001b[31m\"\u001b[1;34m" + fileName + "\u001b[31m\" is already present on \"\u001b[33m" + fileName[0:discWordIndex] + ".m3u\u001b[31m\"\u001b[0m\n--------")
            m3u.close()

The current naming format the .m3u is:

Koudelka (USA)\Koudelka (USA) (Disc 1).cue
Koudelka (USA)\Koudelka (USA) (Disc 2).cue
Koudelka (USA)\Koudelka (USA) (Disc 3).cue
Koudelka (USA)\Koudelka (USA) (Disc 4).cue

And it should instead be:

Koudelka (USA) (Disc 1).cue
Koudelka (USA) (Disc 2).cue
Koudelka (USA) (Disc 3).cue
Koudelka (USA) (Disc 4).cue

I'll be sure to actually test it fully this time...

tralph3 commented 4 years ago

Yeah that's what I get for testing on linux only. That happens because on linux folders are separated by / where on windows it's \

birdybro commented 4 years ago

I remember when learning about this myself to try and make my own awhile ago, there was a newer python 3.x module that covers os-agnostic path handling.

https://docs.python.org/3/library/pathlib.html

I have little knowledge but maybe it would help.

tralph3 commented 4 years ago

I made a quick and dirty fix I'm not proud of, but should work for now, I'd have to take a look at it later.