<commit_before>try:
    import acoustid
    have_acoustid = True
except ImportError:
    have_acoustid = False
import random
import collections
import os

LOOKUPS = 4
CUTOFF = .85

        
class Release:

    """
    Relevent data - release name, release artist, 
    """

    meta = "recordings releasegroups"
    api_key = "<KEY>"

    def __init__(self, audio_files):
        self.num_tracks = len(audio_files)
        self.tracks = audio_files
        self.releasegroups = collections.Counter()
        self.recordings = dict()
        self.can_lookup = False
        self.best_group = None

        # figure out just putting an fpcalc exe in here & then setting the environment variable from there
        # if acoustid.FPCALC_ENVVAR not in os.environ:
        #     os.environ[acoustid.FPCALC_ENVVAR]

        # this is terrible (but not as terrible as just tellin' you to set your FPCALC variable??)
        if have_acoustid:
            fpcalc_name = os.path.join("MusicBrainz Picard", "fpcalc.exe")
            fpcalc_path = os.path.join(os.environ["ProgramFiles"], fpcalc_name)
            if os.path.exists(fpcalc_path):
                os.environ[acoustid.FPCALC_ENVVAR] = fpcalc_path
            fpcalc_path = os.path.join(os.environ["ProgramFiles(x86)"], fpcalc_name)
            if os.path.exists(fpcalc_path):
                os.environ[acoustid.FPCALC_ENVVAR] = fpcalc_path
            if os.path.exists(os.environ[acoustid.FPCALC_ENVVAR]):
                self.can_lookup = True

    def lookup(self):
        if self.can_lookup:
            num_releases = LOOKUPS if len(self.tracks) > LOOKUPS else len(self.tracks)

            print(len(self.tracks))
            track_nums = [i for i in range(len(self.tracks))]
            random.shuffle(track_nums)
            print(track_nums)
            lookups = 0

            while len(track_nums) > 0:
                lookups += 1
                track = self.tracks[track_nums.pop()]
                if track.acoustid.value or track.meta_stuffed.value:
                    continue
                try:
                    fingerprint = acoustid.fingerprint_file(track.file_name)
                except acoustid.FingerprintGenerationError:
                    print("no way to generate fingerprint")
                    self.can_lookup = False
                    return

                track.acoustid.value = "NOT_FOUND"
                track_score = 0
                result = acoustid.lookup(self.api_key, fingerprint[1], fingerprint[0], Release.meta)

                for trackId in result["results"]:
                    if trackId["score"] > track_score:
                        track.acoustid.value = trackId["id"]<commit_msg>Bug fix: check that fpcalc envvar exists before attempting retrieval<commit_after>try:
    import acoustid
    have_acoustid = True
except ImportError:
    have_acoustid = False
import random
import collections
import os

LOOKUPS = 4
CUTOFF = .85

        
class Release:

    """
    Relevent data - release name, release artist, 
    """

    meta = "recordings releasegroups"
    api_key = "<KEY>"

    def __init__(self, audio_files):
        self.num_tracks = len(audio_files)
        self.tracks = audio_files
        self.releasegroups = collections.Counter()
        self.recordings = dict()
        self.can_lookup = False
        self.best_group = None

        # figure out just putting an fpcalc exe in here & then setting the environment variable from there
        # if acoustid.FPCALC_ENVVAR not in os.environ:
        #     os.environ[acoustid.FPCALC_ENVVAR]

        # this is terrible (but not as terrible as just tellin' you to set your FPCALC variable??)
        if have_acoustid:
            fpcalc_name = os.path.join("MusicBrainz Picard", "fpcalc.exe")
            fpcalc_path = os.path.join(os.environ["ProgramFiles"], fpcalc_name)
            if os.path.exists(fpcalc_path):
                os.environ[acoustid.FPCALC_ENVVAR] = fpcalc_path
            fpcalc_path = os.path.join(os.environ["ProgramFiles(x86)"], fpcalc_name)
            if os.path.exists(fpcalc_path):
                os.environ[acoustid.FPCALC_ENVVAR] = fpcalc_path
            if acoustid.FPCALC_ENVVAR in os.environ \
                and os.path.exists(os.environ[acoustid.FPCALC_ENVVAR]):
                self.can_lookup = True

    def lookup(self):
        if self.can_lookup:
            num_releases = LOOKUPS if len(self.tracks) > LOOKUPS else len(self.tracks)

            print(len(self.tracks))
            track_nums = [i for i in range(len(self.tracks))]
            random.shuffle(track_nums)
            print(track_nums)
            lookups = 0

            while len(track_nums) > 0:
                lookups += 1
                track = self.tracks[track_nums.pop()]
                if track.acoustid.value or track.meta_stuffed.value:
                    continue
                try:
                    fingerprint = acoustid.fingerprint_file(track.file_name)
                except acoustid.FingerprintGenerationError:
                    print("no way to generate fingerprint")
                    self.can_lookup = False
                    return

                track.acoustid.value = "NOT_FOUND"
                track_score = 0
                result = acoustid.lookup(self.api_key, fingerprint[1], fingerprint[0], Release.meta)

                for trackId in result["results"]:
                    if trackId["score"] > track_score:
                        track.acoustid.value = trackId["id"]
{'fraction_non_alphanumeric': 0.08629441624365482, 'fraction_numerical': 0.003988397389412618, 'mean_word_length': 1.928343949044586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4538014', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1598, 'n_words': 360}