示例#1
0
def create_image(uri):
    uri = Uri.from_uri(uri)

    if uri is None:
        return None

    return Image.from_id(uri.code)
示例#2
0
def create_image(uri):
    uri = Uri.from_uri(uri)

    if uri is None:
        return None

    return Image.from_id(uri.code)
示例#3
0
 def parse(cls, sp, data, parser):
     return Artist(
         sp, {
             'name': data.get('name'),
             'gid': Uri.from_uri(data.get('uri')).to_gid(),
             'portrait': [{
                 'imageUri': data.get('imageUri')
             }]
         }, parser.MercuryJSON, parser)
示例#4
0
 def parse(cls, sp, data, parser):
     return Artist(sp, {
         'name': data.get('name'),
         'gid': Uri.from_uri(data.get('uri')).to_gid(),
         'portrait': [
             {
                 'imageUri': data.get('imageUri')
             }
         ]
     }, parser.MercuryJSON, parser)
示例#5
0
    def parse(cls, sp, data, parser):
        if type(data) is not dict:
            data = etree_convert(data)

        return Playlist(sp, {
            'uri': Uri.from_uri(data.get('uri')),
            'attributes': {
                'name': data.get('name')
            },
            'image': data.get('image')
        }, parser.XML, parser)
示例#6
0
    def reply_mercury_json(self, data):
        self.response_type = Parser.MercuryJSON

        if self.multi is None:
            self.multi = True

        data = json.loads(data)

        for item in data:
            uri = Uri.from_uri(item.get('uri'))
            yield uri.type, item
示例#7
0
    def reply_mercury_json(self, data):
        self.response_type = Parser.MercuryJSON

        if self.multi is None:
            self.multi = True

        data = json.loads(data)

        for item in data:
            uri = Uri.from_uri(item.get('uri'))
            yield uri.type, item
示例#8
0
    def playlists(self, username, start=0, count=100, callback=None):
        if count > 100:
            raise ValueError("You may only request up to 100 playlists at once")

        request = HermesRequest(self.sp, {
            'method': 'GET',
            'uri': 'hm://playlist/user/%s/rootlist?from=%s&length=%s' % (self.uri_quote(username), start, count)
        }, Playlist, defaults={
            'uri': Uri.from_uri('spotify:user:%s:rootlist' % username)
        })

        return self.request_wrapper(request, callback)
示例#9
0
    def parse(cls, sp, data, parser):
        if type(data) is not dict:
            data = etree_convert(data)

        return Playlist(
            sp, {
                'uri': Uri.from_uri(data.get('uri')),
                'attributes': {
                    'name': data.get('name')
                },
                'image': data.get('image')
            }, parser.XML, parser)
示例#10
0
    def playlists(self, username, start=0, count=100, callback=None):
        if count > 100:
            raise ValueError("You may only request up to 100 playlists at once")

        request = HermesRequest(self.sp, {
            'method': 'GET',
            'uri': 'hm://playlist/user/%s/rootlist?from=%s&length=%s' % (self.uri_quote(username), start, count)
        }, Playlist, defaults={
            'uri': Uri.from_uri('spotify:user:%s:rootlist' % username)
        })

        return self.request_wrapper(request, callback)
示例#11
0
    def parse(cls, sp, data, parser):
        image_uri = None

        if data.get('image'):
            image_uri = 'spotify:image:' + data.get('image')

        return Playlist(sp, {
            'uri': Uri.from_uri(data.get('uri')),
            'attributes': {
                'name': data.get('title')
            },
            'image': image_uri
        }, parser.Tunigo, parser)
示例#12
0
    def playlist(self, uri, start=0, count=100, callback=None):
        if type(uri) is Uri:
            uri = str(uri)

        parts = [self.uri_quote(p) for p in uri.split(':')]

        request = HermesRequest(self.sp, {
            'method': 'GET',
            'uri': 'hm://playlist/%s?from=%s&length=%s' % ('/'.join(parts[1:]), start, count)
        }, Playlist, defaults={
            'uri': Uri.from_uri(uri)
        })

        return self.request_wrapper(request, callback)
