Skip to content

Commit 68595ee

Browse files
author
Thomas Scholtes
committed
Import rar archives
1 parent e3acdd0 commit 68595ee

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

beets/importer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ def prune(self, filename):
548548

549549

550550
class ArchiveImportTask(ImportTask):
551+
"""Additional methods for handling archives.
552+
553+
Use when `toppath` points to a `zip`, `tar`, or `rar` archive.
554+
"""
551555

552556
def __init__(self, toppath):
553557
super(ArchiveImportTask, self).__init__(toppath)
@@ -582,6 +586,13 @@ def handlers(cls):
582586
cls._handlers.append((is_zipfile, ZipFile))
583587
from tarfile import is_tarfile, TarFile
584588
cls._handlers.append((is_tarfile, TarFile))
589+
try:
590+
from rarfile import is_rarfile, RarFile
591+
except ImportError:
592+
pass
593+
else:
594+
cls._handlers.append((is_rarfile, RarFile))
595+
585596
return cls._handlers
586597

587598
def cleanup(self):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def _read(fn):
9999
'echonest_tempo': ['pyechonest'],
100100
'lastgenre': ['pylast'],
101101
'web': ['flask'],
102+
'import': ['rarfile'],
102103
},
103104
# Non-Python/non-PyPI plugin dependencies:
104105
# replaygain: mp3gain || aacgain

test/rsrc/archive.rar

2.3 KB
Binary file not shown.

test/test_importer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,19 @@ def create_archive(self):
342342
return path
343343

344344

345+
class ImportRarTest(ImportZipTest):
346+
347+
def create_archive(self):
348+
return os.path.join(_common.RSRC, 'archive.rar')
349+
350+
351+
@unittest.skip('Implment me!')
352+
class ImportPasswordRarTest(ImportZipTest):
353+
354+
def create_archive(self):
355+
return os.path.join(_common.RSRC, 'password.rar')
356+
357+
345358
class ImportSingletonTest(_common.TestCase, ImportHelper):
346359
"""Test ``APPLY`` and ``ASIS`` choices for an import session with singletons
347360
config set to True.

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ deps =
1414
flask
1515
responses
1616
pyechonest
17+
rarfile
1718
commands =
1819
nosetests {posargs}
1920

0 commit comments

Comments
 (0)