Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exceptions #25

Open
jcor29 opened this issue Oct 30, 2024 · 1 comment
Open

Uncaught exceptions #25

jcor29 opened this issue Oct 30, 2024 · 1 comment

Comments

@jcor29
Copy link

jcor29 commented Oct 30, 2024

Hi,
Tagminder is really a great idea
Sadly, ruffly 10% of Flacs are reported badly encoded.

This is my case, and Tagminder keeps crashing on badly encoded Flacs
To improve this , i wrote a tiny program to fix this, it does not crash on hundreds of corrupted Flac files

Please catch the appropriate exceptions, and log the file e.g
but unusable as such for me

I you need corrupted Flacs, i'll be keen to give you access to it, this to improve your testing

Thanks
Jacques

-----

import glob, sys, os
from multiprocessing import Pool as ProcessPool

import mutagen.flac
from mutagen import MutagenError
from mutagen.flac import FLAC

DIR_TO_SCAN = "/tmp"
STATE, EXCEPTION, PATH, INSTANCE = 0, 1, 2, 3

def _syntax():
print('syntax : ' + sys.argv[0] + "

")
exit(2)
def flac_processor(path):

# first parameter - flac state valid/invalid
# second - the mutagen exception type issued
# third - flac path
# the flac mutagen instance associated
scan = [False, None, path, None]

# do stuff
try:
     scan[INSTANCE] = FLAC(path)
     scan[STATE] = True
     scan[INSTANCE] = None
except MutagenError as ex:
    scan[STATE] = False
    scan[EXCEPTION] = ex
    print(' NOK : ' +  path)
except mutagen.flac.FLACNoHeaderError as ex:
    scan[STATE] = False
    scan[EXCEPTION] = ex
    print(' NOK : ' +  path)

except mutagen.flac.FLACVorbisError as ex:
    scan[STATE] = False
    scan[EXCEPTION] = ex
except TypeError as ex:
    scan[STATE] = False
    scan[EXCEPTION] = ex
    print(' NOK : ' +  path)
    #print(ex)

return scan

class BadFlac(object):
def init(self,path):
self.results = list()
self.valids, self.invalids, self.mutagens = list(), list(), list()

    desired_file_list = [file_name for file_name in glob.iglob(path + '**/**', recursive=True) if file_name.endswith('.flac')]
    with ProcessPool(processes=8) as pool:
        self.results = pool.map(flac_processor, desired_file_list)

    for _scan in self.results:
        if _scan[STATE]:
            self.valids.append(_scan[PATH])
            self.mutagens.append(_scan[INSTANCE])
        else:
            self.invalids.append(_scan[PATH])

def total(self):
    return len(self.valids) + len(self.invalids)

def total_invalid(self):
    return len(self.invalids)

def total_valid(self):
    return len(self.valids)

def get_valids(self):
    return self.mutagens

def _stats(self):
    print(str(self.total()) + " tracks")
    print(str(self.total_valid()) + " valid tracks")
    print(str(self.total_invalid()) + " invalid tracks")

if name == "main":

print(sys.argv[1])
if len(sys.argv) == 2:
    path = sys.argv[1]
    if os.path.exists(path):
        DIR_TO_SCAN = path
    else:
        _syntax()
else:
    _syntax()

print("Check : " + DIR_TO_SCAN)

validation = BadFlac(DIR_TO_SCAN)
validation._stats()
@audiomuze
Copy link
Owner

I'll add exception handling etc. when I'm done with core functionality and am ready to release something properly. At present my focus is continuing with the data wrangling that gets metadata into great shape and consistent. If someone wants to submit a PR to handle corrupt files in the meantime, they're welcome to. There's no point sorting tags in corrupt files though, so in the absence of a PR I'll only get there when the core of what I want managed data wise is completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants