Exemplo n.º 1
0
 def update_infofile_cached(self):
     artist = self.artistName.text()
     if artist != '未知':
         infoPath = SearchOnline.get_local_artist_info_path(artist)
         if os.path.exists(infoPath):
             os.remove(infoPath)
             self.set_artist_info(artist)
Exemplo n.º 2
0
 def run(self):
     i = 0
     cnt = len(self.list)
     while i < cnt and self.runPermit:
         title = self.list[i][0]
         print('开始下载及歌手信息:%s'%title)
         try:
             artist = title.split(Configures.Hyphen)[0].strip()
             SearchOnline.get_artist_image_path(artist)
         except:
             pass
         musicId = self.list[i][1]
         lrcPath = composite_lyric_path_use_title(title)
         if not os.path.exists(lrcPath):
             SearchOnline.get_lrc_contents(title, musicId)
         i  += 1
Exemplo n.º 3
0
 def update_infofile_cached(self):
     artist = self.artistName.text()
     if artist != '未知':
         infoPath = SearchOnline.get_local_artist_info_path(artist)
         if os.path.exists(infoPath):
             os.remove(infoPath)
             self.set_artist_info(artist)
Exemplo n.º 4
0
 def run(self):
     i = 0
     cnt = len(self.list)
     while i < cnt and self.runPermit:
         title = self.list[i][0]
         print('开始下载及歌手信息:%s' % title)
         try:
             artist = title.split(Configures.Hyphen)[0].strip()
             SearchOnline.get_artist_image_path(artist)
         except:
             pass
         musicId = self.list[i][1]
         lrcPath = composite_lyric_path_use_title(title)
         if not os.path.exists(lrcPath):
             SearchOnline.get_lrc_contents(title, musicId)
         i += 1
Exemplo n.º 5
0
 def set_media_source_at_row(self, row, clickPlayFlag=False):
     if not self.playlist.length() or row < 0:
         return
     self.stop_music()
     self.clickPlayFlag = clickPlayFlag
     self.playlist.set_current_row(row)
     sourcePath = self.playlist.get_music_path_at(row)
     self.title = self.playlist.get_music_title_at(row)
     self.sourceTrace = "local" if self.playlist.get_music_id_at(row) == Configures.LocalMusicId else "online"
     self.artistName, self.musicName = get_artist_and_musicname_from_title(self.title)
     self.playlistName = self.playlist.get_name()
     self.totalTime = self.playlist.get_music_time_at(row)
     self.album = self.playlist.get_music_album_at(row)
     self.errorType = Configures.NoError
     isAnUrl = False
     if not os.path.exists(sourcePath):
         if self.playlist.get_name() == Configures.PlaylistOnline:
             if sourcePath == Configures.NoLink:
                 musicId = self.playlist.get_music_id_at(row)
                 sourcePath = SearchOnline.get_song_link(musicId)
                 if sourcePath:
                     self.playlist.set_music_path_at(row, sourcePath)
                 else:
                     self.errorType = Configures.UrlError
             isAnUrl = True
         else:
             self.errorType = Configures.PathError
             sourcePath = "/usr/share/sounds/error_happened.ogg"
     if self.errorType == Configures.NoError:
         self.sourcePath = sourcePath
         self.musicFileName = get_base_name_from_path(sourcePath)
         self.playedDate = get_time_of_now()
         self.songinfosManager.update_datas_of_item(
             self.musicFileName,
             self.playedDate,
             self.musicName,
             self.artistName,
             self.totalTime,
             self.album,
             self.playlistName,
         )
         if not self.timerFlag:
             self.timerFlag = True
             self.timeSpan = 0
         if isAnUrl:
             url = QUrl(sourcePath)
         else:
             url = QUrl.fromLocalFile(sourcePath)
         self.play_from_url(url)
     else:
         self.timerFlag = False
         self.dont_hide_main_window_signal.emit()
         if self.errorType == Configures.DisnetError:
             QMessageBox.critical(
                 self, "错误", "联网出错!\n无法联网播放歌曲'%s'!\n您最好在网络畅通时下载该曲目!" % self.playlist.get_music_title_at(row)
             )
         elif self.errorType == Configures.PathError:
             QMessageBox.information(self, "提示", "路径'%s'无效,请尝试重新下载并添加对应歌曲!" % self.playlist.get_music_path_at(row))
