示例#1
0
    def getLyric(self):
        musicInfo = self.parent.player.getCurrentMusicInfo()

        if not musicInfo:
            return "✧请慢慢欣赏~"

        musicId = musicInfo.get('music_id')
        if self.currentMusicId == musicId:
            return self.lyricCache
            # return self.detailInfo.detailText.toPlainText()

        lyricUrl = musicInfo.get('lyric')
        # 默认网易云,网易云没有返回歌词地址,所以会是None.
        if not lyricUrl:
            future = aAsync(netease.lyric, musicId)
            data = yield from future
        else:
            if 'xiami' in lyricUrl:
                future = aAsync(xiami.lyric, lyricUrl)
                data = yield from future
            elif lyricUrl == 'qq':
                # TODO
                # get qq music lyric.
                return "✧请慢慢欣赏~"


        if not data:
            self.currentMusicId = musicId
            return "✧请慢慢欣赏~"

        # 这里暂时处理下不获取时间信息,只获取歌词信息。
        # data = re.sub(r'\[.*?\]', '', data)
        self.currentMusicId = musicId
        self.lyricCache = data
        return data    
    def downloadSong(self, musicInfo):
        logger.info("正在下载的音乐的信息: {}".format(musicInfo))

        url = musicInfo.get('url')
        allMusicName = re.search(r'.*\.[a-zA-Z0-9]+', url[url.rfind('/')+1:]).group(0)
        if allMusicName:

            musicSuffix = allMusicName[allMusicName.rfind('.')+1:]
            musicName = '{name}.{suf}'.format(name=musicInfo.get('name') + ' - ' + musicInfo.get('author'), suf=musicSuffix)
        else:
            # TODO MD5。
            musicName = "random_name.mp3"

        musicName = replace_forbidden_sym(musicName)

        self.downloadFrame.parent.systemTray.showMessage("~~~", '{musicName} 加入下载队列'.format(musicName=musicName))
        # TODO
        # Streaming.
        future = aAsync(myRequests.httpRequest, url, 'GET')
        data = yield from future

        localPath = '{myDownloadFolder}/{musicName}'.format(myDownloadFolder=self.myDownloadFolder, musicName=musicName)
        with open(localPath, 'wb') as f:
            f.write(data.content)

        musicInfo['url'] = localPath

        # 从托盘栏给出提示。
        self.downloadFrame.parent.systemTray.showMessage("~~~", '{musicName} 下载完成'.format(musicName=musicName))
        # 将音乐信息加到musicList中。
        self.musicList.append(musicInfo)
        self.updateDownloadShowTable(musicInfo)
示例#3
0
    def search(self):
        text = self.header.searchLine.text()
        future = aAsync(netease.search, text)
        self.result = yield from future
        if not self.result['songCount']:
            songsIds = []
            self.result['songs'] = []
        else: 
            songsIds = [i['id'] for i in self.result['songs']]

            self.songsDetail = {j:'http{0}'.format(i) for i, j in enumerate(songsIds)}
           
            # 进行重新编辑方便索引。
            songs = self.result['songs']
            self.result['songs'] = [{'name':i['name'], 
            'artists': i['ar'], 
            'picUrl': i['al']['picUrl'],
            'mp3Url': self.songsDetail[i['id']],
            'duration': i['dt'],
            'music_id':i['id']} for i in songs]

        songsCount = self.result['songCount']

        # 总数是0即没有找到。
        if not songsCount:
            songs = []
        else:
            songs = self.result['songs'] 

        self.header.parent.searchArea.setText(text)

        self.header.parent.searchArea.config.setSingsData(songs)

        self.header.parent.config.setTabIndex(5)
