client.py 2.29 KB
Newer Older
1
import musicbrainzngs
2
import memoize.djangocache
3
4
5

from django.conf import settings
from funkwhale_api import __version__
6

7
8
9
10
_api = musicbrainzngs
_api.set_useragent('funkwhale', str(__version__), 'contact@eliotberriot.com')


11
12
13
14
store = memoize.djangocache.Cache('default')
memo = memoize.Memoizer(store, namespace='memoize:musicbrainz')


15
16
17
18
19
20
21
22
23
24
25
def clean_artist_search(query, **kwargs):
    cleaned_kwargs = {}
    if kwargs.get('name'):
        cleaned_kwargs['artist'] = kwargs.get('name')
    return _api.search_artists(query, **cleaned_kwargs)


class API(object):
    _api = _api

    class artists(object):
26
27
28
29
30
        search = memo(
            clean_artist_search, max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        get = memo(
            _api.get_artist_by_id,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
31
32

    class images(object):
33
34
35
        get_front = memo(
            _api.get_image_front,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
36
37

    class recordings(object):
38
39
40
41
42
43
        search = memo(
            _api.search_recordings,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        get = memo(
            _api.get_recording_by_id,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
44
45

    class works(object):
46
47
48
49
50
51
        search = memo(
            _api.search_works,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        get = memo(
            _api.get_work_by_id,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
52
53

    class releases(object):
54
55
56
57
58
59
60
61
62
        search = memo(
            _api.search_releases,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        get = memo(
            _api.get_release_by_id,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        browse = memo(
            _api.browse_releases,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
63
64
65
        # get_image_front = _api.get_image_front

    class release_groups(object):
66
67
68
69
70
71
72
73
74
        search = memo(
            _api.search_release_groups,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        get = memo(
            _api.get_release_group_by_id,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
        browse = memo(
            _api.browse_release_groups,
            max_age=settings.MUSICBRAINZ_CACHE_DURATION)
75
76
77
        # get_image_front = _api.get_image_front

api = API()