예제 #1
0
 def do_status(self, args):
     lth = min(len(Prompt.subfolders), len(Prompt.metadata))
     if lth == 0:
         print(yellow_fg("No subfolders have been added"))
     else:
         for i in range(lth):
             print(yellow_fg(Prompt.subfolders[i]))
             print(smooth_dict(Prompt.metadata[i]))
예제 #2
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'))
 def list_content(self, only_file = True):
     idx = 0
     for audio_file in self.audio_files:
         print(yellow_fg(str(idx) + " : " + get_last_name(audio_file[0])), end = 2 * ' ') if only_file else print(yellow_fg(str(idx) + " : " + get_last_name(audio_file[0])) + "\n" + smooth_dict(audio_file[1]))
         idx += 1
     if only_file and len(self.audio_files) > 0:
         print()
예제 #4
0
    def do_remove(self, args):
        global SONG_DIR_PATH

        if args.startswith('subfolder'):
            if len(args) == 9:  # 9 == len('subfolder')
                rank = 1
                for sub in Prompt.subfolders:
                    print(bright(str(rank)), cyan_fg(sub))
                    rank += 1
                print(
                    "Type the numbers corresponding to the subfolders you wish to remove, and separate them using "
                    + dim('":"'))
                print("For instance, " + bright('3:2:14:6'))
                print(
                    "If your intention is to remove 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(Prompt.subfolders) + 1)
                    ]
                    res = ''.join(res)
                while not parse(res)[0]:
                    print(
                        red_fg("Unvalid format, please respect " +
                               bright('3:8:1:7')) + red_fg(" standard"))
                    print("Please write it again, or type " + bright('exit') +
                          " to cancel, or type " + bright('all') +
                          " to remove all")
                    res = input("[$] ")
                    if res == 'exit':
                        print(magenta_fg(bright('Operation canceled')))
                        return
                    elif res == 'all':
                        res = [
                            str(i) + ":"
                            for i in range(1,
                                           len(Prompt.subfolders) + 1)
                        ]
                        res = ''.join(res)
                ranks = parse(res)[1]
                indexes = [ranks[i] - i - 1 for i in range(len(ranks))]
                # Hierarchical removing
                if Prompt.recursively:
                    metadata_removed, subfolders_removed = [], []
                    for r in ranks:
                        subfolders_removed.append(Prompt.subfolders[r - 1])
                        metadata_removed.append(Prompt.metadata[r - 1])
                        for subitem in Prompt.subfolders:
                            if Prompt.subfolders[
                                    r - 1] in subitem and Prompt.subfolders[
                                        r - 1] != subitem:
                                subfolders_removed.append(subitem)
                                metadata_removed.append(Prompt.metadata[
                                    Prompt.subfolders.index(subitem)])
                    Prompt.subfolders = [
                        subfolder for subfolder in Prompt.subfolders
                        if subfolder not in subfolders_removed
                    ]
                    Prompt.metadata = [
                        metadata for metadata in Prompt.metadata
                        if metadata not in metadata_removed
                    ]
                else:
                    for i in indexes:
                        if i < len(Prompt.subfolders):
                            del Prompt.subfolders[i]
                            del Prompt.metadata[i]
                print(green_fg('Done'))
            else:
                print("Usage : 'remove subfolder'")
        elif args.startswith('metadata'):
            if (len(args) == 8):  # 4 == len('metadata')
                rank = 1
                for sub in Prompt.subfolders:
                    print(bright(blue_fg(str(rank))), blue_fg(sub))
                    print(smooth_dict(Prompt.metadata[rank - 1]))
                    rank += 1
                print(
                    "Type the numbers corresponding to the subfolders whose metadata you wish to reset, and separate them using "
                    + dim('":"'))
                print("For instance, " + bright('6:2:16:1'))
                print(
                    "If your intention is to reset 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(Prompt.subfolders) + 1)
                    ]
                    res = ''.join(res)
                while not parse(res)[0]:
                    print(
                        red_fg("Unvalid format, please respect " +
                               bright('3:1:9:18')) + red_fg(" standard"))
                    print("Please write it again, or type " + bright('exit') +
                          " to cancel, or type " + bright('all') +
                          " to reset all")
                    res = input("[$] ")
                    if (res == 'exit'):
                        print(magenta_fg(bright('Operation canceled')))
                        return
                    elif (res == 'all'):
                        res = [
                            str(i) + ":"
                            for i in range(1,
                                           len(Prompt.subfolders) + 1)
                        ]
                        res = ''.join(res)
                ranks = parse(res)[1]
                for r in ranks:
                    if r - 1 < len(Prompt.metadata):
                        for field in Prompt.metadata[r - 1]:
                            Prompt.metadata[r - 1][field] = None
                print(green_fg('Done'))
            else:
                print("Usage : 'remove metadata'")
        else:
            print("Usage :")
            print("'remove subfolder'")
            print("'remove metadata'")
