Beispiel #1
0
    def search(self, keyword, page):

        re_dict = copy.deepcopy(RetDataModule.mod_search)

        try:
            resp = self.session.get(url=self.searchurl % (keyword, page),
                                    headers=self.headers)
            resp = resp.json()

        except simplejson.errors.JSONDecodeError:
            code = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
        print(resp)
        if resp["pgt"] != 0:
            songList = ReturnFunction.songList(Data=resp["musics"],
                                               songdir="[\"songName\"]",
                                               artistsdir="[\"artist\"]",
                                               iddir="[\"copyrightId\"]",
                                               page=page)
            songList.buidingSongList()
            re_dict_class = ReturnFunction.RetDataModuleFunc()
            now_page = page
            before_page, next_page = page - 1, page + 1
            totalnum = songList.count
            re_dict = re_dict_class.RetDataModSearch(now_page,
                                                     next_page,
                                                     before_page,
                                                     songList,
                                                     totalnum,
                                                     code=ReturnStatus.SUCCESS,
                                                     status='Success')

            return re_dict
Beispiel #2
0
    def ReturnSongList(self, specialid, page=1):

        url = "http://m.kugou.com/plist/list/%s?json=true"
        try:
            resp = requests.get(url=url%(specialid), headers=self.headers).json()
        except simplejson.errors.JSONDecodeError:
            code   = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            return ReturnStatus.ERROR_SEVER
        else:
            try:
                code = ReturnStatus.SUCCESS
                status = "ReturnStatus.SUCCESS"
                image = resp['info']['list']['imgurl']
                re_dict_class = ReturnFunction.RetDataModuleFunc()
    
                songList = ReturnFunction.songList(Data=resp["list"]["list"]['info'], songdir="[\"filename\"]", artistsdir="[\'filename\'][:item[\'filename\'].find(\"-\")]", iddir="[\"hash\"]", page=page)
                songList.buidingSongList()
                re_dict  = re_dict_class.RetDataModCdlist(resp['info']['list']['specialname'], resp['info']['list']['nickname'],
                                                          resp['info']['list']['intro'], resp['info']['list']['specialid'], 
                                                         image.replace(r"{size}", "400"), songList, resp['list']['list']['total'], 
                                                         resp['list']['list']['total'], code=code, status=status)
                                                         
            except:
                code = ReturnStatus.DATA_ERROR
                status = "ReturnStatus.DATA_ERROR"
                return ReturnStatus.DATA_ERROR
            else:
                re_dict['code']   = ReturnStatus.SUCCESS

        return re_dict
Beispiel #3
0
    def Search_List(self, keyword, page=1) -> str:

        try:
            resp = eval(self.session.get(url=self.baseurl%(keyword, page), headers=self.headers).text[17:-1])

        except simplejson.errors.JSONDecodeError:
            code   = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            return ReturnStatus.ERROR_SEVER
        try:
            if resp["status"] == 1:
                code                   = ReturnStatus.SUCCESS
                status                 = "ReturnStatus.SUCCESS"
                songList               = ReturnFunction.songList(Data=resp["data"]["info"], songdir="[\"songname_original\"]", artistsdir="[\'singername\']", iddir="[\"hash\"]", page=page)
                songList.buidingSongList()
                re_dict_class          = ReturnFunction.RetDataModuleFunc()
                now_page               = page
                before_page, next_page = page-1, page+1
                totalnum               = songList.count
                re_dict                = re_dict_class.RetDataModSearch(now_page, next_page, before_page, songList, totalnum, code=code, status=status)
        except KeyError:
            code   = ReturnStatus.NO_EXISTS
            status = 'ReturnStatus.NO_EXISTS'
            return ReturnStatus.NO_EXISTS

        except:
            code   = ReturnStatus.ERROR_UNKNOWN
            status = 'ReturnStatus.ERROR_UNKNOWN'
            return ReturnStatus.ERROR_UNKNOWN

        else:
            return re_dict
