Commit c48186e7 authored by Chris Lamb's avatar Chris Lamb 💬

Add support for comparing MP3 files. (Closes: #43)

parent d6eb188d
Pipeline #36114 failed with stage
in 15 minutes and 18 seconds
......@@ -44,6 +44,7 @@ Build-Depends:
llvm <!nocheck>,
lz4 <!nocheck> | liblz4-tool <!nocheck>,
mono-utils <!nocheck>,
mplayer <!nocheck>,
ocaml-nox <!nocheck>,
odt2txt <!nocheck>,
# oggvideotools [!s390x] <!nocheck>,
......
......@@ -7,7 +7,7 @@
# $ mv debian/tests/control.tmp debian/tests/control
Tests: pytest-with-recommends
Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, fontforge-extras, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnumeric, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, openssh-client, pgpdump, poppler-utils, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, zip, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, ffmpeg, fontforge-extras, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnumeric, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, openssh-client, pgpdump, poppler-utils, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, zip, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
Tests: pytest
Depends: diffoscope, python3-pytest, file
......
......@@ -64,6 +64,7 @@ class ComparatorManager(object):
('gettext.MoFile',),
('ipk.IpkFile',),
('rust.RustObjectFile',),
('ffprobe.FfprobeFile',),
('gnumeric.GnumericFile',),
('gzip.GzipFile',),
('haskell.HiFile',),
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2019 Chris Lamb <lamby@debian.org>
#
# diffoscope 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.
#
# diffoscope 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 diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
from diffoscope.tools import tool_required
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
class Ffprobe(Command):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.flag = False
def start(self):
super().start()
self.stderr = ''
@property
def stdout(self):
return self._process.stderr.splitlines(True)
@tool_required('ffprobe')
def cmdline(self):
return ('ffprobe', self.path)
def filter(self, line):
if self.flag:
return line
elif line == b' Metadata:\n':
self.flag = True
return b''
class FfprobeFile(File):
DESCRIPTION = "Multimedia metadata"
FILE_TYPE_RE = re.compile(r'^Audio file')
def compare_details(self, other, source=None):
return [Difference.from_command(
Ffprobe,
self.path,
other.path,
source='ffprobe',
)]
......@@ -72,6 +72,9 @@ EXTERNAL_TOOLS = {
'debian': 'device-tree-compiler',
'arch': 'dtc',
},
'ffprobe': {
'debian': 'ffmpeg',
},
'file': {
'debian': 'file',
'arch': 'file',
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2019 Chris Lamb <lamby@debian.org>
#
# diffoscope 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.
#
# diffoscope 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 diffoscope. If not, see <https://www.gnu.org/licenses/>.
import pytest
from diffoscope.comparators.ffprobe import FfprobeFile
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
mp3_1 = load_fixture('test1.mp3')
mp3_2 = load_fixture('test2.mp3')
def test_identification(mp3_1):
assert isinstance(mp3_1, FfprobeFile)
def test_no_differences(mp3_1):
difference = mp3_1.compare(mp3_1)
assert difference is None
@pytest.fixture
def differences(mp3_1, mp3_2):
return mp3_1.compare(mp3_2).details
@skip_unless_tools_exist('ffprobe')
def test_diff(differences):
expected_diff = get_data('mp3_expected_diff')
assert differences[0].unified_diff == expected_diff
@skip_unless_tools_exist('ffprobe')
def test_compare_non_existing(monkeypatch, mp3_1):
assert_non_existing(monkeypatch, mp3_1, has_null_source=False)
@@ -1,9 +1,9 @@
- title : Example track title 1
- genre : Example genre 1
- artist : Example artist name 1
- album : Example track title 1
- comment : Example comment 1
- track : 1
- date : 1111
+ genre : Example genre 2
+ artist : Example artist name 2
+ title : Example track title 2
+ comment : Example comment 2
+ track : 2
+ album : Example track title 2
+ date : 2222
Duration: 00:00:00.22, start: 0.000000, bitrate: 17 kb/s
Stream #0:0: Audio: mp3, 8000 Hz, mono, fltp, 8 kb/s
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment