-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (45 loc) · 1.79 KB
/
main.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
# -*- coding: utf-8 -*-
import os
import re
import tag_walker
from web_walker import WebWalker
def get_audio_files(directory=None, extensions=['.mp3']):
if not directory:
directory = input('Podaj ścieżkę do folderu: ')
audio_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if any(file.endswith(ext) for ext in extensions):
audio_files.append(os.path.join(root, file))
return audio_files
def verify_zaiks_structure(zaiks):
return bool(re.match(r'\d{7}', zaiks))
def find_em_all(path):
ww = WebWalker()
audio_files = get_audio_files(path)
for song in audio_files:
print(song)
zaiks = tag_walker.get_zaiks(song)
if zaiks:
if verify_zaiks_structure(zaiks):
print(f'Numer o poprawnej strukturze już znajduje się w metadanych - {zaiks}')
continue
band_name = tag_walker.get_band_name(song)
song_title = tag_walker.get_song_title(song)
print(f'{band_name} - {song_title}: ', end='')
if band_name and song_title:
ww.open_chrome()
try:
if len(song) > 60:
zaiks = ww.get_id(band_name=band_name, song_title=song_title[:60])
else:
zaiks = ww.get_id(band_name=band_name, song_title=song_title)
tag_walker.set_zaiks(song, zaiks)
except Exception as e:
print(e)
with open('not found.txt', 'a+', encoding='utf-8') as f:
f.write(f'{band_name} - {song_title}: wystąpił problem\n')
else:
print(f'No tags for {song}')
with open('not found.txt', 'a+', encoding='utf-8') as f:
f.write(f'No tags for {song}\n')