Beispiel #4
0
    def search_by_keyword(self, keyword, page = 1, num = 10):
        '''
        通过关键字搜索歌曲
        keyword : 关键字
        page : 当前页数[默认=1]
        num : 返回结果最大数量[默认=10]
        返回值 : 歌曲列表
        '''
        re_dict = copy.deepcopy(RetDataModule.mod_search) #拷贝搜索结果模板
        try:
            _url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&'\
            'new_json=1&remoteplace=txt.yqq.top&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0'\
            '&p={0}&n={1}&w={2}&hostUin=0&format=json&inCharset=utf8&'\
            'outCharset=utf-8&notice=0&platform=yqq&needNewCode=0'.format(page, num, keyword)
            response = self.session.request('GET', _url, headers = self.headers)
            serach_res = response.json()
            if serach_res.get('code', -1) == 0:
                song_list     = serach_res.get('data',{}).get('song',{}).get('list',[])
                songList      = ReturnFunction.songList(Data=song_list, songdir="[\"name\"]", artistsdir="[\'singer\'][0][\'name\']", iddir="[\"mid\"]", page=page)
                songList.buidingSongList()

                re_dict_class = ReturnFunction.RetDataModuleFunc()
                now_page      = page
                before_page, next_page = page-1, page+1
                totalnum      = songList.count
                re_dict       = re_dict_class.RetDataModSearch(now_page, next_page, before_page, songList, totalnum, code=ReturnStatus.SUCCESS, status='Success')
            else:
                code   = ReturnStatus.ERROR_SEVER
                status = 'ReturnStatus.ERROR_SEVER'
                return ReturnStatus.ERROR_SEVER
        except:
            code = ReturnStatus.ERROR_UNKNOWN
            status = 'ReturnStatus.ERROR_UNKNOWN'
            return ReturnStatus.ERROR_UNKNOWN    
        return re_dict
Beispiel #5
0
    def TopSongList(self):
        url     = "http://m.kugou.com/plist/index&json=true"

        try:
            resp = requests.get(url=url, headers=self.headers).json()
        except simplejson.errors.JSONDecodeError:
            code   = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            return ReturnStatus.ERROR_SEVER
        else:
            try:
                code = ReturnStatus.SUCCESS
                status = "ReturnStatus.SUCCESS"


                re_dict_class = ReturnFunction.RetDataModuleFunc()

                ItemList = ReturnFunction.TopSongList(Data=resp["plist"]["list"]['info'], 
                                                    ItemNameDir="[\"specialname\"]", 
                                                    ImageUrlDir="[\'imgurl\'].replace(r\"{size}\", \"400\")", 
                                                    IdDir="[\"specialid\"]", InfoDir="[\"intro\"]")
                ItemList.buidingSongList()
                re_dict = re_dict_class.RetDataModHotItemList(ItemList, ItemList.count, code=200, status='Success')

            except:
                code = ReturnStatus.DATA_ERROR
                status = "ReturnStatus.DATA_ERROR"
                return ReturnStatus.DATA_ERROR
            else:
                return re_dict
Beispiel #6
0
    def search_details(self, music_id):
        try:
            resp = eval(
                self.session.get(url=self.detailurl % (music_id),
                                 headers=self.headers).text)
        except simplejson.errors.JSONDecodeError:
            code = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            return 0
        else:
            code = ReturnStatus.SUCCESS
            status = "ReturnStatus.SUCCESS"

            try:
                resp = resp["data"]
                re_dict_class = ReturnFunction.RetDataModuleFunc()
                re_dict = re_dict_class.RetDataModSong(
                    resp["listenUrl"],
                    resp["songId"],
                    str(resp["songName"]),
                    str(resp["singerName"])[2:-2],
                    resp["picL"],
                    resp["lyricLrc"],
                    comment=["暂无评论数据"],
                    tlyric='None',
                    code=code,
                    status=status)

            except:
                re_dict["code"] = ReturnStatus.DATA_ERROR
        return re_dict
Beispiel #7
0
 def search_by_id(self, songMid):
     '''
     通过id搜索歌曲信息
     songMid : 歌曲识别码
     返回值 : 歌曲信息
     '''
     re_dict = copy.deepcopy(RetDataModule.mod_search) #拷贝搜素结果模板
     try:
         _url = 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg?songmid={0}&'\
         'tpl=yqq_song_detail&format=json&loginUin=0&hostUin=0&inCharset=utf8&outCharset=utf-8&'\
         'notice=0&platform=yqq&needNewCode=0'.format(songMid)
         response = self.session.request('GET', _url, headers = self.headers)
         serach_res = response.json()
         if serach_res.get('code', -1) == 0: 
             info = serach_res.get('data')[0]
             re_dict_class = ReturnFunction.RetDataModuleFunc()
             music_id = info['mid']
             re_dict = re_dict_class.RetDataModSong(self.get_play_url(music_id, self.get_music_vkey(music_id)), 
                 music_id, info['name'], info['singer'][0]['name'], self.get_image_url(info['album']['mid']),
                 self.get_music_lyric(music_id), comment=['暂无评论数据'], tlyric='None', code=ReturnStatus.SUCCESS, status='Success')
         else:
             code   = ReturnStatus.ERROR_SEVER
             status = 'ReturnStatus.ERROR_SEVER'
             return ReturnStatus.ERROR_SEVER
     except:
         code = ReturnStatus.ERROR_UNKNOWN
         status = 'ReturnStatus.ERROR_UNKNOWN'
         return ReturnStatus.ERROR_UNKNOWN    
     return re_dict
