From fe03d08a8ea3081e44873005127fd1d419732ea6 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Fri, 11 Jan 2019 13:50:42 +0100
Subject: [PATCH] Removed unused acoustid dependency / logic

---
 CONTRIBUTING.rst                              |  2 +-
 api/Dockerfile                                |  2 +-
 api/config/settings/common.py                 |  1 -
 api/docker/Dockerfile.test                    |  2 -
 .../providers/acoustid/__init__.py            | 27 ------------
 .../acoustid/dynamic_preferences_registry.py  | 16 -------
 api/requirements/base.txt                     |  1 -
 api/tests/test_acoustid.py                    | 43 -------------------
 8 files changed, 2 insertions(+), 92 deletions(-)
 delete mode 100644 api/funkwhale_api/providers/acoustid/__init__.py
 delete mode 100644 api/funkwhale_api/providers/acoustid/dynamic_preferences_registry.py
 delete mode 100644 api/tests/test_acoustid.py

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index ff1df416..c2d36485 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -391,7 +391,7 @@ This is regular pytest, so you can use any arguments/options that pytest usually
     # Stop on first failure
     docker-compose -f dev.yml run --rm api pytest -x
     # Run a specific test file
-    docker-compose -f dev.yml run --rm api pytest tests/test_acoustid.py
+    docker-compose -f dev.yml run --rm api pytest tests/music/test_models.py
 
 Writing tests
 ^^^^^^^^^^^^^
diff --git a/api/Dockerfile b/api/Dockerfile
index 6acdaac5..e22c456f 100644
--- a/api/Dockerfile
+++ b/api/Dockerfile
@@ -10,7 +10,7 @@ RUN apt-get update; \
     grep -Fv "python3-dev" | \
     xargs apt-get install -y --no-install-recommends; \
     rm -rf /usr/share/doc/* /usr/share/locale/*
-RUN curl -L https://github.com/acoustid/chromaprint/releases/download/v1.4.2/chromaprint-fpcalc-1.4.2-linux-x86_64.tar.gz | tar -xz -C /usr/local/bin --strip 1
+
 COPY ./requirements/base.txt /requirements/base.txt
 RUN pip install -r /requirements/base.txt
 COPY ./requirements/production.txt /requirements/production.txt
diff --git a/api/config/settings/common.py b/api/config/settings/common.py
index 74fe79ed..7eb606d8 100644
--- a/api/config/settings/common.py
+++ b/api/config/settings/common.py
@@ -160,7 +160,6 @@ LOCAL_APPS = (
     "funkwhale_api.radios",
     "funkwhale_api.history",
     "funkwhale_api.playlists",
-    "funkwhale_api.providers.acoustid",
     "funkwhale_api.subsonic",
 )
 
diff --git a/api/docker/Dockerfile.test b/api/docker/Dockerfile.test
index 963e3ab2..9e3202f9 100644
--- a/api/docker/Dockerfile.test
+++ b/api/docker/Dockerfile.test
@@ -11,8 +11,6 @@ RUN apt-get update; \
     xargs apt-get install -y --no-install-recommends; \
     rm -rf /usr/share/doc/* /usr/share/locale/*
 
-RUN curl -L https://github.com/acoustid/chromaprint/releases/download/v1.4.2/chromaprint-fpcalc-1.4.2-linux-x86_64.tar.gz | tar -xz -C /usr/local/bin --strip 1
-
 RUN mkdir /requirements
 COPY ./requirements/base.txt /requirements/base.txt
 RUN pip install -r /requirements/base.txt
diff --git a/api/funkwhale_api/providers/acoustid/__init__.py b/api/funkwhale_api/providers/acoustid/__init__.py
deleted file mode 100644
index 558a95bb..00000000
--- a/api/funkwhale_api/providers/acoustid/__init__.py
+++ /dev/null
@@ -1,27 +0,0 @@
-import acoustid
-
-from dynamic_preferences.registries import global_preferences_registry
-
-
-class Client(object):
-    def __init__(self, api_key):
-        self.api_key = api_key
-
-    def match(self, file_path):
-        return acoustid.match(self.api_key, file_path, parse=False)
-
-    def get_best_match(self, file_path):
-        results = self.match(file_path=file_path)
-        MIN_SCORE_FOR_MATCH = 0.8
-        try:
-            rows = results["results"]
-        except KeyError:
-            return
-        for row in rows:
-            if row["score"] >= MIN_SCORE_FOR_MATCH:
-                return row
-
-
-def get_acoustid_client():
-    manager = global_preferences_registry.manager()
-    return Client(api_key=manager["providers_acoustid__api_key"])
diff --git a/api/funkwhale_api/providers/acoustid/dynamic_preferences_registry.py b/api/funkwhale_api/providers/acoustid/dynamic_preferences_registry.py
deleted file mode 100644
index 2411de86..00000000
--- a/api/funkwhale_api/providers/acoustid/dynamic_preferences_registry.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from django import forms
-from dynamic_preferences.registries import global_preferences_registry
-from dynamic_preferences.types import Section, StringPreference
-
-acoustid = Section("providers_acoustid")
-
-
-@global_preferences_registry.register
-class APIKey(StringPreference):
-    section = acoustid
-    name = "api_key"
-    default = ""
-    verbose_name = "Acoustid API key"
-    help_text = "The API key used to query AcoustID. Get one at https://acoustid.org/new-application."
-    widget = forms.PasswordInput
-    field_kwargs = {"required": False}
diff --git a/api/requirements/base.txt b/api/requirements/base.txt
index c586bc6d..bf4660a1 100644
--- a/api/requirements/base.txt
+++ b/api/requirements/base.txt
@@ -50,7 +50,6 @@ django-taggit>=0.22,<0.23
 pymemoize==1.0.3
 
 django-dynamic-preferences>=1.7,<1.8
-pyacoustid>=1.1.5,<1.2
 raven>=6.5,<7
 python-magic==0.4.15
 ffmpeg-python==0.1.10
diff --git a/api/tests/test_acoustid.py b/api/tests/test_acoustid.py
deleted file mode 100644
index ab3dfd1d..00000000
--- a/api/tests/test_acoustid.py
+++ /dev/null
@@ -1,43 +0,0 @@
-from funkwhale_api.providers.acoustid import get_acoustid_client
-
-
-def test_client_is_configured_with_correct_api_key(preferences):
-    api_key = "hello world"
-    preferences["providers_acoustid__api_key"] = api_key
-
-    client = get_acoustid_client()
-    assert client.api_key == api_key
-
-
-def test_client_returns_raw_results(db, mocker, preferences):
-    api_key = "test"
-    preferences["providers_acoustid__api_key"] = api_key
-    payload = {
-        "results": [
-            {
-                "id": "e475bf79-c1ce-4441-bed7-1e33f226c0a2",
-                "recordings": [
-                    {
-                        "artists": [
-                            {
-                                "id": "9c6bddde-6228-4d9f-ad0d-03f6fcb19e13",
-                                "name": "Binärpilot",
-                            }
-                        ],
-                        "duration": 268,
-                        "id": "f269d497-1cc0-4ae4-a0c4-157ec7d73fcb",
-                        "title": "Bend",
-                    }
-                ],
-                "score": 0.860825,
-            }
-        ],
-        "status": "ok",
-    }
-
-    m = mocker.patch("acoustid.match", return_value=payload)
-    client = get_acoustid_client()
-    response = client.match("/tmp/noopfile.mp3")
-
-    assert response == payload
-    m.assert_called_once_with("test", "/tmp/noopfile.mp3", parse=False)
-- 
GitLab