diff --git a/inv/host_vars/chosto.me/vars.yml b/inv/host_vars/chosto.me/vars.yml index d8529b7..939c28d 100644 --- a/inv/host_vars/chosto.me/vars.yml +++ b/inv/host_vars/chosto.me/vars.yml @@ -18,3 +18,7 @@ traefik_network: proxy domain_name: chosto.me letsencrypt_email: quentinduchemin@tuta.io + +# When importing to Funkwhale, you must choose a library +# Create a library, get the ID in URL and put it there +funkwhale_import_library_id: 3e772648-0ce1-4dc1-be59-39e8e6f409d6 diff --git a/music.yml b/music.yml index f5c690b..56ceba6 100644 --- a/music.yml +++ b/music.yml @@ -2,7 +2,6 @@ - hosts: all become: yes tasks: - tags: requirements - name: Install and configure Funkwhale, deezloader and beets include_role: name: music diff --git a/roles/music/tasks/download_music.yml b/roles/music/tasks/download_music.yml index 9758b25..88c32be 100644 --- a/roles/music/tasks/download_music.yml +++ b/roles/music/tasks/download_music.yml @@ -7,6 +7,9 @@ mode: 0644 - name: Download required albums + # So that files are written with base user perms + become: yes + become_user: "{{ base_user_name }}" shell: cmd: "deez-dw.py --recursive_download True --recursive_quality True --output {{ deezloader_songs_path }} --not_gui False --link {{ item }}" chdir: "{{ deezloader_folder_path }}" diff --git a/roles/music/tasks/funkwhale.yml b/roles/music/tasks/funkwhale.yml index 094d1b4..b1ae08d 100644 --- a/roles/music/tasks/funkwhale.yml +++ b/roles/music/tasks/funkwhale.yml @@ -6,6 +6,8 @@ loop: - deezloader - beets + - pexpect + - pylast - name: Create deezloader and beets directories file: diff --git a/roles/music/tasks/import_music.yml b/roles/music/tasks/import_music.yml index 161684d..e759311 100644 --- a/roles/music/tasks/import_music.yml +++ b/roles/music/tasks/import_music.yml @@ -2,3 +2,34 @@ template: src: beets_config.yaml.j2 dest: "{{ beets_config_folder }}/config.yaml" + owner: "{{ base_user_name }}" + group: "{{ base_user_name }}" + mode: 0644 + +- name: Make sure logs are writable + file: + path: "{{ beets_log_file }}" + state: touch + owner: "{{ base_user_name }}" + group: "{{ base_user_name }}" + mode: 0644 + +- name: Tag music (auto-tag when confidence > 80%, use as-is otherwise) + # So that files are written with user perms + become: yes + become_user: "{{ base_user_name }}" + shell: + # Quiet mode = do not ask anything to the user + # Default are in configuration file + cmd: "beet -c {{ beets_config_folder }}/config.yaml import -q {{ deezloader_songs_path }}" + +- name: Import music into Funkwhale + shell: + # funkwhale_import_music_directory is the mounted version of tagged + # files at previous step + cmd: "docker-compose run --rm api python manage.py import_files {{ funkwhale_import_library_id }} {{ funkwhale_import_music_directory }} --recursive --noinput --prune" + chdir: "{{ funkwhale_folder_name }}" + +- name: Delete files once imported + shell: + cmd: "rm -rf {{ funkwhale_import_music_directory_host }}/*" diff --git a/roles/music/templates/beets_config.yaml.j2 b/roles/music/templates/beets_config.yaml.j2 index e3191fc..80f4c2a 100644 --- a/roles/music/templates/beets_config.yaml.j2 +++ b/roles/music/templates/beets_config.yaml.j2 @@ -3,8 +3,8 @@ threaded: yes plugins: lyrics ftintitle embedart duplicates fetchart lastgenre acousticbrainz lyrics match: - # Allow 90% confidence for auto-tagging - strong_rec_thresh: 0.10 + # Allow 80% confidence for auto-tagging + strong_rec_thresh: 0.20 max_rec: media: strong label: strong @@ -23,6 +23,16 @@ ui: color: yes import: - write: yes + # Always move files to Funkwhale import directory move: yes - log: /var/log/beets.log + # Previous import interrupted, start for the begining + # Should not really change because files are deleted after import + resume: no + # Merge albums if they look the same + duplicate_action: merge + # Use-as-is if no release found (could be then added to MusicBrainz) + # Reasonable because Deezer metadata is good enough in most cases + quiet_fallback: asis + log: {{ beets_log_file }} + # Preferred languages for aliases (in case of foreign artist with another alphabet for example) + languages: fr en diff --git a/roles/music/vars/main.yml b/roles/music/vars/main.yml index fcfa3b6..fcae11c 100644 --- a/roles/music/vars/main.yml +++ b/roles/music/vars/main.yml @@ -13,3 +13,4 @@ redis_version: 6 deezloader_folder_path: /home/{{ base_user_name }}/deezloader deezloader_songs_path: "{{ deezloader_folder_path }}/songs" beets_config_folder: "/home/{{ base_user_name }}/.config/beets" +beets_log_file: "/var/log/beets.log"