Completed
Push — master ( 91d748...e1a893 )
by Andreas
19s queued 12s
created

CMSCli   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ask_paths() 0 5 1
A main_process() 0 14 1
A start_interactive() 0 13 4
1
"""CLI Версия CMS."""
2
import os
3
4
vers = '0.3.4'
5
6
7
def ask_paths():
8
    """Запуск и в интерактивном режиме."""
9
    input_dir = input('Путь до исходной директории: ')
10
    output_dir = input('Путь до конечной директории: ')
11
    return input_dir, output_dir
12
13
14
def start_interactive():
15
    """Запуск интерактивного режима."""
16
    answers = ask_paths()
17
    input_dir = answers[0]
18
    output_dir = answers[1]
19
    if input_dir is None or output_dir is None:
20
        print('Не указана начальная или конечная директория')
21
        return
22
    elif input_dir == output_dir:
23
        print('Начальная и конечная директории не должны совпадать')
24
        return
25
    else:
26
        main_process(input_dir, output_dir)
27
28
29
def main_process(input_dir, output_dir):
30
    """Принимает начальную и конечную директории, запускает копирование.
31
32
    Параметры
33
    ----------
34
    input_dir : string
35
        Путь начальной директории в виде строки.
36
    output_dir : string
37
        Путь конечной директории в виде строки.
38
39
    Не возвращает результатов.
40
    -------
41
    """
42
    pass
43
44
45
start_interactive()
46
exit()
47
48
for path, subdirs, files in os.walk(input_dir):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable input_dir does not seem to be defined.
Loading history...
49
    for file in files:
50
        # Перегоняем все MP3 в целевую директорию,
51
        # потом разберемся что с ними делать
52
        # Хотя, лучше искать только нужные (отбрасывать лайвы и ремиксы
53
        # и перегонять уже без них)
54
        filtered = re.search('.*mp3', file)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable re does not seem to be defined.
Loading history...
55
        if filtered is not None:
56
            print(f'{path}/{filtered.group(0)}')
57
            shutil.copyfile(f'{path}/{filtered.group(0)}',
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable shutil does not seem to be defined.
Loading history...
58
                            f'{output_dir}/{filtered.group(0)}')
59
60
source_file = []
61
# 3.1. Удаление ремиксов и лайвов
62
regex = r'.*\(.*[Rr]emix.*\).*|.*\(.*[Ll]ive.*\).*'
63
for files in os.walk(output_dir):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable output_dir does not seem to be defined.
Loading history...
64
    for file in files[2]:
65
        try:
66
            source_file.append(re.search(regex, file).group(0))
67
        except Exception:
68
            pass
69
for file in source_file:
70
    print('Removing Remix: ', file)
71
    os.remove(f'{output_dir}/{file}')
72
source_file.clear()  # Очищаем список
73
74
# 3.2. Готовим список свежепринесенных файлов с вычищенными ремиксами и лайвами
75
for files in os.walk(output_dir):
76
    for file in files[2]:
77
        try:
78
            source_file.append(file)
79
        except Exception:
80
            pass
81
82
# 3.3. Убираем из имен файлов мусор (номера треков в различном формате)
83
for file in source_file:
84
    new_file = re.sub(r'^[\d{1,2}\s\-\.]*', '', file)
85
    shutil.move(f'{output_dir}/{file}', f'{output_dir}/{new_file}')
86
source_file.clear()
87