Exemple #1
0
def get_artist_info(artistid, artist=None):
    '''
    Get artist info, if cached, just return it.
    Artist pic is also retrieved and saved to info['pic']
    '''
    if artistid == 0:
        url = ''.join([
            SEARCH,
            'stype=artistinfo&artist=', 
            Utils.encode_uri(artist),
            ])
    else:
        url = ''.join([
            SEARCH,
            'stype=artistinfo&artistid=', 
            str(artistid),
            ])
    #print('Net.get_artist_info, url:', url)
    req_content = urlopen(url)
    if req_content is None:
        return None
    try:
        info = Utils.json_loads_single(req_content.decode())
    except Exception as e:
        print('Error: Net.get_artist_info:', e, 'with url:', url)
        return None
    # set logo size to 100x100
    pic_path = info['pic']
    url = get_artist_pic_url(pic_path)
    if url:
        info['pic'] = get_image(url)
    else:
        info['pic'] = None
    return info
Exemple #2
0
def search_artists(keyword, page):
    url = ''.join([
        SEARCH,
        'ft=artist&pn=',
        str(page),
        '&rn=',
        str(ICON_NUM),
        '&newsearch=1&primitive=0&cluster=0',
        '&itemset=newkm&rformat=json&encoding=utf8&all=',
        parse.quote(keyword),
        ])
    #print('Net.search_artists(), ', url)
    if url not in req_cache:
        req_content = urlopen(url, use_cache=False)
        if req_content is None:
            return (None, 0, 0)
        req_cache[url] = req_content
    try:
        artists_wrap = Utils.json_loads_single(req_cache[url].decode())
    except Exception as e:
        print('Error: Net.search_artists():', e, 'with url:', url)
        return (None, 0, 0)
    hit = int(artists_wrap['TOTAL'])
    pages = math.ceil(hit / SONG_NUM)
    artists = artists_wrap['abslist']
    return (artists, hit, pages)
Exemple #3
0
def get_artist_similar(artistid, page):
    '''
    http://search.kuwo.cn/r.s?stype=similarartist&artistid=336&sortby=0&rn=20&pn=0
    Only has 10 items
    '''
    url = ''.join([
        SEARCH,
        'stype=similarartist&sortby=0&rn=',
        str(ICON_NUM),
        '&pn=',
        str(page),
        '&artistid=',
        str(artistid),
        ])
    #print('Net.get_artist_similar(), url:', url)
    req_content = urlopen(url)
    if req_content is None:
        return (None, 0)
    try:
       artists_wrap = Utils.json_loads_single(req_content.decode())
    except Exception as e:
        print('Error: Net.get_artist_similar:', e, 'with url:', url)
        return (None, 0)
    artists = artists_wrap['artistlist']
    pages = math.ceil(int(artists_wrap['total']) / ICON_NUM)
    return (artists, pages)
Exemple #4
0
def search_albums(keyword, page):
    url = ''.join([
        SEARCH,
        'ft=album&pn=',
        str(page),
        '&rn=',
        str(ICON_NUM),
        '&newsearch=1&primitive=0&cluster=0',
        '&itemset=newkm&rformat=json&encoding=utf8&all=',
        parse.quote(keyword),
        ])
    #print('search_albums:', url)
    if url not in req_cache:
        req_content = urlopen(url, use_cache=False)
        if not req_content:
            return (None, 0, 0)
        req_cache[url] = req_content
    try:
        albums_wrap = Utils.json_loads_single(req_cache[url].decode())
    except ValueError  as e:
        print('Error: Net.search_albums():', e, 'with url:', url)
        return (None, 0, 0)
    hit = int(albums_wrap['total'])
    pages = math.ceil(hit / ICON_NUM)
    albums = albums_wrap['albumlist']
    return (albums, hit, pages)
Exemple #5
0
def search_songs(keyword, page):
    url = ''.join([
        SEARCH,
        'ft=music&rn=',
        str(SONG_NUM),
        '&newsearch=1&primitive=0&cluster=0',
        '&itemset=newkm&rformat=json&encoding=utf8&all=',
        parse.quote(keyword),
        '&pn=',
        str(page),
        ])
    #print('search songs:', url)
    if url not in req_cache:
        req_content = urlopen(url, use_cache=False)
        if not req_content:
            return (None, 0, 0)
        req_cache[url] = req_content
    try:
        songs_wrap = Utils.json_loads_single(req_cache[url].decode())
    except ValueError as e:
        print('Error: Net.search_song:', e, 'with url:', url)
        return (None, 0, 0)
    hit = int(songs_wrap['TOTAL'])
    pages = math.ceil(hit / SONG_NUM)
    songs = songs_wrap['abslist']
    return (songs, hit, pages)