示例#13
0
    def playlist(self, uri, start=0, count=100, callback=None):
        if type(uri) is Uri:
            uri = str(uri)

        parts = [self.uri_quote(p) for p in uri.split(":")]

        request = HermesRequest(
            self.sp,
            {"method": "GET", "uri": "hm://playlist/%s?from=%s&length=%s" % ("/".join(parts[1:]), start, count)},
            Playlist,
            defaults={"uri": Uri.from_uri(uri)},
        )

        return self.request_wrapper(request, callback)
示例#14
0
    def playlist(self, uri, start=0, count=100, callback=None):
        if type(uri) is Uri:
            uri = str(uri)

        parts = [self.uri_quote(p) for p in uri.split(':')]

        request = HermesRequest(self.sp, {
            'method': 'GET',
            'uri': 'hm://playlist/%s?from=%s&length=%s' % ('/'.join(parts[1:]), start, count)
        }, Playlist, defaults={
            'uri': Uri.from_uri(uri)
        })

        return self.request_wrapper(request, callback)
示例#15
0
    def parse(cls, sp, data, parser):
        image_uri = None

        if data.get('image'):
            image_uri = 'spotify:image:' + data.get('image')

        return Playlist(
            sp, {
                'uri': Uri.from_uri(data.get('uri')),
                'attributes': {
                    'name': data.get('title')
                },
                'image': image_uri
            }, parser.Tunigo, parser)
示例#16
0
 def parse(cls, sp, data, parser):
     return Album(sp, {
         'gid': Uri.from_uri(data.get('uri')).to_gid(),
         'name': data.get('albumName'),
         'artist': [
             {
                 'artistName': data.get('artistName')
             }
         ],
         'cover': [
             {
                 'image': data.get('image')
             }
         ],
     }, parser.Tunigo, parser)
示例#17
0
    def playlists(self, username, start=0, count=100, callback=None):
        if count > 100:
            raise ValueError("You may only request up to 100 playlists at once")

        request = HermesRequest(
            self.sp,
            {
                "method": "GET",
                "uri": "hm://playlist/user/%s/rootlist?from=%s&length=%s" % (self.uri_quote(username), start, count),
            },
            Playlist,
            defaults={"uri": Uri.from_uri("spotify:user:%s:rootlist" % username)},
        )

        return self.request_wrapper(request, callback)
示例#18
0
 def parse(cls, sp, data, parser):
     return Album(sp, {
         'name': data.get('name'),
         'gid': Uri.from_uri(data.get('uri')).to_gid(),
         'artist': [
             {
                 'uri': data.get('artistUri'),
                 'name': data.get('artistName')
             }
         ],
         'cover': [
             {
                 'imageUri': data.get('imageUri'),
             }
         ]
     }, parser.MercuryJSON, parser)
示例#19
0
    def list(self, group=None, flat=False):
        if group:
            # Pull the code from a group URI
            parts = group.split(':')
            group = parts[2] if len(parts) == 4 else group

        path = []

        for item in self.items:
            if item.uri.type == 'start-group':
                # Ignore groups if we are returning a flat list
                if flat:
                    continue

                # Only return placeholders on the root level
                if (not group and not path) or (path and path[-1] == group):
                    # Return group placeholder
                    yield PlaylistItem(self.sp).dict_update({
                        'uri':
                        Uri.from_uri('spotify:group:%s:%s' %
                                     (item.uri.code, item.uri.title)),
                        'name':
                        item.uri.title
                    })

                path.append(item.uri.code)
                continue
            elif item.uri.type == 'end-group':
                # Group close tag
                if path and path.pop() == group:
                    return

                continue

            if group is None:
                # Ignore if we are inside a group
                if path and not flat:
                    continue
            else:
                # Ignore if we aren't inside the specified group
                if not path or path[-1] != group:
                    continue

            # Return item
            yield item
