Skip to content

Commit

Permalink
new: Composer (TCOM) support (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit authored Nov 18, 2017
1 parent 3094a8a commit c12425c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/eyed3/id3/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FrameException(Error):
SUBTITLE_FID = b"TIT3" # noqa
ARTIST_FID = b"TPE1" # noqa
ALBUM_ARTIST_FID = b"TPE2" # noqa
COMPOSER_FID = b"TCOM" # noqa
ALBUM_FID = b"TALB" # noqa
TRACKNUM_FID = b"TRCK" # noqa
GENRE_FID = b"TCON" # noqa
Expand Down
15 changes: 15 additions & 0 deletions src/eyed3/id3/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ def _setAlbumArtist(self, val):
def _getAlbumArtist(self):
return self.getTextFrame(frames.ALBUM_ARTIST_FID)

@requireUnicode(1)
def _setComposer(self, val):
self.setTextFrame(frames.COMPOSER_FID, val)

def _getComposer(self):
return self.getTextFrame(frames.COMPOSER_FID)

@property
def composer(self):
return self._getComposer()

@composer.setter
def composer(self, v):
self._setComposer(v)

@requireUnicode(1)
def _setAlbum(self, val):
self.setTextFrame(frames.ALBUM_FID, val)
Expand Down
19 changes: 15 additions & 4 deletions src/eyed3/plugins/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def PositiveIntArg(i):
g.add_argument("--track-offset", type=int, dest="track_offset",
metavar="N", help=ARGS_HELP["--track-offset"])

g.add_argument("--composer", type=UnicodeArg, dest="composer",
metavar="STRING", help=ARGS_HELP["--composer"])
g.add_argument("-d", "--disc-num", type=PositiveIntArg, dest="disc_num",
metavar="NUM", help=ARGS_HELP["--disc-num"])
g.add_argument("-D", "--disc-total", type=PositiveIntArg,
Expand Down Expand Up @@ -575,7 +577,11 @@ def printTag(self, tag):
printMsg("%s: %s" % (boldText("title"), title))
printMsg("%s: %s" % (boldText("artist"), artist))
printMsg("%s: %s" % (boldText("album"), album))
printMsg("%s: %s" % (boldText("album artist"), tag.album_artist))
if tag.album_artist:
printMsg("%s: %s" % (boldText("album artist"),
tag.album_artist))
if tag.composer:
printMsg("%s: %s" % (boldText("composer"), tag.composer))

for date, date_label in [
(tag.release_date, "release date"),
Expand Down Expand Up @@ -737,21 +743,24 @@ def printTag(self, tag):
printMsg("\nTerms of Use (%s): %s" % (boldText("USER"),
tag.terms_of_use))

# --verbose
if self.args.verbose:
printMsg("-" * self.terminal_width)
printMsg("%d ID3 Frames:" % len(tag.frame_set))
for fid in tag.frame_set:
frames = tag.frame_set[fid]
num_frames = len(frames)
count = " x %d" % num_frames if num_frames > 1 else ""
total_bytes = 0
if not tag.isV1():
total_bytes = sum(
tuple(frame.header.data_size + frame.header.size
for frame in frames))
for frame in frames if frame.header))
else:
total_bytes = 30
printMsg("%s%s (%d bytes)" % (fid.decode("ascii"), count,
total_bytes))
if total_bytes:
printMsg("%s%s (%d bytes)" % (fid.decode("ascii"),
count, total_bytes))
printMsg("%d bytes unused (padding)" %
(tag.file_info.tag_padding_size, ))
else:
Expand Down Expand Up @@ -828,6 +837,7 @@ def handleEdits(self, tag):
self.args.tagging_date)),
("beats per minute", partial(tag._setBpm, self.args.bpm)),
("publisher", partial(tag._setPublisher, self.args.publisher)),
("composer", partial(tag._setComposer, self.args.composer)),
):
if setFunc.args[0] is not None:
printWarning("Setting %s: %s" % (what, setFunc.args[0]))
Expand Down Expand Up @@ -1169,4 +1179,5 @@ def _getTemplateKeys():
"modification times.",
"--track-offset": "Increment/decrement the track number by [-]N. "
"This option is applied after --track=N is set.",
"--composer": "Set the composer's name.",
}
12 changes: 10 additions & 2 deletions src/eyed3/plugins/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from argparse import ArgumentTypeError

from eyed3 import id3
from eyed3 import id3, compat
from eyed3.utils import console, formatSize, formatTime
from eyed3.plugins import LoaderPlugin
try:
Expand Down Expand Up @@ -63,7 +63,7 @@ def __compile(self):
self.sub_patterns = self.__compile_asts(asts)
self.__text = None
except BaseException as parsing_error:
raise PatternCompileException(parsing_error.message)
raise PatternCompileException(compat.unicode(parsing_error))

def __compile_asts(self, asts):
patterns = []
Expand Down Expand Up @@ -315,6 +315,14 @@ def _get_output_for(self, audio_file):
return audio_file.tag.album_artist


class ComposerTagPattern(TagPattern):
NAMES = ["C", "composer"]
DESCRIPTION = "Composer"

def _get_output_for(self, audio_file):
return audio_file.tag.composer


class TitleTagPattern(TagPattern):
NAMES = ["t", "title"]
DESCRIPTION = "Title"
Expand Down
15 changes: 15 additions & 0 deletions src/test/test_classic_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ def testNewTagArtist(self, version=id3.ID3_DEFAULT_VERSION):
assert af.tag is not None
assert af.tag.artist == u"The Cramps"

def testNewTagComposer(self, version=id3.ID3_DEFAULT_VERSION):
for opts in [ ["--composer=H.R.", self.test_file] ]:
self._addVersionOpt(version, opts)

with RedirectStdStreams() as out:
args, _, config = main.parseCommandLine(opts)
retval = main.main(args, config)
assert retval == 0

af = eyed3.load(self.test_file)
assert af is not None
assert af.tag is not None
assert af.tag.composer == u"H.R."

def testNewTagAlbum(self, version=id3.ID3_DEFAULT_VERSION):
for opts in [ ["-A", "Psychedelic Jungle", self.test_file],
["--album=Psychedelic Jungle", self.test_file] ]:
Expand Down Expand Up @@ -745,6 +759,7 @@ def test_all(audiofile, image, eyeD3):
"--fs-encoding=latin1",
"--no-config",
"--add-object", "{}:image/gif".format(image),
"--composer", "Cibo Matto",
])


Expand Down
7 changes: 6 additions & 1 deletion src/test/test_display_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def __init__(self, name):
def testSimpleTags(self):
self.file.tag.artist = u"The Artist"
self.file.tag.title = u"Some Song"
self.__checkOutput(u"%a% - %t%", u"The Artist - Some Song")
self.file.tag.composer = u"Some Composer"
self.__checkOutput(u"%a% - %t% - %C%", u"The Artist - Some Song - Some Composer")

def testComposer(self):
self.file.tag.composer = u"Bad Brains"
self.__checkOutput(u"%C% - %composer%", u"Bad Brains - Bad Brains")

def testCommentsTag(self):
self.file.tag.comments.set(u"TEXT", description=None, lang=b"DE")
Expand Down

0 comments on commit c12425c

Please sign in to comment.