예제 #1
0
def tag(song_path):
    '''
    Takes a song at <song_path>
    Tags it with metadata retrieved through the AcoustID API
    '''
    metadata = get_metadata(song_path)
    artist, title, date = retrieve(song_path)
    tags = {'ARTIST': artist, 'TITLE': title, 'DATE': date}
    replace_metadata(metadata, tags)
    song = AudioSegment.from_file(song_path, format=get_extension(song_path))
    song.export(song_path, format=get_extension(song_path), tags=metadata)
예제 #2
0
def create_metadata(song_path, sample_dir_path):
    # Samples creation
    dir_path = rdir_generator(sample_dir_path)
    song = AudioSegment.from_file(song_path, format=get_extension(song_path))
    start_times = onset_times(song, N_SAMPLES, SAMPLE_LGTH)
    for i in range(N_SAMPLES):
        create_sample(song, dir_path, start_times[i] * 1000)

    # Metadata object creation
    metadata = get_metadata(song_path)
    metadata['PATH'] = dir_path
    return metadata
예제 #3
0
    def do_export(self, args):
        print("Processing...")
        # Organising files via a tree depth roaming (parcours en profondeur)
        permutation = []
        copy = Prompt.subfolders.copy()
        Prompt.subfolders.sort()
        for element in copy:
            permutation.append(Prompt.subfolders.index(element))
        Prompt.metadata = [
            Prompt.metadata[permutation.index(i)]
            for i in range(len(permutation))
        ]

        # Pre-metadata replacement for folders
        for item in Prompt.subfolders:
            for subitem in Prompt.subfolders[Prompt.subfolders.index(item) +
                                             1:]:
                if item in subitem:
                    replace_metadata(
                        Prompt.metadata[Prompt.subfolders.index(subitem)],
                        Prompt.metadata[Prompt.subfolders.index(item)])

        # Samples creation
        metadata = []
        for sub in Prompt.subfolders:
            print(yellow_fg(sub))
            start_time = time()
            metadata.append(create_dir_metadata(sub, self.sample_dir_path))
            end_time = time()
            if [
                    item for item in [item[2] for item in walk(sub)][0]
                    if get_extension(item) in AUDIO_EXTENSIONS
            ]:  # Checks if directory contains at least one audio file
                elapsed_time = end_time - start_time
                print("\nFolder exportation time : " +
                      blue_fg('{:02d}h:{:02d}m:{:02d}s'.format(
                          int(elapsed_time //
                              3600), int((elapsed_time % 3600) //
                                         60), int(elapsed_time % 60))) + "\n")
        for i in range(len(Prompt.metadata)):
            for j in range(len(metadata[i])):
                replace_metadata(metadata[i][j], Prompt.metadata[i])
        metadata = [item for arr in metadata
                    for item in arr]  # final item which contains all metadata
        file = open(self.sample_dir_path + '/metadata.txt', 'a')
        for d in metadata:
            file.write(sober_dict(d) + '\n')
            print(smooth_dict(d))
        file.close()
        # TODO : Truly export these metadata in the database
        print(green_fg('Done'))
예제 #4
0
 def do_tag(self, args):
     print("This operation is " + red_fg("irreversible") +
           ", take it into account before doing it")
     #TODO : function that automatically adds metadata to files in selected folders
     rank = 1
     roots = [item[0] for item in walk(SONG_DIR_PATH)]
     for root in roots:
         print(bright(str(rank)), cyan_fg(root))
         rank += 1
     print(
         "Type the numbers corresponding to the subfolders whose content you wish to automatically tag, and separate them using "
         + dim('":"'))
     print("For instance, " + bright('3:12:1:5'))
     print("Note that tagging ", end='')
     print(green_fg("will"), end='') if Prompt.recursively else print(
         red_fg("won't"), end='')
     print(" be recursive")
     print("If your intention is to add all of them, simply write " +
           bright("all") + ", otherwise type " + bright('exit'))
     res = input("[$] ")
     if (res == 'exit'):
         print(magenta_fg(bright('Operation canceled')))
         return
     elif (res == 'all'):
         res = [str(i) + ":" for i in range(1, len(roots) + 1)]
         res = ''.join(res)
     while not parse(res)[0]:
         print(
             red_fg("Unvalid format, please respect " +
                    bright('2:4:15:6')) + red_fg(" standard"))
         print("Please write it again, or type " + bright('exit') +
               " to cancel, or type " + bright('all') +
               " to add all subfolders")
         res = input("[$] ")
         if (res == 'exit'):
             print(magenta_fg(bright('Operation canceled')))
             return
         elif (res == 'all'):
             res = [str(i) + ":" for i in range(1, len(roots) + 1)]
             res = ''.join(res)
     print("Processing...")
     ranks = parse(res)[1]
     indexes = [
         ranks[i] - 1 for i in range(len(ranks))
         if ranks[i] - 1 < len(roots)
     ]
     for i in indexes:
         print(yellow_fg(roots[i]))
         start_time = time()
         tag_dir(roots[i])
         end_time = time()
         if [
                 item for item in [item[2] for item in walk(roots[i])][0]
                 if get_extension(item) in AUDIO_EXTENSIONS
         ]:  # Checks if directory contains at least one audio file
             elapsed_time = end_time - start_time
             print("\nFolder exportation time : " +
                   blue_fg('{:02d}h:{:02d}m:{:02d}s'.format(
                       int(elapsed_time //
                           3600), int((elapsed_time % 3600) //
                                      60), int(elapsed_time % 60))))
     # Adding other subfolders according to hierarchy
     if Prompt.recursively:
         for i in indexes:
             for subitem in roots:
                 if roots[i] in subitem and roots[i] != subitem:
                     print(yellow_fg(subitem))
                     start_time = time()
                     tag_dir(subitem)
                     end_time = time()
                     if [
                             item for item in
                         [item[2] for item in walk(subitem)][0]
                             if get_extension(item) in AUDIO_EXTENSIONS
                     ]:  # Checks if directory contains at least one audio file
                         elapsed_time = end_time - start_time
                         print("\nFolder exportation time : " +
                               blue_fg('{:02d}h:{:02d}m:{:02d}s'.format(
                                   int(elapsed_time // 3600),
                                   int((elapsed_time % 3600) //
                                       60), int(elapsed_time % 60))))
     print(green_fg('Done'))
     pass
예제 #5
0
def is_audio_file(file_path):
    '''Checks whether file at <file_path> is an audio file or not'''
    return get_extension(file_path) in AUDIO_EXTENSIONS and isfile(file_path)