-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_ext.py
81 lines (63 loc) · 1.97 KB
/
all_ext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Para leer metadatos
import eyed3
import time
# Para navegar por los directorios
import os
# Para copiar y mover archivos
import shutil
from utils.file_loader import (
database_mp3,
database_mp4,
database_flac,
metadata_mp3,
metadata_mp4,
metadata_flac,
folder_creator,
printProgressBar,
name_cleaning,
name_creator,
)
cwd = os.getcwd()
print(cwd)
new_folder = f"{cwd}\\Music_library"
try:
os.mkdir(new_folder)
except:
print("Ya existe una carpeta con este nombre.")
# Por fines del development borro la carpeta si ya existe
# debo quitar esto en producción.
shutil.rmtree(new_folder)
os.mkdir(new_folder)
list_mp3 = database_mp3()
list_mp4 = database_mp4()
list_flac = database_flac()
t0 = time.perf_counter()
for i, filename in enumerate(list_flac):
file_path = f"{cwd}\\{filename}"
title, artist, album = metadata_flac(file_path)
new_file_name = name_creator(title, artist, album, new_folder)
new_file_path = f"{new_folder}\\{artist}\\{album}\\{new_file_name}.flac"
shutil.copy2(file_path, new_file_path)
print(title, i)
# 166
# Tiempo del script 140.6982674000028s sincrónico
# 98
for i, filename in enumerate(list_mp4):
file_path = f"{cwd}\\{filename}"
title, artist, album = metadata_mp4(file_path)
new_file_name = name_creator(title, artist, album, new_folder)
new_file_path = f"{new_folder}\\{artist}\\{album}\\{new_file_name}.m4a"
shutil.copy2(file_path, new_file_path)
print(title, i)
for i, filename in enumerate(list_mp3):
file_path = f"{cwd}\\{filename}"
title, artist, album = metadata_mp3(file_path)
new_file_name = name_creator(title, artist, album, new_folder)
new_file_path = f"{new_folder}\\{artist}\\{album}\\{new_file_name}.mp3"
if len(new_file_path) > 256:
new_file_path = f"{new_file_path[:251]}.mp3"
shutil.copy2(file_path, new_file_path)
print(title, i)
tf = time.perf_counter()
print(tf - t0)
# 1986 MP3, 18 m4a, 166flac