Beispiel #8
0
    def Search_details(self, music_id):

        try:
            resp = eval(
                self.session.get(url=self.searchurl % (music_id),
                                 headers=self.headers).text)
        except simplejson.errors.JSONDecodeError:
            code = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            return 0
        else:
            code = ReturnStatus.SUCCESS
            status = "ReturnStatus.SUCCESS"

            try:
                resp = resp["data"]
                re_dict_class = ReturnFunction.RetDataModuleFunc()
                re_dict = re_dict_class.RetDataModSong(
                    self.get_play_url(music_id),
                    resp["songinfo"]["id"],
                    resp["songinfo"]['songName'],
                    resp["songinfo"]['artist'],
                    resp["songinfo"]['pic'],
                    resp['lrclist'],
                    self.get_comment(music_id),
                    tlyric='None',
                    code=code,
                    status=status)

            except:
                re_dict["code"] = ReturnStatus.DATA_ERROR
        return re_dict
Beispiel #9
0
    def Search_List(self, keyword, page=1):

        re_dict = copy.deepcopy(RetDataModule.mod_search)

        try:
            page -= 1
            resp = eval(
                self.session.get(url=self.baseurl % (keyword, page),
                                 headers=self.headers).text)

        except simplejson.errors.JSONDecodeError:
            code = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
        try:
            if resp["HIT"] != 0:
                songList = ReturnFunction.songList(Data=resp["abslist"],
                                                   songdir="[\"SONGNAME\"]",
                                                   artistsdir="[\"ARTIST\"]",
                                                   iddir="[\"MUSICRID\"][6:]",
                                                   page=page)
                songList.buidingSongList()
                re_dict_class = ReturnFunction.RetDataModuleFunc()
                now_page = page + 1
                before_page, next_page = page, page + 2
                totalnum = songList.count
                re_dict = re_dict_class.RetDataModSearch(
                    now_page,
                    next_page,
                    before_page,
                    songList,
                    totalnum,
                    code=ReturnStatus.SUCCESS,
                    status='Success')
                for re in re_dict['song']['list']:
                    re['music_name'].replace(' ', ' ')
                    re['artists'].replace(' ', ' ')

        except KeyError:
            code = ReturnStatus.NO_EXISTS
            status = 'ReturnStatus.NO_EXISTS'
            return ReturnStatus.NO_EXISTS
        except:
            code = ReturnStatus.ERROR_UNKNOWN
            status = 'ReturnStatus.ERROR_UNKNOWN'
            return ReturnStatus.ERROR_UNKNOWN
        else:
            return re_dict
Beispiel #10
0
    def get_cdlist(self, disstid, uin='447231743',  song_begin=0, song_num=1000, page=1):
        '''
        song_num 在这里直接是获取整个歌单所有的歌曲
        通过disstid获取的歌单
        disstid : 歌单id
        uin : 用户识别码[]
        song_begin : 歌曲起始索引[默认=0]
        # song_num : 欲获取歌曲的数量[默认=10]
        返回值 : 歌单(mod_cdlist格式)
        '''

        try:
            _url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg?'\
            'type=1&json=1&utf8=1&onlysong=0&disstid={0}&format=json&loginUin={1}&hostUin=0'\
            '&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&song_begin={2}'\
            '&song_num={3}'.format(disstid, uin, song_begin, song_num)
            response = self.session.request('GET', _url, headers = self.headers)
            retjson = response.json()


            if retjson.get('code', -1) == 0:

                code = ReturnStatus.SUCCESS
                status = "ReturnStatus.SUCCESS"

                re_dict_class = ReturnFunction.RetDataModuleFunc()
    
                songList = ReturnFunction.songList(Data=retjson['cdlist'][0]["songlist"], songdir="[\"songname\"]", artistsdir="[\"singer\"][0][\"name\"]", iddir="[\"songmid\"]", page=page)

                songList.buidingSongList()
                re_dict = re_dict_class.RetDataModCdlist(retjson['cdlist'][0]['dissname'], retjson['cdlist'][0]['nickname'],
                                                        retjson['cdlist'][0]['desc'], retjson['cdlist'][0]['disstid'], 
                                                        retjson['cdlist'][0]['logo'], songList, retjson['cdlist'][0]['total_song_num'],
                                                        retjson['cdlist'][0]['cur_song_num'], code=code, status=status
                                                        )
            else:
                code   = ReturnStatus.ERROR_SEVER
                status = 'ReturnStatus.ERROR_SEVER'
                return ReturnStatus.ERROR_SEVER
        except:
            code = ReturnStatus.ERROR_UNKNOWN
            status = 'ReturnStatus.ERROR_UNKNOWN'
            return ReturnStatus.ERROR_UNKNOWN    
        return re_dict
