Esempio n. 1
0
def get_recommend():
    logging.debug('首页推荐条目')
    music = Music()
    with auto_logging():
        res = music._recommend()
        logging.debug(res)
        if res['code'] != current_app.config['ERROR_OK']: raise APIException()
    return res
Esempio n. 2
0
def hot_keys():
    logging.debug('热门搜索')
    music = Music()
    with auto_logging():
        res = music._hot_keys()
        if res['code'] != current_app.config['ERROR_OK']: raise APIException()
        keys = res['data']
    music_hot_keys = json_formatter(keys)
    return jsonify(music_hot_keys)
Esempio n. 3
0
def top_list():
    logging.debug('排行榜')
    music = Music()
    with auto_logging():
        res = music._top_list()
        if res['code'] != current_app.config['ERROR_OK']: raise APIException()
        top = res['data']['topList']
    music_top = json_formatter(top)
    return jsonify(music_top)
Esempio n. 4
0
def songs_url():
    logging.debug('获取歌曲url')
    music = Music()
    with auto_logging():
        mids = request.args.get('songsmid', None)
        if mids is None: return APIException()
        res = music._songs_urls(mids)
    songs_meta = json_formatter(res)
    return jsonify(songs_meta)
Esempio n. 5
0
def song_lyric(id):
    logging.debug('获取歌词')
    music = Music()
    with auto_logging():
        res = music._lyric(id)
        if res['code'] != current_app.config['ERROR_OK']: raise APIException()
        lyc = decode_bs64(res['lyric'])
    music_lyc = json_formatter(dict(songid=id, lyric=lyc))
    return jsonify(music_lyc)
Esempio n. 6
0
def search_song(keyword):
    logging.debug('搜索歌曲')
    music = Music()
    with auto_logging():
        page = int(request.args.get('page', 1))
        count = int(request.args.get('count', 20))
        res = music._search(keyword, page, count)
        if res['code'] != current_app.config['ERROR_OK']: raise APIException()
        search = res['data']['song']
        total = search['totalnum']
        all_song = get_songlist(search['list'])
    music_search = json_formatter(dict(total=total, song=all_song))
    return jsonify(music_search)
Esempio n. 7
0
 def _songs_urls(self, mids):
     """获取歌曲url"""
     guid = str(random.randrange(1000000000, 10000000000))
     params = {"guid": guid, "format": "json", "json": 3}
     s = requests.Session()
     s.headers.update(self.headers)
     r = s.get("http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg",
               params=params)
     if r.status_code != requests.codes.ok:
         raise APIException()
     j = r.json()
     if j["code"] != current_app.config['ERROR_OK']:
         raise APIException()
     vkey = j["key"]
     # "M800", "M500", "C400"
     urls = []
     for mid in mids.split(','):
         url1 = "http://dl.stream.qqmusic.qq.com/M500%s.mp3?vkey=%s&guid=%s&fromtag=1" % (
             mid, vkey, guid)
         url2 = "http://dl.stream.qqmusic.qq.com/C400%s.m4a?vkey=%s&guid=%s&fromtag=1" % (
             mid, vkey, guid)
         urls.append({mid: [url1, url2]})
     return urls
Esempio n. 8
0
def top_list_songs(topid):
    logging.debug('排行榜歌曲')
    music = Music()
    with auto_logging():
        top_res = music._top_list_songs(topid)
        if top_res['code'] != current_app.config['ERROR_OK']:
            raise APIException()
        total = top_res['total_song_num']
        _top_info = top_res['topinfo']
        top_info = dict(
            name=_top_info['ListName'],
            info=_top_info['info'],
            pic=_top_info['pic_album'],
        )
        logging.debug(top_info)
        update_time = top_res['update_time']
        all_song = get_songlist(top_res['songlist'])
    music_top_list_songs = json_formatter(
        dict(total=total,
             top_info=top_info,
             update_time=update_time,
             all_song=all_song))
    return jsonify(music_top_list_songs)
Esempio n. 9
0
def auto_logging():
    try:
        yield
    except:
        logging.error(traceback.format_exc())
        raise APIException()