Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jean-Francois Dockes
recoll
Commits
d35c2a55
Commit
d35c2a55
authored
Feb 27, 2017
by
Jean-Francois Dockes
Browse files
Process a few non-standard tag names found in the wild + check for embedded images
parent
ba350d68
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/filters/rclaudio
View file @
d35c2a55
...
...
@@ -7,6 +7,7 @@ import os
import
rclexecm
try
:
import
mutagen
from
mutagen
import
File
from
mutagen.id3
import
ID3TimeStamp
except
:
...
...
@@ -63,6 +64,8 @@ tagdict = {
'TPOS'
:
'DISCNUMBER'
,
'TPUB'
:
'LABEL'
,
'TXXX:ORCHESTRA'
:
'ORCHESTRA'
,
'ORCHESTRA'
:
'ORCHESTRA'
,
'ENSEMBLE'
:
'ORCHESTRA'
,
'TRC'
:
'ISRC'
,
'TRCK'
:
'TRACKNUMBER'
,
'TRK'
:
'TRACKNUMBER'
,
...
...
@@ -84,6 +87,7 @@ tagdict = {
'TXT'
:
'LYRICIST'
,
'TYE'
:
'DATE'
,
'TYER'
:
'DATE'
,
'YEAR'
:
'DATE'
,
'ULT'
:
'LYRICS'
,
'USLT'
:
'LYRICS'
,
'aART'
:
'ALBUMARTIST'
,
...
...
@@ -110,7 +114,8 @@ tagdict = {
'
\xa9
ope'
:
'ORIGINALARTIST'
,
'
\xa9
too'
:
'ENCODEDBY'
,
'
\xa9
wrt'
:
'COMPOSER'
,
'ALBUM'
:
'ALBUM'
,
'ALBUM'
:
'ALBUM'
,
'ALBUM ARTIST'
:
'ALBUMARTIST'
,
'ALBUMARTIST'
:
'ALBUMARTIST'
,
'ALBUMARTISTSORT'
:
'ALBUMARTISTSORT'
,
'ALBUMSORT'
:
'ALBUMSORT'
,
...
...
@@ -140,9 +145,13 @@ tagdict = {
'RELEASEDATE'
:
'RELEASEDATE'
,
'REMIXER'
:
'REMIXER'
,
'SUBTITLE'
:
'SUBTITLE'
,
'DISCTOTAL'
:
'TOTALDISCS'
,
'TOTALDISCS'
:
'TOTALDISCS'
,
'TOTALTRACKS'
:
'TOTALTRACKS'
,
'TRACKTOTAL'
:
'TOTALTRACKS'
,
'TRACKNUMBER'
:
'TRACKNUMBER'
,
'TRACKNUM'
:
'TRACKNUMBER'
,
'TRACK'
:
'TRACKNUMBER'
,
'TITLE'
:
'TITLE'
,
'TITLESORT'
:
'TITLESORT'
,
}
...
...
@@ -160,7 +169,31 @@ class AudioTagExtractor:
for
prop
in
dir
(
mutf
.
info
):
self
.
em
.
rclog
(
"mutinfo: %s -> %s"
%
(
prop
,
getattr
(
mutf
.
info
,
prop
)))
def
_printableFilename
(
self
):
return
self
.
filename
.
decode
(
'utf-8'
,
errors
=
'replace'
)
def
_embeddedImageFormat
(
self
,
mutf
):
#self.em.rclog("_embeddedImage: MIME: %s"%mutf.mime)
if
'audio/mp3'
in
mutf
.
mime
:
for
tagname
in
mutf
.
iterkeys
():
if
tagname
.
startswith
(
'APIC:'
):
#self.em.rclog("mp3 img: %s" % mutf[tagname].mime)
return
'jpg'
if
mutf
[
tagname
].
mime
==
'image/jpeg'
else
'png'
elif
'audio/x-flac'
in
mutf
.
mime
:
if
mutf
.
pictures
:
return
'jpg'
if
mutf
.
pictures
[
0
].
mime
==
'image/jpeg'
else
'png'
elif
'audio/mp4'
in
mutf
.
mime
:
if
'covr'
in
mutf
.
iterkeys
():
format
=
mutf
[
'covr'
][
0
].
imageformat
if
format
==
mutagen
.
mp4
.
AtomDataType
.
JPEG
:
return
'jpg'
else
:
return
'png'
return
''
def
extractone
(
self
,
params
):
#self.em.rclog("extractone %s %s" % (params["filename:"],
...
...
@@ -172,6 +205,7 @@ class AudioTagExtractor:
return
(
ok
,
docdata
,
""
,
rclexecm
.
RclExecM
.
eofnow
)
filename
=
params
[
"filename:"
]
mimetype
=
params
[
"mimetype:"
]
self
.
filename
=
filename
try
:
mutf
=
File
(
filename
)
except
Exception
as
err
:
...
...
@@ -219,6 +253,8 @@ class AudioTagExtractor:
# just have a big translation dictionary for all
for
tag
,
val
in
mutf
.
iteritems
():
#self.em.rclog("Original tag: <%s>, val <%s>" % (tag, val))
if
tag
.
upper
()
in
tagdict
:
tag
=
tag
.
upper
()
if
tag
in
tagdict
:
ntag
=
tagdict
[
tag
].
lower
()
#self.em.rclog("New tag: %s" % ntag)
...
...
@@ -234,6 +270,9 @@ class AudioTagExtractor:
#self.em.rclog("Tag %s -> %s" % (ntag, val0))
except
Exception
as
err
:
self
.
em
.
rclog
(
"Error while extracting tag: %s"
%
err
)
else
:
pass
#self.em.rclog("Unprocessed tag: %s, value %s"%(tag,val))
# TPA,TPOS,disc DISCNUMBER/TOTALDISCS
# TRCK,TRK,trkn TRACKNUMBER/TOTALTRACKS
...
...
@@ -253,9 +292,16 @@ class AudioTagExtractor:
minf
[
'orchestra'
]
=
val
[
10
:]
#self.em.rclog("minf after tags %s\n" % minf)
# Check for embedded image. We just set a flag.
embdimg
=
self
.
_embeddedImageFormat
(
mutf
)
if
embdimg
:
#self.em.rclog("Embedded image format: %s" % embdimg)
minf
[
"embdimg"
]
=
embdimg
self
.
em
.
setmimetype
(
"text/plain"
)
self
.
em
.
setfield
(
"charset"
,
'utf-8'
)
for
tag
,
val
in
minf
.
iteritems
():
#self.em.rclog("%s -> %s" % (tag, val))
self
.
em
.
setfield
(
tag
,
val
)
...
...
@@ -263,7 +309,6 @@ class AudioTagExtractor:
if
tag
==
'artist'
:
self
.
em
.
setfield
(
'author'
,
val
)
try
:
docdata
=
mutf
.
pprint
().
encode
(
'utf-8'
,
errors
=
'replace'
)
except
Exception
as
err
:
...
...
@@ -272,13 +317,16 @@ class AudioTagExtractor:
ok
=
True
return
(
ok
,
docdata
,
""
,
rclexecm
.
RclExecM
.
eofnext
)
###### File type handler api, used by rclexecm ---------->
def
openfile
(
self
,
params
):
self
.
currentindex
=
0
return
True
def
getipath
(
self
,
params
):
return
self
.
extractone
(
params
)
def
getnext
(
self
,
params
):
if
self
.
currentindex
>=
1
:
...
...
@@ -288,6 +336,7 @@ class AudioTagExtractor:
self
.
currentindex
+=
1
return
ret
def
makeObject
():
print
(
"makeObject"
);
proto
=
rclexecm
.
RclExecM
()
...
...
@@ -295,6 +344,7 @@ def makeObject():
extract
=
AudioTagExtractor
(
proto
)
return
17
if
__name__
==
'__main__'
:
proto
=
rclexecm
.
RclExecM
()
extract
=
AudioTagExtractor
(
proto
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment