예제 #1
0
 def add_bunch_to_list(self):
     """向“在线试听”列表批量添加歌曲。"""
     selecteds = self.searchTable.selectedIndexes()
     if not len(selecteds):
         return
     self.added_items = []
     playlistTemp = Playlist()
     playlistTemp.fill_list(Configures.PlaylistOnline)
     musicIdsInOnlineList = playlistTemp.get_items_queue()
     for index in selecteds:
         if index.column() == 0:
             row = index.row()
             musicId = self.searchTable.item(row, 4).text()
             if musicId not in musicIdsInOnlineList:
                 musicName = self.searchTable.item(row, 1).text()
                 artist = self.searchTable.item(row, 2).text()
                 title = connect_as_title(artist, musicName)
                 album = self.searchTable.item(row, 3).text()
                 lrcPath = composite_lyric_path_use_title(title)
                 if os.path.exists(lrcPath):
                     os.remove(lrcPath)
                 self.added_items.append([title, musicId])
                 playlistTemp.add_record(musicId, title,
                                         Configures.ZeroTime, album,
                                         Configures.NoLink, 0, musicId)
     if len(self.added_items):
         playlistTemp.commit_records()
         thread = DownloadLrcThread(self.added_items)
         thread.setDaemon(True)
         thread.setName("downloadLrc")
         thread.start()
         self.add_bunch_to_list_succeed.emit()
예제 #2
0
 def initial_params(self):
     self.files = []
     self.lock = None
     self.downloadDir = ''
     self.deleteFlag = False
     self.isPlaying = False
     self.playingList = Playlist()
     self.allPlaylistNames = []
     self.mode = 0
예제 #3
0
 def add_items_to_new_playlist(self, name, selecteds):
     currentListName = self.listName
     if not selecteds:
         return
     playlistTemp = Playlist()
     for index in selecteds:
         row = index.row()
         if index.column() == 0:
             playlistTemp.add_item(self.playlist.get_item_from_queue(row),
                                   self.playlist.get_infos_at(row))
     self.set_playlist_use_name(name)
     self.add_musics_from_other_playlist(playlistTemp)
     self.set_playlist_use_name(currentListName)
예제 #4
0
 def mark_selected_as_favorite(self):
     selecteds = self.selectedIndexes()
     self.markedIndexes = []
     playlistTemp = Playlist()
     playlistTemp.fill_list(Configures.PlaylistFavorite)
     existsTitles = playlistTemp.get_titles()
     for index in selecteds:
         row = index.row()
         path = self.playlist.get_music_path_at(row)
         title = self.playlist.get_music_title_at(row)
         if index.column(
         ) == 0 and title not in existsTitles and os.path.exists(path):
             playlistTemp.add_item(self.playlist.get_item_from_queue(row),
                                   self.playlist.get_record_at(row))
             self.markedIndexes.append(row)
     if len(self.markedIndexes):
         playlistTemp.commit_records()
         self.musics_marked_signal.emit()
예제 #5
0
 def initial_params(self):
     self.playlist = None
     self.artistName = 'Zheng-Yejian'
     self.clickPlayFlag = False  #用来标志一首歌是否是主动点击选中的
     self.timerFlag = False
     self.timeStart = 0
     self.timeSpan = 0
     self.sourcePath = ''
     self.errorType = Configures.NoError
     self.currentSourceRow = -1
     self.nearPlayedSongs = []
     self.downloadDir = globalSettings.DownloadfilesPath
     self.songinfosManager = SonginfosManager()
     self.totalTime = Configures.ZeroTime
     self.playmode = Configures.PlaymodeRandom  #播放模式指示器
     playlistTemp = Playlist()
     playlistTemp.fill_list(Configures.PlaylistFavorite)
     self.lovedSongs = playlistTemp.get_titles()