Exemplo n.º 6
0
 def set_media_source_at_row(self, row, clickPlayFlag=False):
     if not self.playlist.length() or row < 0:
         return
     self.stop_music()
     self.clickPlayFlag = clickPlayFlag
     self.playlist.set_current_row(row)
     sourcePath = self.playlist.get_music_path_at(row)
     self.title = self.playlist.get_music_title_at(row)
     self.sourceTrace = 'local' if self.playlist.get_music_id_at(
         row) == Configures.LocalMusicId else 'online'
     self.artistName, self.musicName = get_artist_and_musicname_from_title(
         self.title)
     self.playlistName = self.playlist.get_name()
     self.totalTime = self.playlist.get_music_time_at(row)
     self.album = self.playlist.get_music_album_at(row)
     self.errorType = Configures.NoError
     isAnUrl = False
     if not os.path.exists(sourcePath):
         if self.playlist.get_name() == Configures.PlaylistOnline:
             if sourcePath == Configures.NoLink:
                 musicId = self.playlist.get_music_id_at(row)
                 sourcePath = SearchOnline.get_song_link(musicId)
                 if sourcePath:
                     self.playlist.set_music_path_at(row, sourcePath)
                 else:
                     self.errorType = Configures.UrlError
             isAnUrl = True
         else:
             self.errorType = Configures.PathError
             sourcePath = "/usr/share/sounds/error_happened.ogg"
     if self.errorType == Configures.NoError:
         self.sourcePath = sourcePath
         self.musicFileName = get_base_name_from_path(sourcePath)
         self.playedDate = get_time_of_now()
         self.songinfosManager.update_datas_of_item(
             self.musicFileName, self.playedDate, self.musicName,
             self.artistName, self.totalTime, self.album, self.playlistName)
         if not self.timerFlag:
             self.timerFlag = True
             self.timeSpan = 0
         if isAnUrl:
             url = QUrl(sourcePath)
         else:
             url = QUrl.fromLocalFile(sourcePath)
         self.play_from_url(url)
     else:
         self.timerFlag = False
         self.dont_hide_main_window_signal.emit()
         if self.errorType == Configures.DisnetError:
             QMessageBox.critical(
                 self, "错误", "联网出错!\n无法联网播放歌曲'%s'!\n您最好在网络畅通时下载该曲目!" %
                 self.playlist.get_music_title_at(row))
         elif self.errorType == Configures.PathError:
             QMessageBox.information(
                 self, "提示", "路径'%s'无效,请尝试重新下载并添加对应歌曲!" %
                 self.playlist.get_music_path_at(row))
Exemplo n.º 7
0
 def set_artist_info(self, artist):
     if artist == 'Zheng-Yejian':
         self.ui_initial()
     elif artist != self.artistName.text():
         infoPath = SearchOnline.get_artist_info_path(artist)
         infoDict = parse_artist_info(infoPath)
         self.artistName.setText(artist)
         self.artistBirthday.setText('生日:%s'%infoDict['birthday'])
         self.artistBirthplace.setText('出生地:%s'%infoDict['birthplace'])
         self.artistLanguage.setText('语言:%s'%infoDict['language'])
         self.artistGender.setText('性别:%s'%infoDict['gender'])
         self.artistConstellation.setText('星座:%s'%infoDict['constellation'])
         self.artistDetail.clear()
         self.artistDetail.setAlignment(Qt.AlignHCenter)
         self.artistDetail.setHtml(self.get_artist_detail_style_text(infoDict['info']))
         imagePath = SearchOnline.get_artist_image_path(artist)
         if imagePath:
             pixmap = QPixmap(imagePath)
         else:
             pixmap = QPixmap(IconsHub.Anonymous)
         self.artistHeadLabel.setPixmap(pixmap)
Exemplo n.º 8
0
 def update_parameters(self):
     self.currentSourceRow = self.playlist.get_current_row()
     self.musicTitleLabel.setText(self.title)
     self.playAction.setText(self.musicName)
     imagePath = SearchOnline.get_artist_image_path(self.artistName)
     if imagePath:
         pixmap = QPixmap(imagePath)
     else:
         pixmap = QPixmap(IconsHub.Anonymous)
     self.artistHeadLabel.setPixmap(pixmap)
     musicId = self.playlist.get_music_id_at(self.currentSourceRow)
     self.update_window_lyric_signal.emit(self.title, musicId)
Exemplo n.º 9
0
 def update_parameters(self):
     self.currentSourceRow = self.playlist.get_current_row()
     self.musicTitleLabel.setText(self.title)
     self.playAction.setText(self.musicName)
     imagePath = SearchOnline.get_artist_image_path(self.artistName)
     if imagePath:
         pixmap = QPixmap(imagePath)
     else:
         pixmap = QPixmap(IconsHub.Anonymous)
     self.artistHeadLabel.setPixmap(pixmap)
     musicId = self.playlist.get_music_id_at(self.currentSourceRow)
     self.update_window_lyric_signal.emit(self.title, musicId)
