Skip to content

Commit

Permalink
Fix bad frames detection in stats plugin for python3 (#113)
Browse files Browse the repository at this point in the history
Comparison of string vs binary string was preventing detection of private frames
in stats plugin.
  • Loading branch information
gaetano-guerriero authored and nicfit committed Oct 31, 2017
1 parent 6916b24 commit f1d7160
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/eyed3/plugins/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from eyed3.utils import guessMimetype
from eyed3.utils.console import Fore, Style, printMsg
from eyed3.plugins import LoaderPlugin
from eyed3.id3.frames import ImageFrame
from eyed3.id3 import frames

ID3_VERSIONS = [id3.ID3_V1_0, id3.ID3_V1_1,
id3.ID3_V2_2, id3.ID3_V2_3, id3.ID3_V2_4]
Expand Down Expand Up @@ -150,7 +150,7 @@ def test(self, path, audio_file):
return None


BAD_FRAMES = ["PRIV", "GEOB"]
BAD_FRAMES = [frames.PRIVATE_FID, frames.OBJECT_FID]


class Id3FrameRules(Rule):
Expand All @@ -162,9 +162,10 @@ def test(self, path, audio_file):
tag = audio_file.tag
for fid in tag.frame_set:
if fid[0] == 'T' and fid != "TXXX" and len(tag.frame_set[fid]) > 1:
scores.append((-10, "Multiple %s frames" % fid))
scores.append((-10, "Multiple %s frames" % fid.decode('ascii')))
elif fid in BAD_FRAMES:
scores.append((-13, "%s frames are bad, mmmkay?" % fid))
scores.append((-13, "%s frames are bad, mmmkay?" %
fid.decode('ascii')))

return scores

Expand Down Expand Up @@ -381,8 +382,8 @@ def __init__(self):
super(Id3ImageTypeCounter, self).__init__()

self._key_names = {}
for attr in dir(ImageFrame):
val = getattr(ImageFrame, attr)
for attr in dir(frames.ImageFrame):
val = getattr(frames.ImageFrame, attr)
if isinstance(val, int) and not attr.endswith("_TYPE"):
self._key_names[val] = attr

Expand Down
32 changes: 32 additions & 0 deletions src/test/test_stats_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import unicode_literals
import os
import tempfile
import unittest

import eyed3.id3
import eyed3.main

from . import RedirectStdStreams


class TestId3FrameRules(unittest.TestCase):
def test_bad_frames(self):
try:
fd, tempf = tempfile.mkstemp(suffix='.id3')
os.close(fd)
tagfile = eyed3.id3.TagFile(tempf)
tagfile.initTag()
tagfile.tag.title = 'mytitle'
tagfile.tag.privates.set(b'mydata', b'onwer0')
tagfile.tag.save()
args = ['--plugin', 'stats', tempf]
args, _, config = eyed3.main.parseCommandLine(args)

with RedirectStdStreams() as out:
eyed3.main.main(args, config)
finally:
os.remove(tempf)

print(out.stdout.getvalue())

self.assertIn('PRIV frames are bad', out.stdout.getvalue())

0 comments on commit f1d7160

Please sign in to comment.