Merge branch 'develop'
This commit is contained in:
2
setup.py
2
setup.py
@@ -33,10 +33,8 @@ entry_points = \
|
||||
setup_kwargs = {
|
||||
'name': 'musicbrainzapi',
|
||||
'version': '1.0.0',
|
||||
'description': '',
|
||||
'long_description': None,
|
||||
'description': 'Python module to calculate statistics and generate a wordcloud for a given artist. Uses the Musicbrainz API and the lyrics.ovh API.',
|
||||
'long_description': '',
|
||||
'author': 'dtomlinson',
|
||||
'author_email': 'dtomlinson@panaetius.co.uk',
|
||||
'maintainer': None,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
musicbrainzapi: A CLI lyrics searcher
|
||||
=====================================
|
||||
musicbrainzapi: A CLI lyrics searcher.
|
||||
======================================
|
||||
|
||||
This module was written by dtomlinson <dtomlinson@panaetius.co.uk> for Aire Logic
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
"""
|
||||
Lyrics object with statistics.
|
||||
===============================
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from typing import Union, Dict, List
|
||||
from dataclasses import dataclass
|
||||
@@ -10,8 +14,7 @@ import numpy as np
|
||||
|
||||
@dataclass
|
||||
class Lyrics:
|
||||
"""Lyrics object for an artist.
|
||||
"""
|
||||
"""Lyrics object for an artist."""
|
||||
|
||||
artist_id: str
|
||||
artist: str
|
||||
|
||||
@@ -106,6 +106,7 @@ class LyricsBuilder(LyricsConcreteBuilder):
|
||||
-------
|
||||
str
|
||||
URL for lyrics from the lyrics api.
|
||||
|
||||
"""
|
||||
lyrics_api_base = 'https://api.lyrics.ovh/v1'
|
||||
lyrics_api_url = html.escape(f'{lyrics_api_base}/{artist}/{song}')
|
||||
@@ -123,7 +124,8 @@ class LyricsBuilder(LyricsConcreteBuilder):
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Lyrics of the trakc
|
||||
Lyrics of the track.
|
||||
|
||||
"""
|
||||
resp = requests.get(url)
|
||||
|
||||
@@ -192,6 +194,7 @@ class LyricsBuilder(LyricsConcreteBuilder):
|
||||
return _d
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Create a builder instance to build a Lyrics object."""
|
||||
self.reset()
|
||||
|
||||
def reset(self) -> None:
|
||||
@@ -208,8 +211,7 @@ class LyricsBuilder(LyricsConcreteBuilder):
|
||||
return self
|
||||
|
||||
def sort_artists(self) -> None:
|
||||
"""Sort the artists from the Musicbrainzapi
|
||||
"""
|
||||
"""Sort the artists from the Musicbrainzapi."""
|
||||
self._sort_names = dict(
|
||||
(i.get('id'), f'{i.get("name")} | {i.get("disambiguation")}')
|
||||
if i.get('disambiguation') is not None
|
||||
@@ -241,8 +243,7 @@ class LyricsBuilder(LyricsConcreteBuilder):
|
||||
return self
|
||||
|
||||
def find_all_albums(self) -> None:
|
||||
"""Find all albums for the chosen artist
|
||||
"""
|
||||
"""Find all albums for the chosen artist."""
|
||||
limit, offset, page = (100, 0, 1)
|
||||
|
||||
resp_0 = addict.Dict(
|
||||
@@ -365,8 +366,7 @@ class LyricsBuilder(LyricsConcreteBuilder):
|
||||
return self
|
||||
|
||||
def find_lyrics_urls(self) -> None:
|
||||
"""Construct the URL for the lyrics api.
|
||||
"""
|
||||
"""Construct the URL for the lyrics api."""
|
||||
self.all_albums_lyrics_url = list()
|
||||
for x in self.all_albums:
|
||||
for alb, tracks in x.items():
|
||||
|
||||
@@ -10,6 +10,7 @@ class LyricsClickDirector:
|
||||
"""Director for Lyrics builder."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Create a Director to orchestrate the builder."""
|
||||
self._builder = None
|
||||
|
||||
@staticmethod
|
||||
@@ -62,6 +63,7 @@ class LyricsClickDirector:
|
||||
------
|
||||
SystemExit
|
||||
If no artist is found will cleanly quit.
|
||||
|
||||
"""
|
||||
artist_meta = None
|
||||
for i, j in self.builder._top_five_results.items():
|
||||
@@ -111,8 +113,7 @@ class LyricsClickDirector:
|
||||
return self
|
||||
|
||||
def _query_for_data(self) -> None:
|
||||
"""Query Musicbrainz api for albums + track data.
|
||||
"""
|
||||
"""Query Musicbrainz api for albums + track data."""
|
||||
self.builder.find_all_albums()
|
||||
self.builder.find_all_tracks()
|
||||
self.builder._product.all_albums_with_tracks = self.builder.all_albums
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
"""
|
||||
Wordcloud from lyrics.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
import collections
|
||||
from importlib import resources
|
||||
@@ -41,6 +45,8 @@ class LyricsWordcloud:
|
||||
all_albums_lyrics_count: 'Lyrics.all_albums_lyrics_count',
|
||||
):
|
||||
"""
|
||||
Create a worcloud object.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pillow_img : PIL.PngImagePlugin.PngImageFile
|
||||
@@ -55,12 +61,14 @@ class LyricsWordcloud:
|
||||
def use_microphone(
|
||||
cls, all_albums_lyrics_count: 'Lyrics.all_albums_lyrics_count',
|
||||
) -> LyricsWordcloud:
|
||||
"""Class method to instantiate with a microphone base image.
|
||||
"""
|
||||
Class method to instantiate with a microphone base image.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
all_albums_lyrics_count : Lyrics.all_albums_lyrics_count
|
||||
List of all albums + track lyrics counted by each word
|
||||
|
||||
"""
|
||||
mic_resource = resources.path(
|
||||
'musicbrainzapi.wordcloud.resources', 'mic.png'
|
||||
@@ -78,7 +86,7 @@ class LyricsWordcloud:
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
"""Static method to generate a random grey colour"""
|
||||
"""Static method to generate a random grey colour."""
|
||||
colour = f'hsl(0, 0%, {random.randint(60, 100)}%)'
|
||||
return colour
|
||||
|
||||
|
||||
Reference in New Issue
Block a user