Skip to content

Commit

Permalink
Hardened release_date search pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Jan 17, 2021
1 parent e0c3932 commit 4ae454b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# [0.4.4] 2021-01-17

### Fixed
- `release_date` search pattern now looks for a specific date format, guarding
it against similar matches that could be found in the description, thanks
@noahsager.


# [0.4.3] 2021-01-17

### Fixed
Expand Down
9 changes: 7 additions & 2 deletions beetsplug/bandcamp/_metaguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"country": re.compile(r'location\ssecondaryText">(?:[\w\s]*, )?([\w\s,]+){1,4}'),
"label": re.compile(r'og:site_name".*content="([^"]*)"'),
"lyrics": re.compile(r'"lyrics":({[^}]*})'),
"release_date": re.compile(r" released (.*)"),
"release_date": re.compile(r"released ([\d]{2} [A-Z][a-z]+ [\d]{4})"),
"track_name": re.compile(
r"""
((?P<track_alt>[ABCDEFGH]{1,3}\d\d?)[^\w]*)?
Expand Down Expand Up @@ -99,6 +99,11 @@ def parse_catalognum(album: str, disctitle: str) -> str:

return ""

@staticmethod
def parse_release_date(string: str) -> str:
match = re.search(PATTERNS["release_date"], string)
return match.groups()[0] if match else ""


class Metaguru(Helpers):
html: str
Expand Down Expand Up @@ -152,7 +157,7 @@ def lyrics(self) -> Optional[str]:

@property
def release_date(self) -> date:
datestr = self._search(PATTERNS["release_date"])
datestr = self.parse_release_date(self.html)
return datetime.strptime(datestr, DATE_FORMAT).date()

@property
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "beetcamp"
version = "0.4.3"
version = "0.4.4"
description = "Bandcamp autotagger source for beets (http://beets.io)."
authors = ["Šarūnas Nejus <[email protected]>"]
readme = "README.md"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def test_convert_title(title, expected):
assert urlify(title) == expected


@pytest.mark.parametrize(
("string", "expected"),
[
("released 06 November 2019", "06 November 2019"),
("released on Some Records", ""),
],
)
def test_parse_release_date(string, expected):
assert Metaguru.parse_release_date(string) == expected


@pytest.mark.parametrize(
("name", "expected"),
[
Expand Down

0 comments on commit 4ae454b

Please sign in to comment.