Exemple #6
0
def get_artist_info(artistid, artist=None):
    '''Get artist info, if cached, just return it.

    Artist pic is also retrieved and saved to info['pic']
    '''
    if artistid == 0:
        url = ''.join([
            SEARCH,
            'stype=artistinfo&artist=', 
            Utils.encode_uri(artist),
        ])
    else:
        url = ''.join([
            SEARCH,
            'stype=artistinfo&artistid=', 
            str(artistid),
        ])
    req_content = urlopen(url)
    if not req_content:
        return None
    info = Utils.json_loads_single(req_content.decode())
    if not info:
        return None
    # set logo size to 100x100
    pic_path = info['pic']
    url = get_artist_pic_url(pic_path)
    if url:
        info['pic'] = get_image(url)
    else:
        info['pic'] = None
    return info
Exemple #7
0
def search_songs(keyword, page):
    url = ''.join([
        SEARCH,
        'ft=music&rn=',
        str(SONG_NUM),
        '&newsearch=1&primitive=0&cluster=0',
        '&itemset=newkm&rformat=json&encoding=utf8&all=',
        parse.quote(keyword),
        '&pn=',
        str(page),
    ])
    #print('search songs:', url)
    if url not in req_cache:
        req_content = urlopen(url, use_cache=False)
        if not req_content:
            return (None, 0, 0)
        req_cache[url] = req_content
    try:
        songs_wrap = Utils.json_loads_single(req_cache[url].decode())
    except ValueError as e:
        print('Error: Net.search_song:', e, 'with url:', url)
        return (None, 0, 0)
    hit = int(songs_wrap['TOTAL'])
    pages = math.ceil(hit / SONG_NUM)
    songs = songs_wrap['abslist']
    return (songs, hit, pages)
Exemple #8
0
def get_artist_info(artistid, artist=None):
    '''Get artist info, if cached, just return it.

    Artist pic is also retrieved and saved to info['pic']
    '''
    if artistid == 0:
        url = ''.join([
            SEARCH,
            'stype=artistinfo&artist=',
            Utils.encode_uri(artist),
        ])
    else:
        url = ''.join([
            SEARCH,
            'stype=artistinfo&artistid=',
            str(artistid),
        ])
    #print('Net.get_artist_info, url:', url)
    req_content = urlopen(url)
    if not req_content:
        return None
    try:
        info = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get_artist_info:', e, 'with url:', url)
        return None
    # set logo size to 100x100
    pic_path = info['pic']
    url = get_artist_pic_url(pic_path)
    if url:
        info['pic'] = get_image(url)
    else:
        info['pic'] = None
    return info
Exemple #9
0
def get_artist_mv(artistid, page):
    '''
    http://search.kuwo.cn/r.s?stype=mvlist&artistid=336&sortby=0&rn=20&pn=0
    '''
    url = ''.join([
        SEARCH,
        'stype=mvlist&sortby=0&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
        ])
    print('Net.get_artist_mv(), url:', url)
    req_content = urlopen(url)
    if req_content is None:
        return (None, 0)
    try:
        mvs_wrap = Utils.json_loads_single(req_content.decode())
    except Error as e:
        print('Error: Net.get_artist_mv:', e, 'with url:', url)
        return (None, 0)
    mvs = mvs_wrap['mvlist']
    pages = math.ceil(int(mvs_wrap['total']) / ICON_NUM)
    return (mvs, pages)
Exemple #10
0
def get_artist_songs_by_id(artistid, page):
    '''
    http://search.kuwo.cn/r.s?stype=artist2music&artistid=266&pn=0&rn=20
    '''
    url = ''.join([
        SEARCH,
        'stype=artist2music&artistid=',
        str(artistid),
        '&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
        ])
    #print('Net.get_artist_songs_by_id()', url)
    req_content = urlopen(url)
    if req_content is None:
        return (None, 0)
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except Exception as e:
        print('Error: Net.get-artist_songs_by_id:', e, 'with url:', url)
        return (None, 0)
    songs = songs_wrap['musiclist']
    pages = math.ceil(int(songs_wrap['total']) / SONG_NUM)
    return (songs, pages)