示例#20
0
    def list(self, group=None, flat=False):
        if group:
            # Pull the code from a group URI
            parts = group.split(':')
            group = parts[2] if len(parts) == 4 else group

        path = []

        for item in self.items:
            if item.uri.type == 'start-group':
                # Ignore groups if we are returning a flat list
                if flat:
                    continue

                # Only return placeholders on the root level
                if (not group and not path) or (path and path[-1] == group):
                    # Return group placeholder
                    yield PlaylistItem(self.sp).dict_update({
                        'uri': Uri.from_uri('spotify:group:%s:%s' % (item.uri.code, item.uri.title)),
                        'name': item.uri.title
                    })

                path.append(item.uri.code)
                continue
            elif item.uri.type == 'end-group':
                # Group close tag
                if path and path.pop() == group:
                    return

                continue

            if group is None:
                # Ignore if we are inside a group
                if path and not flat:
                    continue
            else:
                # Ignore if we aren't inside the specified group
                if not path or path[-1] != group:
                    continue

            # Return item
            yield item
示例#21
0
    def get(self, uris, callback=None):
        log.debug("metadata(%s)", uris)

        multi = type(uris) is list

        if type(uris) is not list:
            uris = [uris]

        # array of "request" Objects that will be protobuf'd
        requests = []
        h_type = ""

        for uri in uris:
            if type(uri) is not Uri:
                uri = Uri.from_uri(uri)

            if uri.type == "local":
                log.debug('ignoring "local" track URI: %s', uri)
                continue

            h_type = uri.type

            requests.append({"method": "GET", "uri": "hm://metadata/%s/%s" % (uri.type, uri.to_id())})

        # Build ProtoRequest
        request = HermesRequest(
            self.sp,
            requests,
            {
                "vnd.spotify/metadata-artist": Artist,
                "vnd.spotify/metadata-album": Album,
                "vnd.spotify/metadata-track": Track,
            },
            {"method": "GET", "uri": "hm://metadata/%ss" % h_type},
            container="objects",
            multi=multi,
        )

        return self.request_wrapper(request, callback)
示例#22
0
    def get(self, uris, callback=None):
        log.debug('metadata(%s)', uris)

        multi = type(uris) is list

        if type(uris) is not list:
            uris = [uris]

        # array of "request" Objects that will be protobuf'd
        requests = []
        h_type = ''

        for uri in uris:
            if type(uri) is not Uri:
                uri = Uri.from_uri(uri)

            if uri.type == 'local':
                log.debug('ignoring "local" track URI: %s', uri)
                continue

            h_type = uri.type

            requests.append({
                'method': 'GET',
                'uri': 'hm://metadata/%s/%s' % (uri.type, uri.to_id())
            })

        # Build ProtoRequest
        request = HermesRequest(self.sp, requests, {
            'vnd.spotify/metadata-artist': Artist,
            'vnd.spotify/metadata-album': Album,
            'vnd.spotify/metadata-track': Track
        }, {
            'method': 'GET',
            'uri': 'hm://metadata/%ss' % h_type
        }, multi=multi)

        return self.request_wrapper(request, callback)
示例#23
0
    def get(self, uris, callback=None):
        log.debug('metadata(%s)', uris)

        multi = type(uris) is list

        if type(uris) is not list:
            uris = [uris]

        # array of "request" Objects that will be protobuf'd
        requests = []
        h_type = ''

        for uri in uris:
            if type(uri) is not Uri:
                uri = Uri.from_uri(uri)

            if uri.type == 'local':
                log.debug('ignoring "local" track URI: %s', uri)
                continue

            h_type = uri.type

            requests.append({
                'method': 'GET',
                'uri': 'hm://metadata/%s/%s' % (uri.type, uri.to_id())
            })

        # Build ProtoRequest
        request = HermesRequest(self.sp, requests, {
            'vnd.spotify/metadata-artist': Artist,
            'vnd.spotify/metadata-album': Album,
            'vnd.spotify/metadata-track': Track
        }, {
            'method': 'GET',
            'uri': 'hm://metadata/%ss' % h_type
        }, container='objects', multi=multi)

        return self.request_wrapper(request, callback)