Beispiel #11
0
    def pre_response_neteasymusic(self, text, page=1):
        global count, i, lock

        text = urllib.parse.quote(text)
        data = "hlpretag=&hlposttag=&s=%s&type=1&offset=%s&total=true&limit=10" % (
            text, str((page - 1) * 10))
        resp = self.session.post(url=self.search_url,
                                 data=data,
                                 headers=self.headers)
        result = resp.json()
        try:
            songList = ReturnFunction.songList(
                Data=result['result']['songs'],
                songdir="[\"name\"]",
                artistsdir="[\'artists\'][0][\'name\']",
                iddir="[\"id\"]",
                page=page)
            songList.buidingSongList()
            re_dict_class = ReturnFunction.RetDataModuleFunc()
            now_page = page
            before_page, next_page = page - 1, page + 1
            totalnum = songList.count
            re_dict = re_dict_class.RetDataModSearch(now_page,
                                                     next_page,
                                                     before_page,
                                                     songList,
                                                     totalnum,
                                                     code=ReturnStatus.SUCCESS,
                                                     status='Success')
        except KeyError:
            code = ReturnStatus.NO_EXISTS
            status = 'ReturnStatus.NO_EXISTS'
            return ReturnStatus.NO_EXISTS

        except:
            code = ReturnStatus.ERROR_UNKNOWN
            status = 'ReturnStatus.ERROR_UNKNOWN'
            return ReturnStatus.ERROR_UNKNOWN
        else:
            re_dict['code'] = ReturnStatus.SUCCESS
            re_dict['status'] = 'ReturnStatus.SUCCESS'
            return re_dict
Beispiel #12
0
    def Search_List(self, keyword, page=1):

        re_dict = copy.deepcopy(RetDataModule.mod_search)

        try:
            page -= 1
            resp = eval(self.session.get(url=self.baseurl%(keyword, page), headers=self.headers).text)

        except simplejson.errors.JSONDecodeError:
            code   = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            
        if resp["HIT"] != 0 :
            songList               = ReturnFunction.songList(Data=resp["abslist"], songdir="[\"SONGNAME\"]",artistsdir="[\"ARTIST\"]",iddir="[\"MUSICRID\"][6:]", page=page)
            songList.buidingSongList()
            re_dict_class          = ReturnFunction.RetDataModuleFunc()
            now_page               = page + 1
            before_page, next_page = page , page +2
            totalnum               = songList.count
            re_dict                = re_dict_class.RetDataModSearch(now_page, next_page, before_page, songList, totalnum, code=ReturnStatus.SUCCESS, status='Success')
            
            return re_dict
Beispiel #13
0
    def music_id_requests(self, music_id):

        id_flag = 1
        musicDataiList = self.music_detail(music_id, id_flag)

        lyric = self.requests_lyric(music_id)
        re_dict_class = ReturnFunction.RetDataModuleFunc()
        re_dict = re_dict_class.RetDataModSong(
            self.new_requests_play_url(music_id),
            music_id,
            musicDataiList['music_name'],
            musicDataiList['artists'],
            musicDataiList['image_url'],
            lyric['lyric'],
            comment=self.requests_comment(music_id),
            tlyric=lyric['tlyric'],
            code=ReturnStatus.SUCCESS,
            status='Success')

        return re_dict
Beispiel #14
0
    def hash_search(self, hash):

        try:
            resp = eval(self.session.get(url=self.hashurl%(hash), headers=self.headers).text)
        except simplejson.errors.JSONDecodeError:
            code   = ReturnStatus.ERROR_SEVER
            status = "ReturnStatus.ERROR_SEVER"
            return ReturnStatus.ERROR_SEVER
        else:
            code   = ReturnStatus.SUCCESS
            status = "ReturnStatus.SUCCESS"
            try:
                resp = resp["data"]
                re_dict_class = ReturnFunction.RetDataModuleFunc()
                music_id = resp["hash"]
                re_dict = re_dict_class.RetDataModSong(play_url=resp["play_url"], music_id=music_id, music_name=resp['song_name'], 
                    artists=resp['author_name'], image_url=resp['img'], lyric=resp['lyrics'], comment=['暂无评论数据'], tlyric='None', 
                    code=code, status=status)

            except:re_dict["code"]    = ReturnStatus.DATA_ERROR
        return re_dict