示例#4
0
    def search(self):
        text = self.header.searchLine.text()
        future = aAsync(netease.search, text)
        self.result = yield from future

        if not self.result['songCount']:
            songsIds = []
            self.result['songs'] = []
        else: 
            songsIds = [i['id'] for i in self.result['songs']]

            self.songsDetail = {j:'http{0}'.format(i) for i, j in enumerate(songsIds)}
           
            # 进行重新编辑方便索引。
            songs = self.result['songs']
            self.result['songs'] = [{'name':i['name'], 
            'artists': i['ar'], 
            'picUrl': i['al']['picUrl'],
            'mp3Url': self.songsDetail[i['id']],
            'duration': i['dt'],
            'music_id':i['id']} for i in songs]

        songsCount = self.result['songCount']

        # 总数是0即没有找到。
        if not songsCount:
            songs = []
        else:
            songs = self.result['songs'] 

        self.header.parent.searchArea.setText(text)

        self.header.parent.searchArea.config.setSingsData(songs)

        self.header.parent.config.setTabIndex(3)
示例#5
0
    def search(self, name):
        """接受name信息,由这个引擎进行搜索。"""
        searchEngineer = self.searchEngineers[name]
        data = yield from aAsync(searchEngineer.search, self.searchArea.text)
        if not data['songCount']:
            songsIds = []
            data['songs'] = []
        else: 
            songsIds = [i['id'] for i in data['songs']]

            if name == '网易云':
                songsDetail = {i:'http' for i in songsIds}
            elif name == '虾米' or name == 'QQ':
                songsDetail = {i['id']:i['mp3Url'] for i in data['songs']}

            # 进行重新编辑方便索引。
            songs = data['songs']
            data['songs'] = [{'name':i['name'], 
            'artists': i['ar'], 
            'picUrl': i['al']['picUrl'],
            'mp3Url': songsDetail[i['id']],
            'duration': i['dt'],
            'music_id':i['id'],
            'lyric': i.get('lyric')} for i in songs]

        songsCount = data['songCount']

        # 总数是0即没有找到。
        if not songsCount:
            songs = []
        else:
            songs = data['songs'] 

        self.setSingsData(songs)
示例#6
0
    def search(self, name):
        """接受name信息,由这个引擎进行搜索。"""
        searchEngineer = self.searchEngineers[name]
        data = yield from aAsync(searchEngineer.search, self.searchArea.text)

        if not data['songCount']:
            songsIds = []
            data['songs'] = []
        else: 
            songsIds = [i['id'] for i in data['songs']]

            if name == '网易云':
                songsDetail = {i:'http' for i in songsIds}
            elif name == '虾米' or name == 'QQ':
                songsDetail = {i['id']:i['mp3Url'] for i in data['songs']}

            # 进行重新编辑方便索引。
            songs = data['songs']
            data['songs'] = [{'name':i['name'], 
            'artists': i['ar'], 
            'picUrl': i['al']['picUrl'],
            'mp3Url': songsDetail[i['id']],
            'duration': i['dt'],
            'music_id':i['id'],
            'lyric': i.get('lyric')} for i in songs]

        songsCount = data['songCount']

        # 总数是0即没有找到。
        if not songsCount:
            songs = []
        else:
            songs = data['songs'] 

        self.setSingsData(songs)
示例#7
0
    def loadRealMusicUrl(self, musicInfo):
        # 如果有个Url出错,比如音乐地址403重新获取下地址。
        musicId = musicInfo.get('music_id')

        logger.info("网易云歌曲地址失效,尝试重新获取,id号: {0}".format(musicId))

        if not musicId:
            self.playWidgets.nextSing()
            return

        future = aAsync(netease.singsUrl, [musicId])
        data = yield from future

        if not data:
            self.playWidgets.nextSing()
            return

        logger.info("id {0}'s response: {1}".format(musicId, data))

        if not data:
            print("获取音乐地址失败,请检查网络后重试。")
            return

        url = data[0]['url']
        musicInfo['url'] = url
        self.playList.mediaList[url] = musicInfo
        # replaceIndex = self.playList.musics.index(invalidUrl)

        self.playList.musics[self.playList.currentIndex] = url
        self.playList.play()