예제 #6
0
 def mark_as_favorite(self):
     if self.playlist.get_name(
     ) == Configures.PlaylistFavorite or not self.playlist.length(
     ) or self.currentSourceRow < 0:
         return
     path = self.playlist.get_music_path_at(self.currentSourceRow)
     title = self.playlist.get_music_title_at(self.currentSourceRow)
     if self.playlist.get_name() == Configures.PlaylistOnline:
         musicName = get_full_music_name_from_title(title)
         musicPath = os.path.join(self.downloadDir, musicName)
         musicPathO = os.path.join(Configures.MusicsDir, musicName)
         if not os.path.exists(musicPath) and not os.path.exists(
                 musicPathO):
             QMessageBox.information(self, '提示', '请先下载该歌曲再添加喜欢!')
             return
         if os.path.exists(musicPath):
             path = musicPath
         else:
             path = musicPathO
     elif not os.path.exists(path):
         QMessageBox.information(self, "提示",
                                 "路径'" + "%s" % path + "'无效,无法标记喜欢!")
         return
     playlistTemp = Playlist()
     playlistTemp.fill_list(Configures.PlaylistFavorite)
     if title in self.lovedSongs:
         playlistTemp.remove_item_at(self.lovedSongs.index(title))
         playlistTemp.commit_records()
         self.lovedSongs.remove(title)
         self.favoriteButton.setIcon(QIcon(IconsHub.FavoritesNo))
         self.favoriteButton.setToolTip("收藏")
     else:
         playlistTemp.add_item_from_path(path)
         playlistTemp.commit_records()
         self.lovedSongs.append(title)
         self.favoriteButton.setIcon(QIcon(IconsHub.Favorites))
         self.favoriteButton.setToolTip("取消收藏")
     self.mark_favorite_completed_signal.emit()
예제 #7
0
 def __init__(self, listName, parent=None):
     super(PlaylistWidgetBasic, self).__init__(parent)
     self.listName = ''
     self.playlist = Playlist()
예제 #8
0
 def run(self):
     if self.songLink == Configures.NoLink:
         self.songLink = SearchOnline.get_song_link(self.musicId)
         if not self.songLink:
             self.errorHappend('歌曲的网络链接为空')
             return
     self.downloadStatus = Configures.Downloading
     self.print_info('开始下载')
     self.download_lrc_and_artistinfo(self.title, self.musicId)
     if self.length == 0:
         res = self.try_to_open_url(self.songLink)
         if not res:
             self.errorHappend('无法打开歌曲链接')
         else:
             if res.status == 200 and res.reason == 'OK' and res.getheader(
                     'Content-Type') == 'audio/mpeg':
                 try:
                     self.length = int(res.getheader('Content-Length'))
                 except ValueError:
                     self.errorHappend('无法获取歌曲的大小')
             else:
                 self.errorHappend('不是音乐资源类型')
     if not self.length or self.downloadStatus == Configures.DownloadError:
         return
     self.currentLength = self.check_temp_downloaded(self.tempfileName)
     req = request.Request(self.songLink)
     req.headers['Range'] = 'bytes= %s-%s' % (self.currentLength,
                                              self.length)
     res = self.try_to_open_url(req)
     if not res or res.getheader('Content-Type') != 'audio/mpeg':
         self.errorHappend('无法定位到开始下载处的节点位置')
         return
     contentsList = []
     while self.currentLength < self.length and self.runPermit and self.noPause:
         trytimes = 5
         while (trytimes):
             try:
                 contentCache = res.read(BufferBlock)
                 contentsList.append(contentCache)
                 self.currentLength += BufferBlock
                 if self.currentLength > self.length:
                     self.currentLength = self.length
                 break
             except:
                 time.sleep(0.05)
                 trytimes -= 1
                 continue
         if trytimes == 0:
             self.print_info('下载超时')
             self.pause()
     res.close()
     if self.currentLength == self.length:
         self.downloadStatus = Configures.DownloadCompleted
     if self.downloadStatus != Configures.DownloadCancelled:
         contentsStr = b''.join(contentsList)
         with open(self.tempfileName, 'ab+') as f:
             f.write(contentsStr)
         if self.downloadStatus == Configures.DownloadCompleted:
             if os.path.exists(self.musicPath):
                 os.remove(self.musicPath)
             os.rename(self.tempfileName, self.musicPath)
             write_tags(self.musicPath, self.title, self.album)
             self.print_info('准备添加到“%s”' % Configures.PlaylistDownloaded)
             playlistTemp = Playlist()
             playlistTemp.fill_list(Configures.PlaylistDownloaded)
             title, album, totalTime = read_music_info(self.musicPath)
             if self.lock.acquire():
                 if self.musicPath not in playlistTemp.get_items_queue():
                     playlistTemp.add_record(self.musicPath, title,
                                             totalTime, album,
                                             self.musicPath, self.length,
                                             self.musicId)
                     playlistTemp.commit_records()
                 self.print_info("已完成下载")
                 self.lock.release()