def setSingsData(self, data): # 单曲搜索结果。 searchArea = self.searchArea.contentsTab.currentWidget() if not len(data): # self.contentsTab.addTab() searchArea.noSingsContentsLabel.setText(self.noContents.format(self.searchArea.text, '单曲')) searchArea.singsResultTable.hide() searchArea.noSingsContentsLabel.show() else: searchArea.singsResultTable.setRowCount(len(data)) musicList = [] for count, datas in enumerate(data): picUrl = datas['picUrl'] url = datas['mp3Url'] name = datas['name'] authors = ','.join([t['name'] for t in datas['artists']]) duration = self.transTime(datas['duration']/1000) musicId = datas['music_id'] searchArea.singsResultTable.setItem(count, 0, QTableWidgetItem(name)) searchArea.singsResultTable.setItem(count, 1, QTableWidgetItem(authors)) searchArea.singsResultTable.setItem(count, 2, QTableWidgetItem(duration)) musicList.append({'url': url, 'name': name, 'time':duration, 'author':authors, 'music_img': picUrl, 'music_id': musicId}) searchArea.noSingsContentsLabel.hide() searchArea.singsResultTable.show() self.musicList = musicList
def selectFolder(self): folder = QFileDialog() selectFolder = folder.getExistingDirectory() if not selectFolder: pass else: self.folder.append(selectFolder) mediaFiles = glob.glob(selectFolder + '/*.mp3') allFolder = getAllFolder(selectFolder) for i in allFolder: mediaFiles.extend(glob.glob(i + '/*.mp3')) length = len(mediaFiles) self.native.singsTable.setRowCount( self.native.singsTable.rowCount() + length) self.musicList = [] for i in enumerate(mediaFiles): music = eyed3.load(i[1]) if not music: self.singsTable.removeRow(i[0]) continue try: name = music.tag.title author = music.tag.artist if not name: filePath = i[1].replace(selectFolder, '') name = filePath[1:][:-4] if not author: author = '' except: try: # TODO # if more folders exist. filePath = i[1].replace(selectFolder, '') name = filePath[1:][:-4] except Exception as e: name = i[1] author = '' time = itv2time(music.info.time_secs) self.musicList.append({ 'name': name, 'author': author, 'time': time, 'url': i[1], 'music_img': 'None' }) self.native.singsTable.setItem(i[0], 0, QTableWidgetItem(name)) self.native.singsTable.setItem(i[0], 1, QTableWidgetItem(author)) self.native.singsTable.setItem(i[0], 2, QTableWidgetItem(time))
def setSongs(self, musicInfo): self.recommendFrame.singsTable.setRowCount(len(musicInfo)) for index, data in enumerate(musicInfo): self.musicList.append(data._asdict()) self.recommendFrame.singsTable.setItem(index, 0, QTableWidgetItem(data.name)) self.recommendFrame.singsTable.setItem( index, 1, QTableWidgetItem(data.author)) self.recommendFrame.singsTable.setItem( index, 2, QTableWidgetItem(transTime(data.time / 1000)))
def fromPathLoadSong(self, selectFolder): if not os.path.isdir(selectFolder): os.mkdir(selectFolder) return mediaFiles = glob.glob(selectFolder+'/*.mp3') allFolder = getAllFolder(selectFolder) for i in allFolder: mediaFiles.extend(glob.glob(i+'/*.mp3')) length = len(mediaFiles) self.downloadFrame.singsTable.clearContents() self.downloadFrame.singsTable.setRowCount(length) self.musicList = [] for i in enumerate(mediaFiles): music = eyed3.load(i[1]) if not music: self.singsTable.removeRow(i[0]) continue try: name = music.tag.title author = music.tag.artist if not name: filePath = i[1].replace(selectFolder, '') name = filePath[1:][:-4] if not author: author = '' except: try: # TODO # if more folders exist. filePath = i[1].replace(selectFolder, '') name = filePath[1:][:-4] except Exception as e: name = i[1] author = '' try: time = itv2time(music.info.time_secs) except: time = '00:00' self.musicList.append({'name': name, 'author': author, 'time': time, 'url': i[1], 'music_img': 'None'}) self.downloadFrame.singsTable.setItem(i[0], 0, QTableWidgetItem(name)) self.downloadFrame.singsTable.setItem(i[0], 1, QTableWidgetItem(author)) self.downloadFrame.singsTable.setItem(i[0], 2, QTableWidgetItem(time))
def setupDetailFrames(self, datas, singsUrls, singsIds): result = datas self.musicList = [] self.detailSings.singsTable.clearContents() self.detailSings.titleLabel.setText(result['name']) self.detailSings.authorName.setText(result['creator']['nickname']) # 简介有些太长了,暂时只截取前107个字符。 description = result['description'] # 有些没有简介会报错的。 if not description: description = '' self.detailSings.descriptionText.setText(description) # 这边添加歌曲的信息到table。 self.detailSings.singsTable.setRowCount(result['trackCount']) for i, j, t, x in zip(result['tracks'], range(result['trackCount']), singsUrls, singsIds): names = i['name'] musicName = QTableWidgetItem(names) self.detailSings.singsTable.setItem(j, 0, musicName) author = i['artists'][0]['name'] musicAuthor = QTableWidgetItem(author) self.detailSings.singsTable.setItem(j, 1, musicAuthor) times = self.transTime(i['duration'] / 1000) musicTime = QTableWidgetItem(times) self.detailSings.singsTable.setItem(j, 2, musicTime) music_img = i['album']['blurPicUrl'] lyric = i.get('lyric') self.musicList.append({ 'url': t, 'name': names, 'time': times, 'author': author, 'music_img': music_img, 'music_id': x, 'lyric': lyric })
def updateDownloadShowTable(self, musicInfo): showInfo = [musicInfo.get("name"), musicInfo.get("author"), musicInfo.get("time")] # 这里写"我的下载"的实例对象。 # 首先获取出当前总共多少行。 rowCount = self.showTable.rowCount() self.showTable.setRowCount(rowCount+1) # 然后直接添加过去就好啦。 for i in range(3): self.showTable.setItem(rowCount, i, QTableWidgetItem(showInfo[i]))
def selectFolder(self): folder = QFileDialog() selectFolder = folder.getExistingDirectory() if not selectFolder: pass else: self.folder.append(selectFolder) mediaFiles = glob.glob(selectFolder + '/*.mp3') allFolder = getAllFolder(selectFolder) for i in allFolder: mediaFiles.extend(glob.glob(i + '/*.mp3')) length = len(mediaFiles) self.native.singsTable.setRowCount( self.native.singsTable.rowCount() + length) self.musicList = [] for i in enumerate(mediaFiles): music = eyed3.load(i[1]) if not music: self.singsTable.removeRow(i[0]) continue name = music.tag.title if not name: name = i[1].split('\\')[-1][:-4] author = music.tag.artist if not author: author = '未知歌手' time = itv2time(music.info.time_secs) self.musicList.append({ 'name': name, 'author': author, 'time': time, 'url': i[1], 'music_img': 'None' }) self.native.singsTable.setItem(i[0], 0, QTableWidgetItem(name)) self.native.singsTable.setItem(i[0], 1, QTableWidgetItem(author)) self.native.singsTable.setItem(i[0], 2, QTableWidgetItem(time))