示例#8
0
    def getLyric(self):
        musicInfo = self.parent.player.getCurrentMusicInfo()
        logger.info("尝试获取歌曲歌词地址。 当前歌曲信息: {0}".format(musicInfo))
        if not musicInfo:
            return "✧请慢慢欣赏~"

        if 'http' not in musicInfo.get('url'):
            future = aAsync(
                xiami.search,
                musicInfo.get('name') + ' ' + musicInfo.get('author'))
            data = yield from future
            # 最好做下判断以免搜不到获取时导致报错退出。
            lyricUrl = data['songs'][0].get('lyric')
            future = aAsync(xiami.lyric, lyricUrl)
            data = yield from future
            return data

        musicId = musicInfo.get('music_id')
        if self.currentMusicId == musicId:
            return self.lyricCache
            # return self.detailInfo.detailText.toPlainText()

        lyricUrl = musicInfo.get('lyric')
        # 默认网易云,网易云没有返回歌词地址,所以会是None.
        if not lyricUrl:
            future = aAsync(netease.lyric, musicId)
            data = yield from future
        else:
            if 'xiami' in lyricUrl:
                future = aAsync(xiami.lyric, lyricUrl)
                data = yield from future
            elif lyricUrl == 'qq':
                # TODO
                # get qq music lyric.
                return "✧请慢慢欣赏~"

        if not data:
            self.currentMusicId = musicId
            return "✧请慢慢欣赏~"

        # 这里暂时处理下不获取时间信息,只获取歌词信息。
        # data = re.sub(r'\[.*?\]', '', data)
        self.currentMusicId = musicId
        self.lyricCache = data
        return data
示例#9
0
    def downloadSong(self, x):
        musicInfo = self.musicList[self.currentIndex]
        url = musicInfo.get('url')
        if 'http:' not in url and 'https:' not in url:
            songId = musicInfo.get('music_id')
            future = aAsync(netease.singsUrl, [songId])
            url = yield from future
            url = url[0].get('url')
            musicInfo['url'] = url

        self.download.emit(musicInfo)
示例#10
0
    def downloadSong(self, x):
        musicInfo = self.musicList[self.currentIndex]
        url = musicInfo.get('url')
        if 'http:' not in url and 'https:' not in url:
                songId = musicInfo.get('music_id')
                future = aAsync(netease.singsUrl, [songId])
                url = yield from future
                url = url[0].get('url')
                musicInfo['url'] = url

        self.download.emit(musicInfo)
示例#11
0
    def startRequest(self, ids, coverImgUrl):
        self.coverImgUrl = coverImgUrl
        self.singsButtonClickEvent()

        future = aAsync(self.api.details_playlist, ids)
        self.result = yield from future

        # 由于旧API不在直接返回歌曲地址,需要获取歌曲号后再次进行请求。
        singsIds = [i['id'] for i in self.result['tracks']]

        # 此处还有些问题。
        # 由于是两次url请求,稍微变得有点慢。
        future = aAsync(self.api.singsUrl, singsIds)
        data = yield from future
        self.singsUrls = {i['id']: i['url'] for i in data}
        self.singsUrls = [self.singsUrls[i] for i in singsIds]

        self.detailFrame.config.setupDetailFrames(self.result, self.singsUrls)
        self.detailFrame.picLabel.setSrc(self.coverImgUrl)
        self.detailFrame.picLabel.setStyleSheet('''QLabel {padding: 10px;}''')

        # 隐藏原来的区域,显示现在的区域。
        self.mainContents.mainContents.setCurrentIndex(1)
示例#12
0
    def downloadSong(self, x):
        # x is not to use, but must be.
        musicInfo = self.musicList[self.currentIndex]
        url = musicInfo.get('url')
        if 'http:' not in url and 'https:' not in url:
            songId = musicInfo.get('music_id')
            future = aAsync(netease.singsUrl, [songId])
            url = yield from future
            url = url[0].get('url')
            musicInfo['url'] = url
        else:
            url = musicInfo.get('url')

        future = aAsync(myRequests.httpRequest, url, 'GET')
        data = yield from future

        if 'downloads' not in os.listdir('.'):
            os.mkdir('downloads')

        allMusicName = re.search(r'.*\.[a-zA-Z0-9]+',
                                 url[url.rfind('/') + 1:]).group(0)
        if allMusicName:

            musicSuffix = allMusicName[allMusicName.rfind('.') + 1:]
            musicName = '{name}.{suf}'.format(name=musicInfo.get('name') +
                                              ' - ' + musicInfo.get('author'),
                                              suf=musicSuffix)
        else:
            # TODO MD5。
            musicName = "random_name.mp3"

        with open('downloads/{musicName}'.format(musicName=musicName),
                  'wb') as f:
            f.write(data.content)

        self.searchArea.parent.systemTray.showMessage(
            "~~~", '{musicName} 下载完成'.format(musicName=musicName))
