diff --git a/beets/importer.py b/beets/importer.py index d31fd1a11..61ff1294a 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -548,6 +548,10 @@ class ImportTask(object): class ArchiveImportTask(ImportTask): + """Additional methods for handling archives. + + Use when `toppath` points to a `zip`, `tar`, or `rar` archive. + """ def __init__(self, toppath): super(ArchiveImportTask, self).__init__(toppath) @@ -582,6 +586,13 @@ class ArchiveImportTask(ImportTask): cls._handlers.append((is_zipfile, ZipFile)) from tarfile import is_tarfile, TarFile cls._handlers.append((is_tarfile, TarFile)) + try: + from rarfile import is_rarfile, RarFile + except ImportError: + pass + else: + cls._handlers.append((is_rarfile, RarFile)) + return cls._handlers def cleanup(self): diff --git a/setup.py b/setup.py index e2c917121..c602d275f 100755 --- a/setup.py +++ b/setup.py @@ -99,6 +99,7 @@ setup( 'echonest_tempo': ['pyechonest'], 'lastgenre': ['pylast'], 'web': ['flask'], + 'import': ['rarfile'], }, # Non-Python/non-PyPI plugin dependencies: # replaygain: mp3gain || aacgain diff --git a/test/rsrc/archive.rar b/test/rsrc/archive.rar new file mode 100644 index 000000000..e51051155 Binary files /dev/null and b/test/rsrc/archive.rar differ diff --git a/test/test_importer.py b/test/test_importer.py index 854b21d4b..d6b211c2d 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -342,6 +342,19 @@ class ImportTarTest(ImportZipTest): return path +class ImportRarTest(ImportZipTest): + + def create_archive(self): + return os.path.join(_common.RSRC, 'archive.rar') + + +@unittest.skip('Implment me!') +class ImportPasswordRarTest(ImportZipTest): + + def create_archive(self): + return os.path.join(_common.RSRC, 'password.rar') + + class ImportSingletonTest(_common.TestCase, ImportHelper): """Test ``APPLY`` and ``ASIS`` choices for an import session with singletons config set to True. diff --git a/tox.ini b/tox.ini index 5e50071c6..e84f536ac 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,7 @@ deps = flask responses pyechonest + rarfile commands = nosetests {posargs}