-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
169 lines (126 loc) · 4.83 KB
/
notes.txt
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
stray files ...
lets ignore pdfs
.wav
.pl
------------------------
#!/usr/bin/env python
""" Extracts album art from an MP3 file. Album art is assumed to be in JPEG format. Only the first artwork found is extracted.
Usage: apic-extract mp3-filename [jpg-filename]
(the default value for jpg-filename is "albumart.jpg")
Dependencies: mutagen.mp3
You can also import this as a module (rename it first?) and call
apic_extract yourself.
"""
ze: 51,488,741,676
51,438,410,640
import os
import sys
import mutagen.mp3
def apic_extract(mp3, jpg=None):
"""Extracts album art from a given MP3 file. Output is raw JPEG data.
jpg (optional) specifies a filename to write the image to instead of returning
it. Returns True if this is specified.
If more than one artwork frame exists, then only the first one encountered will
be used.
dfa
Returns False if mp3 can't be opened, and None if no art was found.
"""
try:
tags = mutagen.mp3.Open(mp3)
except:
return False
data = ""
for i in tags:
if i.startswith("APIC"):
data = tags[i].data
break
if not data:
return None
if jpg != None:
out = open(jpg, "w")
out.write(data)
out.close()
return True
return data
if __name__ == "__main__":
if len(sys.argv) < 2 or len(sys.argv) > 3:
print "Usage: %s mp3-filename [jpg-filename]" % os.path.basename(sys.argv[0])
print "(the default value for jpg-filename is \"albumart.jpg\")"
sys.exit(2)
mp3_filename = sys.argv[1]
jpg_filename = "albumart.jpg"
if len(sys.argv) == 3:
jpg_filename = sys.argv[2]
status = apic_extract(mp3_filename, jpg_filename)
if status == False:
print "\"%s\" could not be opened or is not a valid MP3 file" % mp3_filename
elif status == None:
print "\"%s\" does not contain artwork" % mp3_filename
/////////////////////////////////////
(musictags-nVG5Fzdp) robertm@sys76:~/programming/musictags$ python tag2.py level=debug
2018-08-19 05:29:51 - DEBUG - Entering main
dict_keys(['TIT2', 'TPE1', 'TALB', 'TRCK', 'TCON', 'COMM::\x00\x00\x00', 'TDRC'])
{'TIT2': TIT2(encoding=<Encoding.LATIN1: 0>, text=['I Need A Dollar']), 'TPE1': TPE1(encoding=<Encoding.LATIN1: 0>, text=['Aloe Blacc']), 'TALB': TALB(encoding=<Encoding.LATIN1: 0>, text=['Good Things']), 'TRCK': TRCK(encoding=<Encoding.LATIN1: 0>, text=['01']), 'TCON': TCON(encoding=<Encoding.LATIN1: 0>, text=['R&B']), 'COMM::\x00\x00\x00': COMM(encoding=<Encoding.LATIN1: 0>, lang='\x00\x00\x00', desc='', text=['Amazon.com Song ID: 21801727']), 'TDRC': TDRC(encoding=<Encoding.LATIN1: 0>, text=['2010'])}
(musictags-nVG5Fzdp) robertm@sys76:~/programming/musictags$
/////////////////////////
Here's how I was able to pull it off.
no pic found: /home/robertm/tmp/MOZART/FINISHED/Serenata Notturna in D - K239/Serenata Notturna in D - K239.flac
Traceback (most recent call last):
File "find.flac.files.py", line 53, in <module>
main()
File "find.flac.files.py", line 42, in main
print(f'{size:10,} --> {f}')
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcfc' in position 46: surrogates not allowed
(musictags-nVG5Fzdp) [10:29] robertm -- /home/robertm/programming/musictags $ python find.flac.files.py >flac.out.txt
(musictags-nVG5Fzdp) [10:29] robertm -- /home/robertm/programming/musictags $
///////////////////////////////////////////////////
First, get access to the file in Mutagen:
audio = MP3("filename.mp3")
Then, get a reference to the tag you're looking for:
picturetag = audio.tags['APIC:Folder.jpg']
Then, modify the type attribute:
picturetag.type = 3
Then, assign it back into the audio file, just to be sure
audio.tags['APIC:Folder.jpg'] = picturetag
Finally, save it!
audio.save()
//////////////////////////////////////
#
# ttl files processed: 5061
# ttl file size: 42,943,464,128
# ttl over sized covers: 560
#
# ttl files processed: 5061
# ttl file size: 42,942,171,840
# ttl over sized covers: 548
# ttl files processed: 5061
# # ttl file size: 42,932,568,362
# # ttl over sized covers: 457
# ttl files processed: 5061
# ttl file size: 42,912,593,038
# ttl over sized covers: 280
///////////////////////////////////////////////////
Yeah unfortunately Windows doesn't support that version.
Instead of just saving it in ID3v1 try saving it in ID3v3
and ID3v1. I use this in my programs and it works great in Windows 8 and OSX.
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error, TRCK, TIT2, TPE1, TALB, TDRC, TCON
audio = MP3([PATH_TO_FILE], ID3=ID3)
audio.tags.delete([PATH_TO_FILE], delete_v1=True, delete_v2=True)
audio.tags.add(
APIC(
encoding=3,
mime='image/jpeg',
type=3,
desc=u'Cover',
data=open([PATH_TO_COVER_IMAGE], 'rb').read()
)
)
audio.save([PATH_TO_FILE], v2_version=3, v1=2)
////////////////////
assed_Off!.8z5d.jpg
Brassed Off!
Various
/home/robertm/Desktop/mut/Brassed_Off!.8q7s.jpg
ttl_tracks_processed: 8665
ttl_file_size: 258,730,484,963