def add_to_downloadtable(self, songLink, musicPath, title, album, musicId):
     for t in threading.enumerate():
         if t.name == musicPath:
             return
     k = -1
     for i in range(self.downloadModel.rowCount()):
         if musicPath == self.downloadModel.record(i).value("musicPath"):
             k = i
             break
     if k != -1:
         self.downloadTable.selectRow(k)
         self.start_download()
     else:
         self.downloadModel.add_record(title, 0, '未知', '等待', album, songLink, musicPath, musicId)
         row = self.downloadModel.rowCount()-1
         self.downloadTable.selectRow(row)
         downloadThread1 = DownloadThread(self.downloadModel, row)
         downloadThread1.setDaemon(True)
         downloadThread1.setName(musicPath)
         downloadThread1.start()
         
         lrcName = title + '.lrc'
         lrcPath = os.path.join(Configures.lrcsDir, lrcName)
         if os.path.exists(lrcPath):
             os.remove(lrcPath)
         path_item_temp = songLink + '~' + musicId
         list_temp = [(title, path_item_temp)]
         thread = DownloadLrcThread(list_temp)
         thread.setDaemon(True)
         thread.setName(musicPath)
         thread.start()
         
         if not self.timer.isActive():
             self.timer.start(700)
 def download_status_changed(self, ident, isPaused):
     """暂停或重启一个任务。"""
     work = self.allDownloadWorks[ident][0]
     if isPaused:
         if work.downloadStatus != Configures.DownloadCompleted:
             work.pause()
     else:
         args = [work.title, work.album, work.songLink, work.musicPath, work.musicId, work.length, work.lock]
         newDownloadWork = DownloadThread(*args)
         newDownloadWork.setName(ident)
         newDownloadWork.setDaemon(True)
         self.allDownloadWorks[ident][0] = newDownloadWork
         newDownloadWork.start()
         if not self.timer.isActive():
             self.timer.start(self.timeSpan)
    def start_one(self, row):
        if not self.downloadModel.rowCount():
            return
        state = self.downloadModel.data(self.downloadModel.index(row, 3))
        musicPath = self.downloadModel.data(self.downloadModel.index(row, 6))
#        tempfile = musicPath + '.temp'
        if state in ["已取消", "已暂停", '等待'] or not os.path.exists(self.downloadModel.data(self.downloadModel.index(row, 6))):
            for t in threading.enumerate():
                if t.name == musicPath:
                    return
            downloadThread1 = DownloadThread(self.downloadModel, row)
            downloadThread1.setDaemon(True)
            downloadThread1.setName(self.downloadModel.data(self.downloadModel.index(row, 6)))
            downloadThread1.start()
            if not self.timer.isActive():
                self.timer.start(700)
 def add_a_download_work(self, songLink, musicPath, title, album, musicId, size, lock):
     """开始一个下载任务。"""
     if musicPath in self.allDownloadWorks:
         print("下载任务已存在%s" % musicPath)
         return
     downloadWork = DownloadThread(title, album, songLink, musicPath, musicId, size, lock)
     downloadWork.setDaemon(True)
     downloadWork.setName(musicPath)
     downloadListItem = DownloadListItem(musicPath, title, self.timeSpan)
     downloadListItem.downloadStatusChanged.connect(self.download_status_changed)
     downloadListItem.killWork.connect(self.kill_a_download_work)
     self.downloadList.add_item(downloadListItem, 86)
     self.allDownloadWorks[musicPath] = [downloadWork, downloadListItem]
     downloadWork.start()
     if not self.timer.isActive():
         self.timer.start(self.timeSpan)
Beispiel #5
0
 def download_status_changed(self, ident, isPaused):
     """暂停或重启一个任务。"""
     work = self.allDownloadWorks[ident][0]
     if isPaused:
         if work.downloadStatus != Configures.DownloadCompleted:
             work.pause()
     else:
         args = [
             work.title, work.album, work.songLink, work.musicPath,
             work.musicId, work.length, work.lock
         ]
         newDownloadWork = DownloadThread(*args)
         newDownloadWork.setName(ident)
         newDownloadWork.setDaemon(True)
         self.allDownloadWorks[ident][0] = newDownloadWork
         newDownloadWork.start()
         if not self.timer.isActive():
             self.timer.start(self.timeSpan)
Beispiel #6
0
 def add_a_download_work(self, songLink, musicPath, title, album, musicId,
                         size, lock):
     """开始一个下载任务。"""
     if musicPath in self.allDownloadWorks:
         print('下载任务已存在%s' % musicPath)
         return
     downloadWork = DownloadThread(title, album, songLink, musicPath,
                                   musicId, size, lock)
     downloadWork.setDaemon(True)
     downloadWork.setName(musicPath)
     downloadListItem = DownloadListItem(musicPath, title, self.timeSpan)
     downloadListItem.downloadStatusChanged.connect(
         self.download_status_changed)
     downloadListItem.killWork.connect(self.kill_a_download_work)
     self.downloadList.add_item(downloadListItem, 86)
     self.allDownloadWorks[musicPath] = [downloadWork, downloadListItem]
     downloadWork.start()
     if not self.timer.isActive():
         self.timer.start(self.timeSpan)