Skip to content

Commit

Permalink
chg: less annoyances when dealing with unique file IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Feb 12, 2017
1 parent bb13735 commit 85bba0a
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/eyed3/id3/tag.py
Expand Up @@ -1527,8 +1527,8 @@ def match_func(frame, owner_id):
super(UniqueFileIdAccessor, self).__init__(frames.UNIQUE_FILE_ID_FID,
fs, match_func)

@requireBytes(1, 2)
def set(self, data, owner_id):
data, owner_id = b(data), b(owner_id)
if len(data) > 64:
raise TagException("UFID data must be 64 bytes or less")

Expand All @@ -1544,12 +1544,12 @@ def set(self, data, owner_id):
self._fs[frames.UNIQUE_FILE_ID_FID] = uniq_id_frame
return uniq_id_frame

@requireBytes(1)
def remove(self, owner_id):
owner_id = b(owner_id)
return super(UniqueFileIdAccessor, self).remove(owner_id)

@requireBytes(1)
def get(self, owner_id):
owner_id = b(owner_id)
return super(UniqueFileIdAccessor, self).get(owner_id)


Expand Down
110 changes: 110 additions & 0 deletions src/test/test_classic_plugin.py
Expand Up @@ -381,6 +381,116 @@ def testNewTagPublisher(self):
assert_is_not_none(af.tag)
assert_equal(af.tag.publisher, expected)

def testUniqueFileId_1(self):
with RedirectStdStreams() as out:
assert out
args, _, config = main.parseCommandLine(["--unique-file-id",
"Travis:Me",
self.test_file])
retval = main.main(args, config)
assert retval == 0

af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == 1
assert af.tag.unique_file_ids.get("Travis").uniq_id == b"Me"

def testUniqueFileId_dup(self):
with RedirectStdStreams() as out:
assert out
args, _, config = \
main.parseCommandLine(["--unique-file-id", "Travis:Me",
"--unique-file-id=Travis:Me",
self.test_file])
retval = main.main(args, config)
assert retval == 0

af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == 1
assert af.tag.unique_file_ids.get("Travis").uniq_id == b"Me"

def testUniqueFileId_N(self):
# Add 3
with RedirectStdStreams() as out:
assert out
args, _, config = \
main.parseCommandLine(["--unique-file-id", "Travis:Me",
"--unique-file-id=Engine:Kid",
"--unique-file-id", "Owner:Kid",
self.test_file])
retval = main.main(args, config)
assert retval == 0

af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == 3
assert af.tag.unique_file_ids.get("Travis").uniq_id == b"Me"
assert af.tag.unique_file_ids.get("Engine").uniq_id == b"Kid"
assert af.tag.unique_file_ids.get(b"Owner").uniq_id == b"Kid"

# Remove 2
with RedirectStdStreams() as out:
assert out
args, _, config = \
main.parseCommandLine(["--unique-file-id", "Travis:",
"--unique-file-id=Engine:",
"--unique-file-id", "Owner:Kid",
self.test_file])
retval = main.main(args, config)
assert retval == 0

af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == 1

# Remove not found ID
with RedirectStdStreams() as out:
args, _, config = \
main.parseCommandLine(["--unique-file-id", "Travis:",
self.test_file])
retval = main.main(args, config)
assert retval == 0

sout = out.stdout.read()
assert "Unique file ID 'Travis' not found" in sout

af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == 1

def testUniqueFileId(self):
for expected, opts in [
([(b"Travis", b"Me")], ["--unique-file-id", "Travis:Me",
self.test_file]),
([(b"Travis", b"Me")], ["--unique-file-id", "Travis:Me",
"--unique-file-id=Travis:Me",
self.test_file]),
([(b"Travis", b"Me"),
(b"Me", b"Travis")], ["--unique-file-id", "Travis:Me",
"--unique-file-id=Me:Travis",
self.test_file]),
]:
with RedirectStdStreams() as out:
assert out
args, _, config = main.parseCommandLine(opts)
retval = main.main(args, config)
assert retval == 0

af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == len(expected)
for oid, fid in expected:
assert af.tag.unique_file_ids.get(oid).uniq_id == fid

# Removal
'''
with RedirectStdStreams() as out:
assert out
(args, _,
config) = main.parseCommandLine(["--unique-file-id",
expected[0][0]])
retval = main.main(args, config)
assert retval == 0
af = eyed3.load(self.test_file)
assert len(af.tag.unique_file_ids) == len(expected) - 1
'''

# TODO:
# --unique-file-id
# --add-lyrics, --remove-lyrics, --remove-all-lyrics
Expand Down

0 comments on commit 85bba0a

Please sign in to comment.