Git Product home page Git Product logo

python-metallum's Introduction

python-metallum

A basic python API for the amazing www.metal-archives.com

Install

pip install python-metallum

Usage

Artist search

import metallum


# Search bands matching term
bands = metallum.band_search('metallica')
# -> [<SearchResult: Metallica | Thrash Metal (early), Hard Rock/Heavy/Thrash Metal (later) | United States>]

bands[0].name
# -> 'Metallica'

# Fetch band page
band = bands[0].get()

# Get all albums
band.albums
# -> [<Album: No Life 'til Leather (Demo)>, <Album: Kill 'Em All (Full-length)>, ...]

# Get only full-length albums
full_length = band.albums.search(type=metallum.AlbumTypes.FULL_LENGTH)
# -> [<Album: Kill 'Em All (Full-length)>, <Album: Ride the Lightning (Full-length)>, <Album: Master of Puppets (Full-length)>, <Album: ...and Justice for All (Full-length)>, <Album: Metallica (Full-length)>, <Album: Load (Full-length)>, <Album: ReLoad (Full-length)>, <Album: Garage Inc. (Full-length)>, <Album: St. Anger (Full-length)>, <Album: Death Magnetic (Full-length)>, <Album: Hardwired... to Self-Destruct (Full-length)>]

album = full_length[2]
album.title
# -> 'Master of Puppets'

album.date
# -> datetime.datetime(1986, 3, 3, 0, 0)

# Get all tracks
album.tracks
# -> [<Track: Battery (313)>, <Track: Master of Puppets (516)>, <Track: The Thing That Should Not Be (397)>, <Track: Welcome Home (Sanitarium) (388)>, <Track: Disposable Heroes (497)>, <Track: Leper Messiah (341)>, <Track: Orion (508)>, <Track: Damage, Inc. (330)>]

Album search

import metallum

# Search albums matching term
metallum.album_search('seventh')
# -> []

# Search albums containing term
metallum.album_search('seventh', strict=False)
# -> [<SearchResult: Beherit | Seventh Blasphemy | Demo>, <SearchResult: Black Sabbath | Seventh Star | Full-length>, ...]

# Search albums by band
metallum.album_search('seventh', band='iron maiden', strict=False)
# -> [<SearchResult: Iron Maiden | Seventh Son of a Seventh Son | Full-length>]

Refer to source and doctests for detailed usage

python-metallum's People

Contributors

cpowgithub avatar lcharlick avatar mvarga12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-metallum's Issues

Problems with non-latin album names

album_for_id() returns correct data:

metallum.album_for_id(104072).title
-> 'Äpäre'

but band_for_id().albums[].title doesn't:

metallum.band_for_id(2052).albums[6].title
-> 'Ã\x84päre'

Same when writing to a file.

It's interesting that after I concatenate the album's band name with the album title, album.title starts to work fine:

a = metallum.band_for_id(2052).albums[6]
a.title
-> 'Ã\x84päre'
a.bands[0].name + a.title
-> 'AjattaraÄpäre'
a.title
-> 'Äpäre'

Windows 7 64-bit, Python 3.8.1

Genres don't get split correctly in some cases

return self[1].split(', ')

In some cases genres not only contain information in parentheses but the information contains commas:

Heavy Metal/Hard Rock (early, later), Thrash Metal (mid)

If these get split at commas like in the referenced line and again in line 450, the result will be this:

>>> 'Heavy Metal/Hard Rock (early, later), Thrash Metal (mid)'.split(',')
['Heavy Metal/Hard Rock (early', ' later)', ' Thrash Metal (mid)']

Instead it should be:

['Heavy Metal/Hard Rock (early, later)', 'Thrash Metal (mid)']

A possible fix would be to use regular expressions to only split at commas not contained in parentheses:

>>> re.split(r',\s*(?![^()]*\))', 'Heavy Metal/Hard Rock (early, later), Thrash Metal (mid)')
['Heavy Metal/Hard Rock (early, later)', 'Thrash Metal (mid)']

Retrieving of the reviews count for an album

Hi Lachlan

I just wanted to propose a small improvement that could allow to get the total number of reviews for the specific album:

class Album(MetallumEntity):
...
    @property
    def reviews_count(self) -> Optional[int]:
        """
        >>> a.reviews_count
        3

        >>> a2.reviews_count
        1

        >>> a3.reviews_count
        4
        """
        element = self._dd_element_for_label('Reviews:')
        if not element:
            return None

        reviews_count = re.search('(\d)', element.text())
        if not reviews_count:
            return None

        return int(reviews_count.group(1))

403: Forbidden

Getting a forbidden response, probably due to the recent MA migration

Getting more than 200 results

Hi, awesome work here! When I do search bands by country,

e.g. bands = metallum.band_search('*',strict=False, countries=['US'])

only 200 results (results in the first page when the search is performed on MA) are returned.
is there a way to collect all the bands that are returned from this search? Thanks!

No module named 'requests_cache.core'

The rest of the modules are just fine, requests_cache included but requests_cache.core doesn't seem to be a thing? I've tried on two computers and both fail. Removing the import and the one time it is used at line 22 resolves the issue for me

Getting the total duration of the album

Hi, great work. I am finding it really useful.
Is there an easy way to get the total duration for an album without having to add up all the individual track durations?

Queries resulting in more than just the basic band information

BandResult only has properties to extract the data from index 0 to 2 which is sufficient for the most basic query result:

>>> print(metallum.band_search('Iron Maiden'))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom>]

But if other criteria are added, there'll be more information included in other indices and it adds up:

>>> print(metallum.band_search('Iron Maiden', countries='GB')) # Country query results in the location at index 2 instead of the country
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | London, England >]

>>> print(metallum.band_search('Iron Maiden', location='London'))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | London, England >] # Location query adds the location

>>> print(metallum.band_search('Iron Maiden', themes='History')) # Lyrical themes query adds data
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | History, Literature, War, Mythology, Society, Religion>]

>>> print(metallum.band_search('Iron Maiden', label="Parlophone")) # Label query adds data
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | Parlophone>]

Year created from/to both result in extra data containing the year the band was formed in:

>>> print(metallum.band_search('Iron Maiden', year_created_from="1970"))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | 1975>]

>>> print(metallum.band_search('Iron Maiden', year_created_to="1980"))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | 1975>]

>>> print(metallum.band_search('Iron Maiden', year_created_from="1970", year_created_to="1980"))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | 1975>]

Arbitrary combinations are possible:

>>> print(metallum.band_search('Iron Maiden', themes='History', location='London'))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom | London, England  | History, Literature, War, Mythology, Society, Religion>]

>>> print(metallum.band_search('Iron Maiden', countries='GB', location='London', themes='History', year_created_from="1970", year_created_to="1980"))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | London, England  | History, Literature, War, Mythology, Society, Religion | 1975>]

Other queries don't add/change the basic data:

>>> print(metallum.band_search('Iron Maiden', status="1"))
[<SearchResult: Iron Maiden | Heavy Metal, NWOBHM | United Kingdom>]

To access the data separately I added the following in my local version

@property
def other(self) -> str:
    """
    >>> s[0].other
    ['Politics, Misanthropy, Gore']
    """
    return self[3:]

but this is fairly ugly and means that the user has to know what kind of information will be included in there, also in case of a country (but not location) query, the country property will return the location.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.