diff --git a/beets/importer.py b/beets/importer.py index b7bfdb156..38d2a4e62 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -1054,6 +1054,12 @@ class ArchiveImportTask(SentinelImportTask): pass else: cls._handlers.append((is_rarfile, RarFile)) + try: + from py7zr import is_7zfile, SevenZipFile + except ImportError: + pass + else: + cls._handlers.append((is_7zfile, SevenZipFile)) return cls._handlers diff --git a/docs/changelog.rst b/docs/changelog.rst index 6d99dbc89..b3447b936 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -216,6 +216,10 @@ Other new things: ``check_on_import`` config option. * :doc:`/plugins/export`: big speedups when `--include-keys` option is used Thanks to :user:`ssssam`. +* Added 7z support via the `py7zr`_ library + Thanks to :user:`arogl`. :bug:`3906` + + .. _py7zr: https://pypi.org/project/py7zr/ Fixes: diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index d450b299a..0be752eab 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -67,7 +67,7 @@ albums (the latter case is true of typical Artist/Album organizations and many people's "downloads" folders). The path can also be a single song or an archive. Beets supports `zip` and `tar` archives out of the box. To extract `rar` files, install the `rarfile`_ package and the -`unrar` command. +`unrar` command. To extract `7z` files, install the `py7zr`_ package. Optional command flags: @@ -152,6 +152,7 @@ Optional command flags: beet import --set genre="Alternative Rock" --set mood="emotional" .. _rarfile: https://pypi.python.org/pypi/rarfile/ +.. _py7zr: https://pypi.org/project/py7zr/ .. only:: html diff --git a/setup.py b/setup.py index 8191d3888..ca0dc819d 100755 --- a/setup.py +++ b/setup.py @@ -130,7 +130,9 @@ setup( ] + [ 'discogs-client' if (sys.version_info < (3, 0, 0)) else 'python3-discogs-client' - ], + ] + ( + ['py7zr'] if (sys.version_info > (3, 5, 0)) else [] + ), 'lint': [ 'flake8', 'flake8-coding', diff --git a/test/rsrc/archive.7z b/test/rsrc/archive.7z new file mode 100644 index 000000000..6a09fdf4b Binary files /dev/null and b/test/rsrc/archive.7z differ diff --git a/test/test_importer.py b/test/test_importer.py index 3418d4628..48cb23378 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -450,6 +450,12 @@ class ImportRarTest(ImportZipTest): return os.path.join(_common.RSRC, b'archive.rar') +class Import7zTest(ImportZipTest): + + def create_archive(self): + return os.path.join(_common.RSRC, b'archive.7z') + + @unittest.skip('Implement me!') class ImportPasswordRarTest(ImportZipTest):