Exemple #11
0
def search_albums(keyword, page):
    url = ''.join([
        SEARCH,
        'ft=album&pn=',
        str(page),
        '&rn=',
        str(ICON_NUM),
        '&newsearch=1&primitive=0&cluster=0',
        '&itemset=newkm&rformat=json&encoding=utf8&all=',
        parse.quote(keyword),
    ])
    #print('search_albums:', url)
    if url not in req_cache:
        req_content = urlopen(url, use_cache=False)
        if not req_content:
            return (None, 0, 0)
        req_cache[url] = req_content
    try:
        albums_wrap = Utils.json_loads_single(req_cache[url].decode())
    except ValueError as e:
        print('Error: Net.search_albums():', e, 'with url:', url)
        return (None, 0, 0)
    hit = int(albums_wrap['total'])
    pages = math.ceil(hit / ICON_NUM)
    albums = albums_wrap['albumlist']
    return (albums, hit, pages)
Exemple #12
0
def get_album(albumid):
    url = '{0}stype=albuminfo&albumid={1}'.format(SEARCH, albumid)
    req_content = urlopen(url)
    if not req_content:
        return None
    songs_wrap = Utils.json_loads_single(req_content.decode())
    if not songs_wrap:
        return None
    songs = songs_wrap['musiclist']
    return songs
Exemple #13
0
def get_album(albumid):
    url = '{0}stype=albuminfo&albumid={1}'.format(SEARCH, albumid)
    req_content = urlopen(url)
    if not req_content:
        return None
    songs_wrap = Utils.json_loads_single(req_content.decode())
    if not songs_wrap:
        return None
    songs = songs_wrap['musiclist']
    return songs
Exemple #14
0
def get_album(albumid):
    url = ''.join([
        SEARCH,
        'stype=albuminfo&albumid=',
        str(albumid),
        ])
    req_content = urlopen(url)
    if not req_content:
        return None
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        return None
    songs = songs_wrap['musiclist']
    return songs
Exemple #15
0
def get_album(albumid):
    url = ''.join([
        SEARCH,
        'stype=albuminfo&albumid=',
        str(albumid),
    ])
    req_content = urlopen(url)
    if not req_content:
        return None
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        return None
    songs = songs_wrap['musiclist']
    return songs
Exemple #16
0
def get_album(albumid):
    url = ''.join([
        SEARCH,
        'stype=albuminfo&albumid=',
        str(albumid),
        ])
    #print('get_album():', url)
    req_content = urlopen(url)
    if req_content is None:
        return None
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except Exception as e:
        print('Error: Net.get_album()', e, 'with url:', url)
        return None
    songs = songs_wrap['musiclist']
    return songs
