[Git][reproducible-builds/diffoscope][master] Add support for comparing MP3 files. (Closes: reproducible-builds/diffoscope#43)

Chris Lamb gitlab at salsa.debian.org
Mon Feb 11 19:03:07 CET 2019


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
c48186e7 by Chris Lamb at 2019-02-11T18:02:21Z
Add support for comparing MP3 files. (Closes: reproducible-builds/diffoscope#43)

- - - - -


9 changed files:

- debian/control
- debian/tests/control
- diffoscope/comparators/__init__.py
- + diffoscope/comparators/ffprobe.py
- diffoscope/external_tools.py
- + tests/comparators/test_ffprobe.py
- + tests/data/mp3_expected_diff
- + tests/data/test1.mp3
- + tests/data/test2.mp3


Changes:

=====================================
debian/control
=====================================
@@ -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>,


=====================================
debian/tests/control
=====================================
@@ -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


=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -64,6 +64,7 @@ class ComparatorManager(object):
         ('gettext.MoFile',),
         ('ipk.IpkFile',),
         ('rust.RustObjectFile',),
+        ('ffprobe.FfprobeFile',),
         ('gnumeric.GnumericFile',),
         ('gzip.GzipFile',),
         ('haskell.HiFile',),


=====================================
diffoscope/comparators/ffprobe.py
=====================================
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2019 Chris Lamb <lamby at 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',
+        )]


=====================================
diffoscope/external_tools.py
=====================================
@@ -72,6 +72,9 @@ EXTERNAL_TOOLS = {
         'debian': 'device-tree-compiler',
         'arch': 'dtc',
     },
+    'ffprobe': {
+        'debian': 'ffmpeg',
+    },
     'file': {
         'debian': 'file',
         'arch': 'file',


=====================================
tests/comparators/test_ffprobe.py
=====================================
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2019 Chris Lamb <lamby at 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
+
+
+ at pytest.fixture
+def differences(mp3_1, mp3_2):
+    return mp3_1.compare(mp3_2).details
+
+
+ at skip_unless_tools_exist('ffprobe')
+def test_diff(differences):
+    expected_diff = get_data('mp3_expected_diff')
+    assert differences[0].unified_diff == expected_diff
+
+
+ at skip_unless_tools_exist('ffprobe')
+def test_compare_non_existing(monkeypatch, mp3_1):
+    assert_non_existing(monkeypatch, mp3_1, has_null_source=False)


=====================================
tests/data/mp3_expected_diff
=====================================
@@ -0,0 +1,17 @@
+@@ -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


=====================================
tests/data/test1.mp3
=====================================
Binary files /dev/null and b/tests/data/test1.mp3 differ


=====================================
tests/data/test2.mp3
=====================================
Binary files /dev/null and b/tests/data/test2.mp3 differ



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/c48186e7a437ee2d4ca9fbfb65f7abbc3e34a3df

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/c48186e7a437ee2d4ca9fbfb65f7abbc3e34a3df
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20190211/e2a8f1ec/attachment.html>


More information about the rb-commits mailing list