示例#1
0
 def test_ne_uri(self):
     artist1 = Artist(uri="uri1")
     artist2 = Artist(uri="uri2")
     assert artist1 != artist2
     assert hash(artist1) != hash(artist2)
示例#2
0
 def test_eq(self):
     artist1 = Artist(uri="uri", name="name", musicbrainz_id="id")
     artist2 = Artist(uri="uri", name="name", musicbrainz_id="id")
     assert artist1 == artist2
     assert hash(artist1) == hash(artist2)
示例#3
0
 def test_eq_other(self):
     assert Artist() != "other"
示例#4
0
 def test_to_json_and_back_with_field_matching_internal_field(self):
     artist = Artist(uri="uri", name="name").serialize()
     artist["__mro__"] = "foo"
     serialized = json.dumps(artist)
     with self.assertRaises(TypeError):
         json.loads(serialized, object_hook=model_json_decoder)
示例#5
0
 def test_eq_uri(self):
     artist1 = Artist(uri="uri")
     artist2 = Artist(uri="uri")
     assert artist1 == artist2
     assert hash(artist1) == hash(artist2)
示例#6
0
 def test_copying_artist(self):
     artist = Artist()
     self.compare(artist, artist.copy())
示例#7
0
 def test_repr(self):
     assert "Artist(name='name', uri='uri')" == repr(
         Artist(uri="uri", name="name"))
示例#8
0
 def test_multiple_track_performe_name(self):
     self.tags['performer'] = ['performer1', 'performer2']
     performers = [Artist(name='performer1'), Artist(name='performer2')]
     self.check(self.track.replace(performers=performers))
示例#9
0
 def test_multiple_album_artist_name(self):
     self.tags['album-artist'] = ['name1', 'name2']
     artists = [Artist(name='name1'), Artist(name='name2')]
     album = self.track.album.replace(artists=artists)
     self.check(self.track.replace(album=album))
示例#10
0
 def test_multiple_track_artist_name(self):
     self.tags['artist'] = ['name1', 'name2']
     artists = [Artist(name='name1'), Artist(name='name2')]
     self.check(self.track.replace(artists=artists))
示例#11
0
 def test_multiple_track_composer_name(self):
     self.tags['composer'] = ['composer1', 'composer2']
     composers = [Artist(name='composer1'), Artist(name='composer2')]
     self.check(self.track.replace(composers=composers))
示例#12
0
def _make_artist(name: str):
    uri = str(ArtistUri(make_hash(name)))
    return Artist(uri=uri, name=name)
示例#13
0
from mopidy.models import Album, Artist, Ref, Track, Image
import logging

logger = logging.getLogger(__name__)

_rnz_artist = Artist(name='RNZ')

_national_album = Album(
    artists=[_rnz_artist],
    #  images = ['http://www.radionz.co.nz/brand-images/rnz-national.jpg'],
    name='RNZ National',
)

_concert_album = Album(
    artists=[_rnz_artist],
    #  images = ['http://www.radionz.co.nz/brand-images/rnz-concert.jpg'],
    name='RNZ Concert',
)

_news_album = Album(
    artists=[_rnz_artist],
    #  images = ['http://www.radionz.co.nz/brand-images/rnz-news.jpg'],
    name='RNZ News',
)

_parliament_album = Album(
    artists=[_rnz_artist],
    #  images = ['http://www.radionz.co.nz/brand-images/rnz-parliament.jpg'],
    name='RNZ Parliament',
)
示例#14
0
 def build_track(self):
     if self.albumartist:
         self.album['artists'] = [Artist(**self.albumartist)]
     self.track['album'] = Album(**self.album)
     self.track['artists'] = [Artist(**self.artist)]
     return Track(**self.track)
示例#15
0
 def test_name(self):
     name = 'a name'
     artist = Artist(name=name)
     self.assertEqual(artist.name, name)
     with self.assertRaises(AttributeError):
         artist.name = None
示例#16
0
 def test_sortname(self):
     self.tags['musicbrainz-sortname'] = ['another_sortname']
     artist = Artist(name='artist',
                     sortname='another_sortname',
                     musicbrainz_id='artistid')
     self.check(self.track.replace(artists=[artist]))
