Ejemplo n.º 1
0
def Return_User_Song_List_Detail():
    """
    用于向前端返回某一个歌单的详细信息(
                                包括歌单的名称,
                                歌单id,
                                每首歌曲id,
                                歌曲名称,
                                歌曲演唱者
                                )
    """
    global re_dict
    data = request.get_data()     
    try:
        dict_data          = json.loads(data)      
    except:
        re_dict            = _Return_Error_Post(code=ReturnStatus.ERROR_PSOT_DATA, status="Failed", detail = "ERROR_PSOT_DATA")
    try:
        song_list_platform = dict_data["platform"]
    except:
        re_dict            = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS, status="Failed", detail = "ERROR_PARAMS")
    
    song_list_id           = dict_data["id"]
    page                   = dict_data['page']


    if song_list_platform == "Neteasymusic":
        return_user_song_list = neteasy_Hot_Song_List.Hot_Song_List()
        re_dict               = return_user_song_list.Download_SongList(song_list_id)
    
    elif song_list_platform == "Xiamimusic":
        return_song_list = xiami_Song_List.XiamiApi()
        re_dict          = retrun_song_list.getPlaylist(song_list_id)

    elif song_list_platform == "Kugoumusic":
        return_user_song_list = kugou_scrawl.Kugou()
        re_dict               = return_user_song_list.ReturnSongList(song_list_id, page)
    else:
        re_dict = _Return_Error_Post(code=ReturnStatus.NO_SUPPORT, status="Failed", detail = "NO_SUPPORT")


    if re_dict:
        re_dict.update(_Return_Error_Post(code=ReturnStatus.SUCCESS, status="Success", detail="SUCCESS"))
    else:
        re_dict.update(_Return_Error_Post(code=ReturnStatus.ERROR_SEVER, status="Failed", detail="ERROR_SEVER"))
    
    response = Response(json.dumps(re_dict), mimetype = 'application/json')    
    response.headers.add('Server','python flask')     
    response.headers['Access-Control-Allow-Origin']   = '*'
    response.headers['Access-Control-Allow-Methods']  = 'OPTIONS,HEAD,GET,POST'
    response.headers['Access-Control-Allow-Headers']  = 'x-requested-with'          
    return response
Ejemplo n.º 2
0
def Return_Random_User_Song_List():
    """
    用于向前端返回20个热门歌单信息
    允许GET、POST任何请求均可
    """
    global re_dict
    if request.method == "POST":
        pass
        # 暂时重新修改代码
    else:

        KugouTopSongList = kugou_scrawl.Kugou()
        re_dict          = KugouTopSongList.TopSongList()
        print(re_dict)

        response         = Response(json.dumps(re_dict), mimetype = 'application/json')    
        response.headers.add('Server','python flask')       
        return response