Exemple #17
0
def get_artist_mv(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=mvlist&sortby=0&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    mvs_wrap = Utils.json_loads_single(req_content.decode())
    if not mvs_wrap:
        return (None, 0)
    mvs = mvs_wrap['mvlist']
    pages = math.ceil(int(mvs_wrap['total']) / ICON_NUM)
    return (mvs, pages)
Exemple #18
0
def get_artist_songs_by_id(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=artist2music&artistid=',
        str(artistid),
        '&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    songs_wrap = Utils.json_loads_single(req_content.decode())
    if not songs_wrap:
        return (None, 0)
    songs = songs_wrap['musiclist']
    pages = math.ceil(int(songs_wrap['total']) / SONG_NUM)
    return (songs, pages)
Exemple #19
0
def get_artist_songs(artist, page):
    url = ''.join([
        SEARCH,
        'ft=music&itemset=newkw&newsearch=1&cluster=0&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
        '&primitive=0&rformat=json&encoding=UTF8&artist=',
        artist,
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    songs_wrap = Utils.json_loads_single(req_content.decode())
    if not songs_wrap:
        return (None, 0)
    songs = songs_wrap['abslist']
    pages = math.ceil(int(songs_wrap['TOTAL']) / SONG_NUM)
    return (songs, pages)
Exemple #20
0
def get_artist_songs_by_id(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=artist2music&artistid=',
        str(artistid),
        '&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    songs_wrap = Utils.json_loads_single(req_content.decode())
    if not songs_wrap:
        return (None, 0)
    songs = songs_wrap['musiclist']
    pages = math.ceil(int(songs_wrap['total']) / SONG_NUM)
    return (songs, pages)
Exemple #21
0
def get_artist_mv(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=mvlist&sortby=0&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    mvs_wrap = Utils.json_loads_single(req_content.decode())
    if not mvs_wrap:
        return (None, 0)
    mvs = mvs_wrap['mvlist']
    pages = math.ceil(int(mvs_wrap['total']) / ICON_NUM)
    return (mvs, pages)
Exemple #22
0
def get_artist_songs(artist, page):
    url = ''.join([
        SEARCH,
        'ft=music&itemset=newkw&newsearch=1&cluster=0&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
        '&primitive=0&rformat=json&encoding=UTF8&artist=',
        artist,
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    songs_wrap = Utils.json_loads_single(req_content.decode())
    if not songs_wrap:
        return (None, 0)
    songs = songs_wrap['abslist']
    pages = math.ceil(int(songs_wrap['TOTAL']) / SONG_NUM)
    return (songs, pages)
Exemple #23
0
def get_artist_similar(artistid, page):
    '''Only has 10 items'''
    url = ''.join([
        SEARCH,
        'stype=similarartist&sortby=0&rn=',
        str(ICON_NUM),
        '&pn=',
        str(page),
        '&artistid=',
        str(artistid),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    artists_wrap = Utils.json_loads_single(req_content.decode())
    if not artists_wrap:
        return (None, 0)
    artists = artists_wrap['artistlist']
    pages = math.ceil(int(artists_wrap['total']) / ICON_NUM)
    return (artists, pages)
Exemple #24
0
def get_artist_albums(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=albumlist&sortby=1&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        albums_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        return (None, 0)
    albums = albums_wrap['albumlist']
    pages = math.ceil(int(albums_wrap['total']) / ICON_NUM)
    return (albums, pages)
Exemple #25
0
def get_artist_albums(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=albumlist&sortby=1&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
        ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        albums_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        return (None, 0)
    albums = albums_wrap['albumlist']
    pages = math.ceil(int(albums_wrap['total']) / ICON_NUM)
    return (albums, pages)
Exemple #26
0
def get_artist_similar(artistid, page):
    '''Only has 10 items'''
    url = ''.join([
        SEARCH,
        'stype=similarartist&sortby=0&rn=',
        str(ICON_NUM),
        '&pn=',
        str(page),
        '&artistid=',
        str(artistid),
    ])
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    artists_wrap = Utils.json_loads_single(req_content.decode())
    if not artists_wrap:
        return (None, 0)
    artists = artists_wrap['artistlist']
    pages = math.ceil(int(artists_wrap['total']) / ICON_NUM)
    return (artists, pages)
Exemple #27
0
def get_artists(catid, page, prefix):
    url = ''.join([
        ARTIST,
        'stype=artistlist&order=hot&rn=',
        str(ICON_NUM),
        '&category=',
        str(catid),
        '&pn=',
        str(page),
    ])
    if len(prefix) > 0:
        url = url + '&prefix=' + prefix
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    artists_wrap = Utils.json_loads_single(req_content.decode())
    if not artists_wrap:
        return (None, 0)
    pages = int(artists_wrap['total'])
    artists = artists_wrap['artistlist']
    return (artists, pages)
Exemple #28
0
def get_artists(catid, page, prefix):
    url = ''.join([
        ARTIST,
        'stype=artistlist&order=hot&rn=',
        str(ICON_NUM),
        '&category=',
        str(catid),
        '&pn=',
        str(page),
    ])
    if len(prefix) > 0:
        url = url + '&prefix=' + prefix
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    artists_wrap = Utils.json_loads_single(req_content.decode())
    if not artists_wrap:
        return (None, 0)
    pages = int(artists_wrap['total'])
    artists = artists_wrap['artistlist']
    return (artists, pages)
Exemple #29
0
def get_artist_mv(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=mvlist&sortby=0&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
        ])
    #print('Net.get_artist_mv(), url:', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        mvs_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get_artist_mv:', e, 'with url:', url)
        return (None, 0)
    mvs = mvs_wrap['mvlist']
    pages = math.ceil(int(mvs_wrap['total']) / ICON_NUM)
    return (mvs, pages)
Exemple #30
0
def get_artist_songs_by_id(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=artist2music&artistid=',
        str(artistid),
        '&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
        ])
    #print('Net.get_artist_songs_by_id()', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get-artist_songs_by_id:', e, 'with url:', url)
        return (None, 0)
    songs = songs_wrap['musiclist']
    pages = math.ceil(int(songs_wrap['total']) / SONG_NUM)
    return (songs, pages)
Exemple #31
0
def get_artist_songs(artist, page):
    url = ''.join([
        SEARCH,
        'ft=music&itemset=newkw&newsearch=1&cluster=0&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
        '&primitive=0&rformat=json&encoding=UTF8&artist=',
        artist,
        ])
    #print('Net.get_artist_songs()', url)
    req_content = urlopen(url)
    if req_content is None:
        return (None, 0)
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except Exception as e:
        print('Error: Net.get_artist_songs:', e, 'with url:', url)
        return (None, 0)
    songs = songs_wrap['abslist']
    pages = math.ceil(int(songs_wrap['TOTAL']) / SONG_NUM)
    return (songs, pages)
Exemple #32
0
def get_artist_mv(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=mvlist&sortby=0&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
    ])
    #print('Net.get_artist_mv(), url:', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        mvs_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get_artist_mv:', e, 'with url:', url)
        return (None, 0)
    mvs = mvs_wrap['mvlist']
    pages = math.ceil(int(mvs_wrap['total']) / ICON_NUM)
    return (mvs, pages)
Exemple #33
0
def get_artist_songs_by_id(artistid, page):
    url = ''.join([
        SEARCH,
        'stype=artist2music&artistid=',
        str(artistid),
        '&rn=',
        str(SONG_NUM),
        '&pn=',
        str(page),
    ])
    #print('Net.get_artist_songs_by_id()', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        songs_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get-artist_songs_by_id:', e, 'with url:', url)
        return (None, 0)
    songs = songs_wrap['musiclist']
    pages = math.ceil(int(songs_wrap['total']) / SONG_NUM)
    return (songs, pages)
Exemple #34
0
def search_artists(keyword, page):
    url = ''.join([
        SEARCH,
        'ft=artist&pn=',
        str(page),
        '&rn=',
        str(ICON_NUM),
        '&newsearch=1&primitive=0&cluster=0',
        '&itemset=newkm&rformat=json&encoding=utf8&all=',
        parse.quote(keyword),
    ])
    if url not in req_cache:
        req_content = urlopen(url, use_cache=False)
        if not req_content:
            return (None, 0, 0)
        req_cache[url] = req_content
    artists_wrap = Utils.json_loads_single(req_cache[url].decode())
    if not artists_wrap:
        return (None, 0, 0)
    hit = int(artists_wrap['TOTAL'])
    pages = math.ceil(hit / SONG_NUM)
    artists = artists_wrap['abslist']
    return (artists, hit, pages)
Exemple #35
0
def get_artist_similar(artistid, page):
    '''Only has 10 items'''
    url = ''.join([
        SEARCH,
        'stype=similarartist&sortby=0&rn=',
        str(ICON_NUM),
        '&pn=',
        str(page),
        '&artistid=',
        str(artistid),
    ])
    #print('Net.get_artist_similar(), url:', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        artists_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get_artist_similar:', e, 'with url:', url)
        return (None, 0)
    artists = artists_wrap['artistlist']
    pages = math.ceil(int(artists_wrap['total']) / ICON_NUM)
    return (artists, pages)
Exemple #36
0
def get_artists(catid, page, prefix):
    url = ''.join([
        ARTIST,
        'stype=artistlist&order=hot&rn=',
        str(ICON_NUM),
        '&category=',
        str(catid),
        '&pn=',
        str(page),
        ])
    if len(prefix) > 0:
        url = url + '&prefix=' + prefix
    #print('Net.get_artists(), url:', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        artists_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get_artists:', e, 'with url:', url)
        return (None, 0)
    pages = int(artists_wrap['total'])
    artists = artists_wrap['artistlist']
    return (artists, pages)
Exemple #37
0
def get_artist_albums(artistid, page):
    '''http://search.kuwo.cn/r.s?stype=albumlist&artistid=336&sortby=1&rn=20&pn=0
    '''
    url = ''.join([
        SEARCH,
        'stype=albumlist&sortby=1&rn=',
        str(ICON_NUM),
        '&artistid=',
        str(artistid),
        '&pn=',
        str(page),
        ])
    #print('Net.get_artist_albums(), url:', url)
    req_content = urlopen(url)
    if req_content is None:
        return (None, 0)
    try:
        albums_wrap = Utils.json_loads_single(req_content.decode())
    except Exception as e:
        print('Error:', e)
        return (None, 0)
    albums = albums_wrap['albumlist']
    pages = math.ceil(int(albums_wrap['total']) / ICON_NUM)
    return (albums, pages)
Exemple #38
0
def get_artists(catid, page, prefix):
    url = ''.join([
        ARTIST,
        'stype=artistlist&order=hot&rn=',
        str(ICON_NUM),
        '&category=',
        str(catid),
        '&pn=',
        str(page),
    ])
    if len(prefix) > 0:
        url = url + '&prefix=' + prefix
    #print('Net.get_artists(), url:', url)
    req_content = urlopen(url)
    if not req_content:
        return (None, 0)
    try:
        artists_wrap = Utils.json_loads_single(req_content.decode())
    except ValueError as e:
        print('Error: Net.get_artists:', e, 'with url:', url)
        return (None, 0)
    pages = int(artists_wrap['total'])
    artists = artists_wrap['artistlist']
    return (artists, pages)