Skip to content

Commit

Permalink
new: Composer (TCOM) support
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Nov 18, 2017
1 parent d7f1711 commit 14a0cc2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 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
17 changes: 14 additions & 3 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,20 +743,23 @@ 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,
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, ))
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

0 comments on commit 14a0cc2

Please sign in to comment.