Ejemplo n.º 3
0
def play_id():
    """
    用于前端请求歌曲id时服务器针对性的反馈方法
    基本内容如上.
    """
    global re_dict
    if request.method == 'POST':
        data = request.get_data()
        dict_data = json.loads(data)

        try:
            music_platform = dict_data['platform']
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="ERROR_PARAMS")
        else:
            if music_platform != '' or music_platform != None:
                if music_platform == "Neteasymusic":

                    neteasymusic_id = neteasy_scrawl.Netmusic()
                    music_id = dict_data["id"]
                    re_dict = neteasymusic_id.music_id_requests(music_id)
                    if re_dict:
                        re_dict.update({
                            "code": ReturnStatus.SUCCESS,
                            "status": "Success"
                        })
                    else:
                        re_dict = _Return_Error_Post(
                            code=ReturnStatus.NO_MUSIC_DETAIL,
                            status="Failed",
                            detail="NO_MUSIC_DETAIL")
                elif music_platform == "Xiamimusic":
                    try:
                        music_id = dict_data["id"]
                    except KeyError:
                        re_dict = _Return_Error_Post(
                            code=ReturnStatus.ERROR_PARAMS,
                            status="Failed",
                            detail="ERROR_PARAMS")
                    else:
                        re_dict = xiami_scrawl.Search_xiami.id_req(music_id)
                        print(re_dict)
                        if re_dict:
                            re_dict.update({
                                "code": ReturnStatus.SUCCESS,
                                "status": "Success"
                            })
                        else:
                            re_dict = _Return_Error_Post(
                                code=ReturnStatus.OVER_MAXPAGE,
                                status="Failed",
                                detail="OVER_MAXPAGE")

                elif music_platform == "QQmusic":
                    qqmusic_id = qq_scrawl.QQMusic()
                    re_dict = qqmusic_id.search_by_id(dict_data["id"])

                    if re_dict:
                        re_dict.update({
                            "code": ReturnStatus.SUCCESS,
                            "status": "Success"
                        })
                    else:
                        re_dict = _Return_Error_Post(
                            code=ReturnStatus.OVER_MAXPAGE,
                            status="Failed",
                            detail="OVER_MAXPAGE")

                elif music_platform == "Kugoumusic":
                    kugou = kugou_scrawl.Kugou()
                    re_dict = kugou.hash_search(dict_data["id"])

                    if re_dict:
                        re_dict.update({
                            "code": ReturnStatus.SUCCESS,
                            "status": "Success"
                        })
                    else:
                        re_dict = _Return_Error_Post(
                            code=ReturnStatus.OVER_MAXPAGE,
                            status="Failed",
                            detail="OVER_MAXPAGE")

                else:
                    re_dict = _Return_Error_Post(code=ReturnStatus.NO_SUPPORT,
                                                 status="Failed",
                                                 detail="NO_SUPPORT")
        finally:
            response = Response(json.dumps(re_dict),
                                mimetype='application/json')
            response.headers.add('Server', 'python flask')
            response.headers['Access-Control-Allow-Origin'] = '*'
            response.headers[
                'Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
            response.headers[
                'Access-Control-Allow-Headers'] = 'x-requested-with'
            return response

    else:
        re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_METHOD,
                                     status="Failed",
                                     detail="ERROR_METHOD")
        response = Response(json.dumps(re_dict), mimetype='application/json')
        response.headers.add('Server', 'python flask')
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers[
            'Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
        response.headers['Access-Control-Allow-Headers'] = 'x-requested-with'
        return response
Ejemplo n.º 4
0
def search_json():
    """
    用于接受各类前端的歌曲名字的api请求
    分为POST/GET请求
    如果是POST则又分为
    三大platform平台不同而调起不同的爬虫脚本
    有关更多错误码信息请查阅SDK文档
    """
    global re_dict
    if request.method == 'POST':
        re_dict = {}
        data = request.get_data()  # 获得json数据包.
        try:
            dict_data = json.loads(data)  # 解析json数据包.
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PSOT_DATA,
                                         status="Failed",
                                         detail="ERROR_PSOT_DATA")
        try:
            music_title = dict_data["title"]
            music_platform = dict_data["platform"]
            try:
                music_page = dict_data["page"]
            except:
                music_page = 1
            # 获得请求的歌曲名字和选择的音乐平台
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="ERROR_PARAMS")
        else:
            if music_page > 10:
                re_dict = _Return_Error_Post(code=ReturnStatus.OVER_MAXPAGE,
                                             status="Failed",
                                             detail="OVER_MAXPAGE")
            else:
                if music_title != '' or music_title != None:
                    if music_platform == "Neteasymusic":
                        neteasymusic_id = neteasy_scrawl.Netmusic()
                        re_dict = neteasymusic_id.pre_response_neteasymusic(
                            music_title, music_page)
                        try:
                            re_dict["code"]
                        except KeyError:
                            if re_dict:
                                re_dict.update({
                                    "code": ReturnStatus.SUCCESS,
                                    "status": "Success",
                                    "now_page": music_page,
                                    "next_page": music_page + 1,
                                    "before_page": music_page - 1
                                })
                            else:
                                re_dict = _Return_Error_Post(
                                    code=ReturnStatus.OVER_MAXPAGE,
                                    status="Failed",
                                    detail="OVER_MAXPAGE")
                        else:
                            re_dict = _Return_Error_Post(
                                code=ReturnStatus.ERROR_SEVER,
                                status="Failed",
                                detail="ERROR_SEVER")

                    elif music_platform == "Xiamimusic":
                        xiamimusic_search = xiami_scrawl.Search_xiami()
                        re_dict = xiamimusic_search.search_xiami(
                            music_title, music_page)
                        if re_dict:
                            re_dict.update({
                                "code": ReturnStatus.SUCCESS,
                                "status": "Success",
                                "now_page": music_page,
                                "next_page": music_page + 1,
                                "before_page": music_page - 1
                            })
                        else:
                            re_dict = _Return_Error_Post(
                                code=ReturnStatus.OVER_MAXPAGE,
                                status="Failed",
                                detail="OVER_MAXPAGE")
                    elif music_platform == "QQmusic":

                        qqmusic_search = qq_scrawl.QQMusic()
                        re_dict = qqmusic_search.search_by_keyword(
                            music_title, music_page)
                        try:
                            re_dict["code"]
                        except KeyError:
                            if re_dict:
                                re_dict.update({
                                    "code": ReturnStatus.SUCCESS,
                                    "status": "Success",
                                    "now_page": music_page,
                                    "next_page": music_page + 1,
                                    "before_page": music_page - 1
                                })
                            else:
                                re_dict = _Return_Error_Post(
                                    code=ReturnStatus.OVER_MAXPAGE,
                                    status="Failed",
                                    detail="OVER_MAXPAGE")
                        else:
                            pass
                    elif music_platform == "Kugoumusic":

                        kugou_search = kugou_scrawl.Kugou()
                        re_dict = kugou_search.Search_List(
                            music_title, music_page)
                        try:
                            re_dict["code"]
                        except KeyError:
                            if re_dict:
                                re_dict.update({
                                    "code": ReturnStatus.SUCCESS,
                                    "status": "Success",
                                    "now_page": music_page,
                                    "next_page": music_page + 1,
                                    "before_page": music_page - 1
                                })
                            else:
                                re_dict = _Return_Error_Post(
                                    code=ReturnStatus.OVER_MAXPAGE,
                                    status="Failed",
                                    detail="OVER_MAXPAGE")
                        else:
                            pass
                        finally:
                            re_dict.update({
                                "now_page": music_page,
                                "next_page": music_page + 1,
                                "before_page": music_page - 1
                            })
                    else:
                        re_dict = _Return_Error_Post(
                            code=ReturnStatus.NO_SUPPORT,
                            status="Failed",
                            detail="NO_SUPPORT")

                else:
                    re_dict = _Return_Error_Post(
                        code=ReturnStatus.ERROR_PARAMS,
                        status="Failed",
                        detail="ERROR_PARAMS")
        finally:
            if re_dict == "":
                re_dict = _Return_Error_Post(code=ReturnStatus.NOT_SAFE,
                                             status="Failed",
                                             detail="NOT_SAFE")

            response = Response(json.dumps(re_dict),
                                mimetype='application/json')
            response.headers.add('Server', 'python flask')
            response.headers['Access-Control-Allow-Origin'] = '*'
            response.headers[
                'Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
            response.headers[
                'Access-Control-Allow-Headers'] = 'x-requested-with'
            return response

    else:
        re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_METHOD,
                                     status="Failed",
                                     detail="ERROR_METHOD")
        response = Response(json.dumps(re_dict), mimetype='application/json')
        response.headers.add('Server', 'python flask')
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers[
            'Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
        response.headers['Access-Control-Allow-Headers'] = 'x-requested-with'
        return response
Ejemplo n.º 5
0
# # 登录/注册模块的测试,现已可用
#app4 = bcrypt_hash.loginer()
#app5 = bcrypt_hash.AES_Crypt_Cookies()
# print(app4.Sign_Up_Encrypt("The powder toy", "passwd"))
# print(app4.Sign_In_Check("The powder toy", "passwd"))
# print(app5.Creat_Token(1, "Listen now user", "115.238.228.39", "Wechat Firefox"))

# print(app5.Decrypt_Check_Token(b'\xd7\x93x\xc1\xe2~@\xd1\x88\xc4\x15\xb5a\xbb,\x1a\xe7599\xa2\xbc\xa5\x05"\xf4R\xa1\x80\x04\xa6\x8a\x82\xb0\xb2^\xb5\xae\xa2N\xb8\xcf\xba`\'9\xd7C\xf7\xf3\x1cu\xf3\xe8\x8akU\\\r\xcb\x90\xd1i\xa2\x99\xad\x15"\xe3\xb4\xe8\x9f\xb3\xa5\xc6\x03x\xf4\x1aI', "115.238.228.39", "Wechat Firefox"))
# app4.Check_Token(b'c+D+2FdJbUXSY9QLB1UvH8P0/EbqBSz5Km+XRTFiAmCsh19V7nOdxzbVRlc7c2tIwSTgiHBx9tDacxqq49wcrkXApsH232oD7XKbuyHzFVk=\nNQZ',
#                       # "115.238.228.39",
#                       # "Wechat Firefox")

# from project.Scrawl.BaiduMusic import BaiduMusic
# app6 = BaiduMusic.BaiduMusic()
# # print(app6.search_by_keyword('纸短情长'))
# # print(app6.search_by_id('795823'))
# print(app6.get_play_url('299800'))

from project.Scrawl.KugouMusic import kugou

app7 = kugou.Kugou()
# print(app6.Search_List("纸短情长", 1))
# print(app6.hash_search("c592091f71226cd2dc9f840655b235bb"))
# print(app7.ReturnSongList("511210"))
app7.TopSongList()

# from Helper.token_admin import Forbidden

# app8 = Forbidden()
# print(app8.sign_ip("1234test"))
Ejemplo n.º 6
0
# from project.Scrawl.XiamiMusic.XiamiMusic import Search_xiami
# app3 = Search_xiami()
# print(app3.search_xiami('纸短情长'))
# app3 = XiamiMusic.XiamiApi()
# print(app3.getPlaylist("358024020"))



# from project.Helper import bcrypt_hash
# # # 登录/注册模块的测试,现已可用
# app4 = bcrypt_hash.loginer()
# app5 = bcrypt_hash.AES_Crypt_Cookies()
# # print(app4.Sign_Up_Encrypt("The powder toy", "passwd"))
# # print(app4.Sign_In_Check("The powder toy", "passwd"))

# print(app5.Creat_Token(1, "Listen now user", "115.238.228.39", "Wechat Firefox"))
# print(app5.Decrypt_Check_Token(b'\xd7\x93x\xc1\xe2~@\xd1\x88\xc4\x15\xb5a\xbb,\x1a\xe7599\xa2\xbc\xa5\x05"\xf4R\xa1\x80\x04\xa6\x8a\x82\xb0\xb2^\xb5\xae\xa2N\xb8\xcf\xba`\'9\xd7C\xf7\xf3\x1cu\xf3\xe8\x8akU\\\r\xcb\x90\xd1i\xa2\x99\xad\x15"\xe3\xb4\xe8\x9f\xb3\xa5\xc6\x03x\xf4\x1aI', "115.238.228.39", "Wechat Firefox"))
# app4.Check_Token(b'c+D+2FdJbUXSY9QLB1UvH8P0/EbqBSz5Km+XRTFiAmCsh19V7nOdxzbVRlc7c2tIwSTgiHBx9tDacxqq49wcrkXApsH232oD7XKbuyHzFVk=\nNQZ',
#                       # "115.238.228.39", 
#                       # "Wechat Firefox")


from project.Scrawl.KugouMusic import kugou

app6 = kugou.Kugou()
# print(app6.Search_List("纸短情长", 1))
# print(app6.hash_search("c592091f71226cd2dc9f840655b235bb"))
print(app6.ReturnSongList("12345"))


Ejemplo n.º 7
0
def search_json():
    """
    用于接受各类前端的歌曲名字的api请求
    分为POST/GET请求
    如果是POST则又分为
    三大platform平台不同而调起不同的爬虫脚本
    有关更多错误码信息请查阅SDK文档
    """
    global re_dict
    if request.method == 'POST':
        re_dict = {}
        data = request.get_data()  # 获得json数据包.
        try:
            dict_data = json.loads(data)  # 解析json数据包.
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PSOT_DATA,
                                         status="Failed",
                                         detail="ERROR_PSOT_DATA")
        try:
            music_title = dict_data["title"]
            music_platform = dict_data["platform"]
            try:
                music_page = dict_data["page"]
            except:
                music_page = 1
            # 获得请求的歌曲名字和选择的音乐平台
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="ERROR_PARAMS")
        else:
            if music_page > 10:
                re_dict = _Return_Error_Post(code=ReturnStatus.OVER_MAXPAGE,
                                             status="Failed",
                                             detail="OVER_MAXPAGE")
            else:
                if music_title != '' or music_title != None:
                    if music_platform == "Neteasemusic":
                        neteasymusic_id = neteasy_scrawl.Netmusic()
                        re_dict = neteasymusic_id.pre_response_neteasymusic(
                            music_title, music_page)

                    elif music_platform == "Xiamimusic":
                        xiamimusic_search = xiami_scrawl.Search_xiami()
                        re_dict = xiamimusic_search.search_xiami(
                            music_title, music_page)

                    elif music_platform == "QQmusic":
                        qqmusic_search = qq_scrawl.QQMusic()
                        re_dict = qqmusic_search.search_by_keyword(
                            music_title, music_page)

                    elif music_platform == "Kugoumusic":

                        kugou_search = kugou_scrawl.Kugou()
                        re_dict = kugou_search.Search_List(
                            music_title, music_page)

                    elif music_platform == "Kuwomusic":
                        kuwo_search = kuwo_scrawl.KuwoMusic()
                        re_dict = kuwo_search.Search_List(
                            music_title, music_page)

                    elif music_platform == "Migumusic":
                        migu_search = migu_scrawl.Migu()
                        re_dict = migu_search.search(music_title, music_page)

                    elif music_platform == "Baidumusic":
                        baidu_search = baidu_scrawl.BaiduMusic()
                        re_dict = baidu_search.search_by_keyword(
                            keyword=music_title,
                            page_no=music_page,
                            page_num=10)

                    else:
                        logger.logger.warning("用户请求了一个不被支持的平台")
                        re_dict = _Return_Error_Post(
                            code=ReturnStatus.NO_SUPPORT,
                            status="Failed",
                            detail="NO_SUPPORT")

                else:
                    logger.logger.warning("用户的请求有参数错误" + dict_data)
                    re_dict = _Return_Error_Post(
                        code=ReturnStatus.ERROR_PARAMS,
                        status="Failed",
                        detail="ERROR_PARAMS")
        finally:
            if re_dict == "":
                re_dict = _Return_Error_Post(code=ReturnStatus.NOT_SAFE,
                                             status="Failed",
                                             detail="NOT_SAFE")
            elif re_dict == ReturnStatus.NO_EXISTS:
                re_dict = _Return_Error_Post(code=ReturnStatus.NO_EXISTS,
                                             status="Failed",
                                             detail="NO_EXISTS")
                logger.logger.warning("用户的请求不存在。" + dict_data)
            response = Response(json.dumps(re_dict),
                                mimetype='application/json')
            response.headers.add('Server', 'python flask')
            response.headers['Access-Control-Allow-Origin'] = '*'
            response.headers[
                'Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
            response.headers[
                'Access-Control-Allow-Headers'] = 'x-requested-with'
            return response

    else:
        logger.logger.warning("请求search接口使用了错误的方法")
        re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_METHOD,
                                     status="Failed",
                                     detail="ERROR_METHOD")
        response = Response(json.dumps(re_dict), mimetype='application/json')
        response.headers.add('Server', 'python flask')
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers[
            'Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
        response.headers['Access-Control-Allow-Headers'] = 'x-requested-with'
        return response