示例#17
0
 def test_replace_artist(self):
     artist = Artist()
     self.compare(artist, artist.replace())
示例#18
0
 def test_missing_sortname(self):
     del self.tags['musicbrainz-sortname']
     artist = Artist(name='artist',
                     sortname=None,
                     musicbrainz_id='artistid')
     self.check(self.track.replace(artists=[artist]))
示例#19
0
            type='track',
            uri='emby:track:7739d3830818c7aacf6c346172384914'),
        Ref(name=u'Five Silent Miles',
            type='track',
            uri='emby:track:f84df9f70e592a3abda82b1d78026608')
    ]

    with open('tests/data/get_tracks0.json', 'r') as f:
        r_get_mock.return_value = json.load(f)

    assert emby_client.get_tracks(0) == expected


@pytest.mark.parametrize('data,expected', [
    ('tests/data/track0.json',
     Track(album=Album(artists=[Artist(name=u'Chairlift')], name=u'Moth'),
           artists=[Artist(name=u'Chairlift')],
           length=295915,
           name=u'Ottawa to Osaka',
           track_no=6,
           uri='emby:track:18e5a9871e6a4a2294d5af998457ca16')),
    ('tests/data/track1.json',
     Track(album=Album(artists=[Artist(name=u'Chairlift')], name=u'Moth'),
           artists=[Artist(name=u'Chairlift')],
           length=269035,
           name=u'Crying in Public',
           track_no=5,
           uri='emby:track:37f57f0b370274af96de06895a78c2c3')),
    ('tests/data/track2.json',
     Track(album=Album(artists=[Artist(name=u'Chairlift')], name=u'Moth'),
           artists=[Artist(name=u'Chairlift')],
示例#20
0
    def browse(self, uri):
        logger.debug("browse() %s for backend: %s", uri, self.backend)
        result = []

        if not uri.startswith('rnz:'):
            return result

        if uri == 'rnz:root':
            result.append(
                Ref.track(name='Latest News Bulletin', uri='rnz:news'))
            result.append(Ref.directory(name='Streams', uri='rnz:streams'))
            result.append(Ref.directory(name='Podcasts', uri='rnz:podcasts'))
            return result

        if uri == 'rnz:streams':
            return [
                Ref.track(name=stream.name, uri='rnz:stream:%s' % stream.name)
                for stream in content.streams
            ]

        if uri == 'rnz:podcasts':
            return [
                Ref.directory(name=podcast['title'],
                              uri='rnz:podcast:%s' % podcast['title'])
                for podcast in self.get_podcasts()
            ]

        if uri.startswith('rnz:podcast:'):
            title = uri[12:]
            podcast = self.podcasts_map[title]
            podcast_url = podcast['urls']
            r = self.download(podcast_url)

            if r.status_code != 200:
                logging.error("failed to download %s", podcast_url)
                return None

            tree = ET.fromstring(r.text.encode('utf-8'))

            album = Album(
                artists=[Artist(name='RNZ')],
                images=[podcast['imageURL']],
                name=podcast['title'],
            )

            for item in tree.iter('item'):
                title = item.find('title').text.strip()
                logger.debug("got title %s", title)

                duration = item.find('itunes:duration', self.NAMESPACES)

                if duration is not None:
                    logger.debug("got duration %s", duration.text.strip())

                track_url = item.find('enclosure').get('url')

                result.append(
                    Ref.track(
                        name=title,
                        uri='rnz:podcast_item:%s' % track_url,
                    ))

                track_date = item.find('pubDate').text.strip()
                logger.debug("track_date: %s", track_date)
                track_date = parse_date(track_date).strftime('%Y-%m-%d')

                self.podcast_items[track_url] = Track(
                    name=title,
                    album=album,
                    artists=[Artist(name='RNZ')],
                    uri=track_url,
                    comment=item.find('description').text.strip(),
                    date=track_date,
                    length=_duration(
                        item.find('itunes:duration',
                                  self.NAMESPACES).text.strip()) * 1000)
            return result

        return []
示例#21
0
 def test_to_json_and_back(self):
     artist1 = Artist(uri="uri", name="name")
     serialized = json.dumps(artist1, cls=ModelJSONEncoder)
     artist2 = json.loads(serialized, object_hook=model_json_decoder)
     assert artist1 == artist2
示例#22
0
def _convert_mpd_data(data, tracks, music_dir):
    if not data:
        return

    # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5
    # See https://github.com/mopidy/mopidy/issues/302 for details.

    track_kwargs = {}
    album_kwargs = {}
    artist_kwargs = {}
    albumartist_kwargs = {}

    if 'track' in data:
        if '/' in data['track']:
            album_kwargs[b'num_tracks'] = int(data['track'].split('/')[1])
            track_kwargs[b'track_no'] = int(data['track'].split('/')[0])
        else:
            track_kwargs[b'track_no'] = int(data['track'])

    if 'artist' in data:
        artist_kwargs[b'name'] = data['artist']
        albumartist_kwargs[b'name'] = data['artist']

    if 'albumartist' in data:
        albumartist_kwargs[b'name'] = data['albumartist']

    if 'album' in data:
        album_kwargs[b'name'] = data['album']

    if 'title' in data:
        track_kwargs[b'name'] = data['title']

    if 'date' in data:
        track_kwargs[b'date'] = data['date']

    if 'musicbrainz_trackid' in data:
        track_kwargs[b'musicbrainz_id'] = data['musicbrainz_trackid']

    if 'musicbrainz_albumid' in data:
        album_kwargs[b'musicbrainz_id'] = data['musicbrainz_albumid']

    if 'musicbrainz_artistid' in data:
        artist_kwargs[b'musicbrainz_id'] = data['musicbrainz_artistid']

    if 'musicbrainz_albumartistid' in data:
        albumartist_kwargs[b'musicbrainz_id'] = (
            data['musicbrainz_albumartistid'])

    if artist_kwargs:
        artist = Artist(**artist_kwargs)
        track_kwargs[b'artists'] = [artist]

    if albumartist_kwargs:
        albumartist = Artist(**albumartist_kwargs)
        album_kwargs[b'artists'] = [albumartist]

    if album_kwargs:
        album = Album(**album_kwargs)
        track_kwargs[b'album'] = album

    if data['file'][0] == '/':
        path = data['file'][1:]
    else:
        path = data['file']
    path = urllib.unquote(path.encode('utf-8'))

    if isinstance(music_dir, unicode):
        music_dir = music_dir.encode('utf-8')

    # Make sure we only pass bytestrings to path_to_uri to avoid implicit
    # decoding of bytestrings to unicode strings
    track_kwargs[b'uri'] = path_to_uri(music_dir, path)

    track_kwargs[b'length'] = int(data.get('time', 0)) * 1000

    track = Track(**track_kwargs)
    tracks.add(track)
示例#23
0
 def test_eq_name(self):
     artist1 = Artist(name="name")
     artist2 = Artist(name="name")
     assert artist1 == artist2
     assert hash(artist1) == hash(artist2)
示例#24
0
    def _convert_json_data(self, data, remote_url=False):
        if not data:
            return

        track_kwargs = {}
        album_kwargs = {}
        artist_kwargs = {}
        albumartist_kwargs = {}

        if 'track' in data:
            track_kwargs['track_no'] = int(data['track'])

        if 'tracktotal' in data:
            album_kwargs['num_tracks'] = int(data['tracktotal'])

        if 'artist' in data:
            artist_kwargs['name'] = data['artist']
            albumartist_kwargs['name'] = data['artist']

        if 'albumartist' in data:
            albumartist_kwargs['name'] = data['albumartist']

        if 'album' in data:
            album_kwargs['name'] = data['album']

        if 'title' in data:
            track_kwargs['name'] = data['title']

        if 'date' in data:
            track_kwargs['date'] = data['date']

        if 'mb_trackid' in data:
            track_kwargs['musicbrainz_id'] = data['mb_trackid']

        if 'mb_albumid' in data:
            album_kwargs['musicbrainz_id'] = data['mb_albumid']

        if 'mb_artistid' in data:
            artist_kwargs['musicbrainz_id'] = data['mb_artistid']

        if 'mb_albumartistid' in data:
            albumartist_kwargs['musicbrainz_id'] = (
                data['mb_albumartistid'])

        if 'album_id' in data:
            album_art_url = '%s/album/%s/art' % (
                self.api_endpoint, data['album_id'])
            album_kwargs['images'] = [album_art_url]

        if artist_kwargs:
            artist = Artist(**artist_kwargs)
            track_kwargs['artists'] = [artist]

        if albumartist_kwargs:
            albumartist = Artist(**albumartist_kwargs)
            album_kwargs['artists'] = [albumartist]

        if album_kwargs:
            album = Album(**album_kwargs)
            track_kwargs['album'] = album

        if remote_url:
            track_kwargs['uri'] = '%s/item/%s/file' % (
                self.api_endpoint, data['id'])
        else:
            track_kwargs['uri'] = 'beets:track;%s' % data['id']
        track_kwargs['length'] = int(data.get('length', 0)) * 1000

        track = Track(**track_kwargs)

        return track
示例#25
0
 def test_eq_musibrainz_id(self):
     artist1 = Artist(musicbrainz_id="id")
     artist2 = Artist(musicbrainz_id="id")
     assert artist1 == artist2
     assert hash(artist1) == hash(artist2)
示例#26
0
 def test_artists(self):
     artists = [Artist(), Artist(), Artist()]
     result = SearchResult(artists=artists)
     assert list(result.artists) == artists
     with self.assertRaises(AttributeError):
         result.artists = None
示例#27
0
 def test_eq_none(self):
     assert Artist() is not None
示例#28
0
 def test_uri(self):
     uri = "an_uri"
     artist = Artist(uri=uri)
     assert artist.uri == uri
     with self.assertRaises(AttributeError):
         artist.uri = None
示例#29
0
 def test_ne_name(self):
     artist1 = Artist(name="name1")
     artist2 = Artist(name="name2")
     assert artist1 != artist2
     assert hash(artist1) != hash(artist2)
示例#30
0
 def test_name(self):
     name = "a name"
     artist = Artist(name=name)
     assert artist.name == name
     with self.assertRaises(AttributeError):
         artist.name = None
示例#31
0
 def test_uri(self):
     uri = 'an_uri'
     artist = Artist(uri=uri)
     self.assertEqual(artist.uri, uri)
     with self.assertRaises(AttributeError):
         artist.uri = None
示例#32
0
 def test_musicbrainz_id(self):
     mb_id = "mb-id"
     artist = Artist(musicbrainz_id=mb_id)
     assert artist.musicbrainz_id == mb_id
     with self.assertRaises(AttributeError):
         artist.musicbrainz_id = None
示例#33
0
 def test_musicbrainz_id(self):
     mb_id = 'mb-id'
     artist = Artist(musicbrainz_id=mb_id)
     self.assertEqual(artist.musicbrainz_id, mb_id)
     with self.assertRaises(AttributeError):
         artist.musicbrainz_id = None
示例#34
0
 def test_invalid_kwarg(self):
     with self.assertRaises(TypeError):
         Artist(foo="baz")
示例#35
0
 def test_serialize_with_artists(self):
     artist = Artist(name='foo')
     self.assertDictEqual(
         {'__model__': 'Track', 'uri': 'uri', 'name': 'name',
             'artists': [artist.serialize()]},
         Track(uri='uri', name='name', artists=[artist]).serialize())
示例#36
0
    def test_invalid_kwarg_with_name_matching_method(self):
        with self.assertRaises(TypeError):
            Artist(replace="baz")

        with self.assertRaises(TypeError):
            Artist(serialize="baz")
示例#37
0
 def test_serialize_with_artists(self):
     artist = Artist(name="foo")
     self.assertDictEqual(
         {"__model__": "Track", "uri": "uri", "name": "name", "artists": [artist.serialize()]},
         Track(uri="uri", name="name", artists=[artist]).serialize(),
     )
示例#38
0
 def test_serialize_with_artists(self):
     artist = Artist(name="foo")
     self.assertDictEqual(
         {"uri": "uri", "name": "name", "artists": [artist.serialize()]},
         Album(uri="uri", name="name", artists=[artist]).serialize(),
     )