Skip to content

Commit

Permalink
Import rar archives
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Scholtes committed Apr 15, 2014
1 parent e3acdd0 commit 68595ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ def prune(self, filename):


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)
Expand Down Expand Up @@ -582,6 +586,13 @@ def handlers(cls):
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):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def _read(fn):
'echonest_tempo': ['pyechonest'],
'lastgenre': ['pylast'],
'web': ['flask'],
'import': ['rarfile'],
},
# Non-Python/non-PyPI plugin dependencies:
# replaygain: mp3gain || aacgain
Expand Down
Binary file added test/rsrc/archive.rar
Binary file not shown.
13 changes: 13 additions & 0 deletions test/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ def create_archive(self):
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.
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ deps =
flask
responses
pyechonest
rarfile
commands =
nosetests {posargs}

Expand Down

0 comments on commit 68595ee

Please sign in to comment.