示例#13
0
    def setUserData(self):
        profile = self.loginInfor['profile']
        avatarUrl = profile['avatarUrl']
        self.header.userPix.setSrc(avatarUrl)
        # 加载该账户创建及喜欢的歌单。
        userId = profile['userId']
        future = aAsync(netease.user_playlist, userId)
        data = yield from future

        nickname = profile['nickname']
        self.header.loginButton.setText(nickname)

        self.header.loginButton.clicked.disconnect()
        self.header.loginButton.clicked.connect(self.exitLogin)

        self.header.parent.navigation.config.setPlaylists(data)
示例#14
0
    def setUserData(self):
        profile = self.loginInfor['profile']
        avatarUrl = profile['avatarUrl']
        self.header.userPix.setSrc(avatarUrl)
        # 加载该账户创建及喜欢的歌单。
        userId = profile['userId']
        future = aAsync(netease.user_playlist, userId)
        data = yield from future

        nickname = profile['nickname']
        self.header.loginButton.setText(nickname)

        self.header.loginButton.clicked.disconnect()
        self.header.loginButton.clicked.connect(self.exitLogin)
        
        self.header.parent.navigation.config.setPlaylists(data)
示例#15
0
    def getLyric(self):
        musicInfo = self.parent.player.getCurrentMusicInfo()
        if not musicInfo:
            return "✧请慢慢欣赏~"

        musicId = musicInfo.get('music_id')
        if self.currentMusicId == musicId:
            return self.lyricCache
            # return self.detailInfo.detailText.toPlainText()

        future = aAsync(api.lyric, musicId)
        data = yield from future

        if not data:
            self.currentMusicId = musicId
            return "✧请慢慢欣赏~"

        # 这里暂时处理下不获取时间信息,只获取歌词信息。
        # data = re.sub(r'\[.*?\]', '', data)
        self.currentMusicId = musicId
        self.lyricCache = data
        return data
示例#16
0
    def startRequest(self, ids, coverImgUrl):
        self.coverImgUrl = coverImgUrl
        self.singsButtonClickEvent()

        future = aAsync(self.api.details_playlist, ids)
        self.result = yield from future
        # 由于旧API不在直接返回歌曲地址,需要获取歌曲号后再次进行请求。
        singsIds = [i['id'] for i in self.result['tracks']]
        # 此处还有些问题。
        # 由于是两次url请求,稍微变得有点慢。
        # future = aAsync(self.api.singsUrl, singsIds)
        # data = yield from future
        # self.singsUrls = {i['id']:i['url'] for i in data}
        # self.singsUrls = [self.singsUrls[i] for i in singsIds]
        self.singsUrls = ['http{0}'.format(i) for i, j in enumerate(singsIds)]

        self.detailFrame.config.setupDetailFrames(self.result, self.singsUrls, singsIds)
        self.detailFrame.picLabel.setSrc(self.coverImgUrl)
        self.detailFrame.picLabel.setStyleSheet('''QLabel {padding: 10px;}''')

        # 隐藏原来的区域,显示现在的区域。
        self.mainContents.mainContents.setCurrentIndex(1)
示例#17
0
    def loadRealMusicUrl(self, musicInfo):
        # 如果有个Url出错,比如音乐地址403重新获取下地址。
        musicId = musicInfo.get('music_id')
        # invalidUrl = musicInfo.get('url')

        if not musicId:
            self.playWidgets.nextSing()
            return

        future = aAsync(api.singsUrl, [musicId])
        data = yield from future

        if not data:
            self.playWidgets.nextSing()
            return

        url = data[0]['url']
        musicInfo['url'] = url
        self.playList.mediaList[url] = musicInfo
        # replaceIndex = self.playList.musics.index(invalidUrl)

        self.playList.musics[self.playList.currentIndex] = url
        self.playList.play()