-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_process_music.py
71 lines (61 loc) · 2.46 KB
/
android_process_music.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
import eyed3
import os
import shutil
import mutagen
from mutagen.oggopus import OggOpus
from mutagen.oggvorbis import OggVorbis
from mutagen.mp4 import MP4
from mutagen.id3 import APIC, ID3
import re
import sys
# sys.stdout.reconfigure(encoding='utf-8')
eyed3.log.setLevel("ERROR")
print("Current working directory: {0}".format(os.getcwd()))
music_folder = "to process"
to_output_to = "output"
def relabel_ogg_artist(filename, new_artist):
audiofile = OggVorbis(filename)
print(audiofile.tags["artist"])
audiofile.update(artist=new_artist)
audiofile.save()
class process:
def __init__(self):
if not os.path.exists(music_folder):
os.mkdir(music_folder)
self.music_list = self.load_mp3s()
print("loading", self.music_list)
self.remove_artwork()
def load_mp3s(self):
return [os.path.join(music_folder, path) for path in os.listdir(os.path.join(os.getcwd(), music_folder))]
def remove_artwork(self):
for audio in self.music_list:
if audio.endswith(".mp3") or audio.endswith(".aac"):
mp3 = ID3(audio)
mp3.delall("APIC")
mp3.save()
artist_name = mp3['TPE1'].text[0]
if artist_name is None:
artist_name = mp3.tag.artist
process.sort_folders(audio, artist_name)
elif audio.endswith(".m4a"):
process.sort_folders(audio, MP4(audio).tags["©ART"][0])
elif audio.endswith(".opus"):
process.sort_folders(audio, OggOpus(audio).tags["artist"][0])
elif audio.endswith(".ogg"):
audiofile = OggVorbis(audio)
for tag in ("metadata_block_picture", "comment"):
if tag in audiofile.keys():
audiofile.__delitem__(tag)
audiofile.save()
process.sort_folders(audio, audiofile.tags["artist"][0])
@staticmethod
def sort_folders(audio_location, artist_name=None):
artist_name = re.sub("[:|\\|\/|\*|\"|<|>|\|]", "", artist_name)
print(artist_name)
where_to_output = os.path.join(to_output_to, artist_name)
if not os.path.exists(where_to_output):
os.makedirs(where_to_output)
shutil.move(audio_location, os.path.join(
where_to_output, os.path.basename(audio_location)))
# rename("梶浦 由記 - アンチヒーロー〜Main Theme〜.ogg", "Yuki Kajiura")
process()