Add support for flac files.

This commit is contained in:
Bastian Kleineidam 2012-05-17 21:22:56 +02:00
parent 52762df5c6
commit 36c2be760d
11 changed files with 83 additions and 12 deletions

View File

@ -2,6 +2,7 @@
* Added support for Monkey's Audio Compressor handling APE (.ape) files.
* Added support for shorten handling SHN (.shn) files.
* Added support for flac handling FLAC (.flac) files.
0.16 "Game of thrones" (released 12.5.2012)

View File

@ -32,9 +32,9 @@ by the archive file extension.
\fBpatool\fP supports 7z (.7z), ACE (.ace), ALZIP (.alz), APE (.ape), AR (.a),
ARC (.arc), ARJ (.arj),
BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio), DEB (.deb), DMS (.dms),
GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma),
LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), SHN (.shn), TAR (.tar),
XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo) formats.
FLAC (.flac), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz),
LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), SHN (.shn),
TAR (.tar), XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo) formats.
It relies on helper applications to handle those archive formats
(for example bzip2 for BZIP2 archives).
.PP

View File

@ -25,12 +25,12 @@ DESCRIPTION
patool supports 7z (.7z), ACE (.ace), ALZIP (.alz), APE (.ape),
AR (.a), ARC (.arc), ARJ (.arj), BZIP2 (.bz2), CAB (.cab), com
press (.Z), CPIO (.cpio), DEB (.deb), DMS (.dms), GZIP (.gz),
LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma), LZOP
(.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), SHN (.shn), TAR
(.tar), XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo) formats. It
relies on helper applications to handle those archive formats
(for example bzip2 for BZIP2 archives).
press (.Z), CPIO (.cpio), DEB (.deb), DMS (.dms), FLAC (.flac),
GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA
(.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), SHN
(.shn), TAR (.tar), XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo)
formats. It relies on helper applications to handle those ar
chive formats (for example bzip2 for BZIP2 archives).
The archive formats TAR (.tar), ZIP (.zip), BZIP2 (.bz2) and
GZIP (.gz) are supported natively and do not require helper

View File

@ -106,6 +106,10 @@ ArchivePrograms = {
'list': ('py_echo',),
},
'flac': {
'extract': ('flac',),
'test': ('flac',),
'create': ('flac',),
'list': ('py_echo',),
},
'tar': {
None: ('tar', 'star', 'py_tarfile'),

39
patoolib/programs/flac.py Normal file
View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Bastian Kleineidam
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the flac program."""
from patoolib import util
def extract_flac (archive, compression, cmd, **kwargs):
"""Decompress a FLAC archive to a WAV file."""
outfile = util.get_single_outfile(kwargs['outdir'], archive,
extension=".wav")
cmdlist = [cmd, '--decode', archive, '--output-name', outfile]
return cmdlist
def create_flac (archive, compression, cmd, *args, **kwargs):
"""Compress a WAV file to a FLAC archive."""
cmdlist = [cmd, args[0], '--output-name', archive]
return cmdlist
def test_flac (archive, compression, cmd, **kwargs):
"""Test a FLAC file."""
cmdlist = [cmd, '--test']
if not kwargs['verbose']:
cmdlist.append('-s')
cmdlist.append(archive)
return cmdlist

View File

@ -54,6 +54,10 @@ def list_shn (archive, compression, cmd, **kwargs):
"""List a SHN archive."""
return stripext(cmd, archive, extension=".wav")
def list_flac (archive, compression, cmd, **kwargs):
"""List a FLAC archive."""
return stripext(cmd, archive, extension=".wav")
def stripext (cmd, archive, extension=""):
"""Print the name without suffix."""
print util.stripext(archive)+extension

View File

@ -48,9 +48,10 @@ fallback by the archive file extension.
patool supports 7z (.7z), ACE (.ace), ALZIP (.alz), APE (.ape), AR (.a),
ARC (.arc), ARJ (.arj), BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio),
DEB (.deb), DMS (.dms), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh),
LZIP (.lz), LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz),
SHN (.shn), TAR (.tar), XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo) formats.
DEB (.deb), DMS (.dms), FLAC (.flac), GZIP (.gz), LRZIP (.lrz),
LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma), LZOP (.lzo), RPM (.rpm),
RAR (.rar), RZIP (.rz), SHN (.shn), TAR (.tar), XZ (.xz), ZIP (.zip, .jar)
and ZOO (.zoo) formats.
It relies on helper applications to handle those archive formats
(for example bzip2 for BZIP2 archives).

BIN
tests/data/t.flac.flac Normal file

Binary file not shown.

BIN
tests/data/t.flac.wav Normal file

Binary file not shown.

View File

@ -151,6 +151,7 @@ class TestArchives (ArchiveTest):
self.archive_list('t.txt.rz')
self.archive_list('t.ape')
self.archive_list('t.shn')
self.archive_list('t.flac')
@needs_program('unzip')
def test_unzip (self):
@ -453,3 +454,10 @@ class TestArchives (ArchiveTest):
self.program = 'shorten'
self.archive_extract('t.shn')
self.archive_create('t.shn', srcfile="t.wav")
@needs_program('flac')
def test_flac (self):
self.program = 'flac'
self.archive_extract('t.flac')
self.archive_test('t.flac')
self.archive_create('t.flac', srcfile="t.wav")

View File

@ -167,6 +167,12 @@ class TestArchives (ArchiveTest):
# file(1) does not recognize .lzma files
#self.archive_list('t.lzma.foo')
self.archive_list('t.txt.lz.foo')
self.archive_list('t.txt.lrz')
self.archive_list('t.txt.rz.foo')
self.archive_list('t.ape.foo')
# file(1) does not recognize .shn files
#self.archive_list('t.shn.foo')
self.archive_list('t.flac.foo')
@needs_program('file')
@needs_program('unzip')
@ -502,3 +508,11 @@ class TestArchives (ArchiveTest):
# self.program = 'shorten'
# self.archive_extract('t.shn.foo')
# self.archive_create('t.shn.foo', srcfile='t.wav')
@needs_program('file')
@needs_program('flac')
def test_flac (self):
self.program = 'flac'
self.archive_extract('t.flac.foo')
self.archive_test('t.flac.foo')
self.archive_create('t.flac.foo', srcfile='t.wav', format='flac')