Exemplo n.º 10
0
 def searchtable_clicked(self, row):
     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()
     musicId = self.searchTable.item(row, 4).text()
     songLink = SearchOnline.get_song_link(musicId)
     if not songLink:
         return
     thread = DownloadLrcThread([(title, musicId)])
     thread.setDaemon(True)
     thread.setName('downloadLrc')
     thread.start()
     self.listen_online_signal.emit(title, album, songLink, musicId)
Exemplo n.º 11
0
 def searchtable_clicked(self, row):
     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()
     musicId = self.searchTable.item(row, 4).text()
     songLink = SearchOnline.get_song_link(musicId)
     if not songLink:
         return
     thread = DownloadLrcThread([(title, musicId)])
     thread.setDaemon(True)
     thread.setName('downloadLrc')
     thread.start()
     self.listen_online_signal.emit(title, album, songLink, musicId)
Exemplo n.º 12
0
 def set_artist_info(self, artist):
     if artist == 'Zheng-Yejian':
         self.ui_initial()
     elif artist != self.artistName.text():
         infoPath = SearchOnline.get_artist_info_path(artist)
         infoDict = parse_artist_info(infoPath)
         self.artistName.setText(artist)
         self.artistBirthday.setText('生日:%s' % infoDict['birthday'])
         self.artistBirthplace.setText('出生地:%s' % infoDict['birthplace'])
         self.artistLanguage.setText('语言:%s' % infoDict['language'])
         self.artistGender.setText('性别:%s' % infoDict['gender'])
         self.artistConstellation.setText('星座:%s' %
                                          infoDict['constellation'])
         self.artistDetail.clear()
         self.artistDetail.setAlignment(Qt.AlignHCenter)
         self.artistDetail.setHtml(
             self.get_artist_detail_style_text(infoDict['info']))
         imagePath = SearchOnline.get_artist_image_path(artist)
         if imagePath:
             pixmap = QPixmap(imagePath)
         else:
             pixmap = QPixmap(IconsHub.Anonymous)
         self.artistHeadLabel.setPixmap(pixmap)
Exemplo n.º 13
0
 def update_lyric(self, title, musicId):
     self.lyricOffset = 0     
     self.lrcPath = composite_lyric_path_use_title(title)
     lyric = SearchOnline.get_lrc_contents(title, musicId)
     if lyric == Configures.LyricNetError:
         self.playbackPanel.desktopLyric.set_text("网络出错,无法搜索歌词!")
         self.lyricDict.clear()
         self.managePage.lyricText.url_error_lyric()
     elif lyric == Configures.LyricNone:
         self.playbackPanel.desktopLyric.set_text("搜索不到匹配歌词!")
         self.lyricDict.clear()
         self.managePage.lyricText.no_matched_lyric()
     else:
         self.lyricOffset, self.lyricDict = parse_lrc(lyric)
         self.lyricDict[3000000] = ''
         self.t = sorted(self.lyricDict.keys())
         self.managePage.lyricText.set_lyric_offset(self.lyricOffset, self.lyricDict, self.lrcPath)
Exemplo n.º 14
0
 def show_musics(self, searchByType, keyword, page):
     self.searchTable.clear_search_table()
     songs, hit = SearchOnline.search_songs(searchByType, keyword, page)
     if hit == Configures.UrlError:
         return Configures.UrlError
     if not songs or hit == 0:
         return hit
     for song in songs:
         music = song[0]
         artist = song[1]
         album = song[2]
         if not album:
             album = '未知专辑'
         music_id = song[3]
         #            artistId = song['ARTISTID']
         score = song[4]
         self.searchTable.add_record(score, music, artist, album, music_id)
         self.searchTable.sortItems(0, Qt.DescendingOrder)
     return hit
Exemplo n.º 15
0
    def show_musics(self, searchByType, keyword, page):    
        self.searchTable.clear_search_table()
        songs, hit = SearchOnline.search_songs(searchByType, keyword, page)
        if hit == Configures.UrlError:
            return Configures.UrlError
        if not songs or hit == 0:
            return hit
        for song in songs:
            music = song[0]
            artist = song[1]
            album = song[2] 
            if not album:
                album = '未知专辑'
            music_id = song[3]
#            artistId = song['ARTISTID']
            score = song[4]
            self.searchTable.add_record(score, music, artist, album, music_id)
            self.searchTable.sortItems(0, Qt.DescendingOrder)
        return hit
Exemplo n.º 16
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()
Exemplo n.º 17
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()