Skip to content

Commit

Permalink
feat: new config option original_date
Browse files Browse the repository at this point in the history
Let's you prefer an album's original date when importing or syncing rather than the date of the specific album release.
  • Loading branch information
jtpavlock committed Oct 8, 2022
1 parent 9799a64 commit 3894fa7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ Most configuration options reside in their relevant plugin, however there are th
.. note::
If you change ``library_path``, Moe will attempt to search for your music in the new location.

``original_date = false``
Whether or not to always set an album's ``date`` to its ``original_date`` if present.

.. note::
This change will also propagate onto the respective ``year`` fields.

Plugin Options
==============
For plugin specific configuration, see the respective plugin's page. Each plugin option should be specified under that plugin's section in the config.
Expand Down
1 change: 1 addition & 0 deletions moe/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def add_config_validator(settings: dynaconf.base.LazySettings):
dynaconf.Validator("DEFAULT_PLUGINS", default=DEFAULT_PLUGINS),
dynaconf.Validator("DISABLE_PLUGINS", default=set()),
dynaconf.Validator("LIBRARY_PATH", default="~/Music"),
dynaconf.Validator("ORIGINAL_DATE", default=False),
]
settings.validators.register(*validators)

Expand Down
3 changes: 3 additions & 0 deletions moe/library/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def __init__(
for key, value in kwargs.items():
setattr(self, key, value)

if config.CONFIG.settings.original_date and self.original_date:
self.date = self.original_date

log.debug(f"Album created. [album={self!r}]")

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/library/test_album.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Tests an Album object."""

from datetime import date
from pathlib import Path

import pytest

import moe
from moe import config
from moe.config import ExtraPlugin
from moe.library import Album, AlbumError, Extra
from moe.plugins import write as moe_write
Expand Down
13 changes: 7 additions & 6 deletions tests/plugins/musicbrainz/test_mb_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests the musicbrainz plugin."""

import copy
import datetime
from unittest.mock import call, patch

Expand Down Expand Up @@ -368,7 +369,7 @@ def test_print_result(self):
Make sure to add any ``includes`` for whatever is needed for the test.
"""

def test_album_search(self, mock_mb_by_id):
def test_album_search(self, mock_mb_by_id, mb_config):
"""Searching for a release returns the expected album."""
mb_album_id = "2fcfcaaa-6594-4291-b79f-2d354139e108"
mock_mb_by_id.return_value = mb_rsrc.full_release.release
Expand All @@ -380,29 +381,29 @@ def test_album_search(self, mock_mb_by_id):
)
assert mb_album == mb_rsrc.full_release.album()

def test_partial_date_year_mon(self, mock_mb_by_id):
def test_partial_date_year_mon(self, mock_mb_by_id, mb_config):
"""If given date is missing the day, default to 1."""
mb_album_id = "112dec42-65f2-3bde-8d7d-26deddde10b2"
release = mb_rsrc.full_release.release
release = copy.deepcopy(mb_rsrc.full_release.release)
release["release"]["date"] = "1992-12"
mock_mb_by_id.return_value = release

mb_album = moe_mb.get_album_by_id(mb_album_id)

assert mb_album.date == datetime.date(1992, 12, 1)

def test_partial_date_year(self, mock_mb_by_id):
def test_partial_date_year(self, mock_mb_by_id, mb_config):
"""If given date is missing the day and month, default to 1 for each."""
mb_album_id = "112dec42-65f2-3bde-8d7d-26deddde10b2"
release = mb_rsrc.full_release.release
release = copy.deepcopy(mb_rsrc.full_release.release)
release["release"]["date"] = "1992"
mock_mb_by_id.return_value = release

mb_album = moe_mb.get_album_by_id(mb_album_id)

assert mb_album.date == datetime.date(1992, 1, 1)

def test_multi_disc_release(self, mock_mb_by_id):
def test_multi_disc_release(self, mock_mb_by_id, mb_config):
"""We can add a release with multiple discs."""
mb_album_id = "3af9a6ca-c38a-41a7-a53c-32a97e869e8e"
mock_mb_by_id.return_value = mb_rsrc.multi_disc.release
Expand Down

0 comments on commit 3894fa7

Please sign in to comment.