예제 #5
0
    def do_add(self, args):
        global SONG_DIR_PATH

        if args.startswith('subfolder'):
            if (len(args) == 9):  # 9 == len('subfolder')
                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 you wish to add, and separate them using "
                    + dim('":"'))
                print("For instance, " + bright('3:12:1:5'))
                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)
                ranks = parse(res)[1]
                indexes = [ranks[i] - 1 for i in range(len(ranks))]
                for i in indexes:
                    if i < len(roots) and roots[i] not in Prompt.subfolders:
                        Prompt.subfolders.append(roots[i])
                        Prompt.metadata.append({tag: None for tag in METADATA})
                # Adding other subfolders according to hierarchy
                if Prompt.recursively:
                    for item in Prompt.subfolders:
                        for subitem in roots:
                            if item in subitem and item != subitem and subitem not in Prompt.subfolders:
                                Prompt.subfolders.append(subitem)
                                Prompt.metadata.append(
                                    {tag: None
                                     for tag in METADATA})
                print(green_fg('Done'))
            else:
                print("Usage : 'add subfolder'")
        elif args.startswith('metadata'):
            if (len(args) == 8):  # 8 == len('metadata')
                rank = 1
                for sub in Prompt.subfolders:
                    print(bright(blue_fg(str(rank))), blue_fg(sub))
                    print(smooth_dict(Prompt.metadata[rank - 1]))
                    rank += 1
                print(
                    "Type the numbers corresponding to the subfolders whose metadata you wish to modify, and separate them using "
                    + dim('":"'))
                print("For instance, " + bright('6:2:16:1'))
                print(
                    "If your intention is to modify 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 = ['0:'] + [
                        str(i) + ":" for i in range(1,
                                                    len(Prompt.subfolders) + 1)
                    ]
                    res = ''.join(res)
                while not parse(res)[0]:
                    print(
                        red_fg("Unvalid format, please respect " +
                               bright('3:1:9:18')) + red_fg(" standard"))
                    print("Please write it again, or type " + bright('exit') +
                          " to cancel, or type " + bright('all') +
                          " to modify all")
                    res = input("[$] ")
                    if (res == 'exit'):
                        print(magenta_fg(bright('Operation canceled')))
                        return
                    elif (res == 'all'):
                        res = [
                            str(i) + ":"
                            for i in range(1,
                                           len(Prompt.subfolders) + 1)
                        ]
                        res = ''.join(res)
                ranks = parse(res)[1]
                for r in ranks:
                    if r - 1 < len(Prompt.subfolders):
                        print(blue_fg(Prompt.subfolders[r - 1]))
                        print(smooth_dict(Prompt.metadata[r - 1]))
                        for field in Prompt.metadata[r - 1]:
                            print(bright(magenta_fg('<' + field + '>')),
                                  Fore.MAGENTA)
                            res = input("[$] ")
                            if (res == '' or
                                (not res.isdigit() and field == 'DATE')):
                                Prompt.metadata[r - 1][field] = None
                            else:
                                Prompt.metadata[r - 1][field] = res
                        print(Fore.RESET)
                print(green_fg('Done'))
            else:
                print("Usage : 'add metadata'")
        else:
            print("Usage :")
            print("'add subfolder'")
            print("'add metadata'")