Example #1
0
 def set_basic_infos(self, title, totalTime, album, path, size, musicId):
     artist, musicName = get_artist_and_musicname_from_title(title)
     self.title = title
     self.artist = artist
     self.musicName = musicName
     self.album = album
     self.path = path
     self.artistEdit.setText(artist)
     self.musicEdit.setText(musicName)
     self.albumEdit.setText(album)
     self.timeLabel.setText('时长: %s' % totalTime)
     self.sizeLabel.setText('大小: %.2f MB' % convert_B_to_MB(size))
     self.pathLabel.setText(path)
     trace = '线上资源'
     if musicId == Configures.LocalMusicId:
         trace = '本地资源'
     self.traceInfoLabel.setText('歌曲来源: %s' % trace)
     self.set_favorite_info(title in self.lovedSongs)
     item = get_base_name_from_path(path)
     freq, totalSpan, spanMax, nearPlaylistName, nearPlayedDate, nearPlayedTime = self.songinfosManager.get_statistic_infos_of_item(
         item)
     if freq:
         countInfos = '播放次数: %i 次#平均播放时长: %.1f 秒#最长播放时长: %.1f 秒' % (
             freq, totalSpan / freq, spanMax)
         nearPlaylistInfo = '最近播放位置: %s#最近播放时长: %.1f 秒' % (nearPlaylistName,
                                                           nearPlayedTime)
         nearPlayedDateInfo = '最近播放: %s' % format_time_str_with_weekday(
             nearPlayedDate)
     else:
         countInfos = '播放次数: 0 次'
         nearPlaylistInfo = '最近播放位置: 未曾播放'
         nearPlayedDateInfo = '最近播放: 未曾播放'
     self.countInfoLabel.setText(countInfos.replace('#', ' ' * 15))
     self.nearPlaylistLabel.setText(nearPlaylistInfo.replace('#', ' ' * 15))
     self.nearPlayedDateLabel.setText(nearPlayedDateInfo)
Example #2
0
 def get_lrc_from_title(title):
     try:
         artist, songName = get_artist_and_musicname_from_title(title)
         print('searchOnline_%s'%artist)
         url = ''.join([
             'http://search.kuwo.cn/r.s?ft=music&rn=1', '&newsearch=1&primitive=0&cluster=0&itemset=newkm&rformat=xml&encoding=utf8&artist=', 
             SearchOnline.parse_quote(artist), 
             '&all=', 
             SearchOnline.parse_quote(songName), 
             '&pn=0'
         ])
         reqContent = SearchOnline.url_open(url)
         if reqContent ==  Configures.UrlError:
             return Configures.LyricNetError
         if not reqContent:
             return Configures.LyricNone
         songs, hit = SearchOnline.parse_songs_wrap(reqContent)
         if hit == 0 or  not songs:
             return Configures.LyricNone
         musicId = songs[0][3]
         if not musicId:
             return Configures.LyricNone
         lrcContent = SearchOnline.get_lrc_from_musicid(musicId)
         return lrcContent if lrcContent else Configures.LyricNone
     except:
         return Configures.LyricNone
Example #3
0
 def get_lrc_from_title(title):
     try:
         artist, songName = get_artist_and_musicname_from_title(title)
         print('searchOnline_%s' % artist)
         url = ''.join([
             'http://search.kuwo.cn/r.s?ft=music&rn=1',
             '&newsearch=1&primitive=0&cluster=0&itemset=newkm&rformat=xml&encoding=utf8&artist=',
             SearchOnline.parse_quote(artist), '&all=',
             SearchOnline.parse_quote(songName), '&pn=0'
         ])
         reqContent = SearchOnline.url_open(url)
         if reqContent == Configures.UrlError:
             return Configures.LyricNetError
         if not reqContent:
             return Configures.LyricNone
         songs, hit = SearchOnline.parse_songs_wrap(reqContent)
         if hit == 0 or not songs:
             return Configures.LyricNone
         musicId = songs[0][3]
         if not musicId:
             return Configures.LyricNone
         lrcContent = SearchOnline.get_lrc_from_musicid(musicId)
         return lrcContent if lrcContent else Configures.LyricNone
     except:
         return Configures.LyricNone
 def set_basic_infos(self, title, totalTime, album, path, size, musicId):
     artist, musicName = get_artist_and_musicname_from_title(title)
     self.title = title
     self.artist = artist
     self.musicName = musicName
     self.album = album
     self.path = path
     self.artistEdit.setText(artist)
     self.musicEdit.setText(musicName)
     self.albumEdit.setText(album)
     self.timeLabel.setText('时长: %s'%totalTime)
     self.sizeLabel.setText('大小: %.2f MB'%convert_B_to_MB(size))
     self.pathLabel.setText(path)
     trace = '线上资源'
     if musicId == Configures.LocalMusicId:
         trace = '本地资源'
     self.traceInfoLabel.setText('歌曲来源: %s'%trace)
     self.set_favorite_info(title in self.lovedSongs)
     item = get_base_name_from_path(path)
     freq, totalSpan, spanMax, nearPlaylistName, nearPlayedDate, nearPlayedTime = self.songinfosManager.get_statistic_infos_of_item(item)
     if freq:
         countInfos = '播放次数: %i 次#平均播放时长: %.1f 秒#最长播放时长: %.1f 秒'%(freq, totalSpan/freq, spanMax)
         nearPlaylistInfo = '最近播放位置: %s#最近播放时长: %.1f 秒'%(nearPlaylistName,nearPlayedTime)
         nearPlayedDateInfo = '最近播放: %s'%format_time_str_with_weekday(nearPlayedDate)
     else:
         countInfos = '播放次数: 0 次'
         nearPlaylistInfo = '最近播放位置: 未曾播放'
         nearPlayedDateInfo = '最近播放: 未曾播放'
     self.countInfoLabel.setText(countInfos.replace('#', ' '*15))
     self.nearPlaylistLabel.setText(nearPlaylistInfo.replace('#', ' '*15))
     self.nearPlayedDateLabel.setText(nearPlayedDateInfo)
 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))
 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))
Example #7
0
 def tag_values_changed(self, row, oldTitle, title, album):
     widget = self.managePage.playlistWidget
     playlist = widget.get_playlist()
     if oldTitle != title:
         if widget.get_playing_used_state():
             self.playbackPanel.playlist.set_music_title_at(row, title, False)
             if row == self.playbackPanel.currentSourceRow:
                 artistName, musicName = get_artist_and_musicname_from_title(title)
                 self.playbackPanel.playAction.setText(musicName)
                 self.playbackPanel.musicTitleLabel.setText(title)
         if playlist.get_name() == Configures.PlaylistFavorite:
             index = self.playbackPanel.lovedSongs.index(oldTitle)
             self.playbackPanel.lovedSongs[index] = title
         self.playbackPanel.check_favorite()
         thread = DownloadLrcThread(((title, Configures.LocalMusicId), ))
         thread.setDaemon(True)
         thread.setName("downloadLrc")
         thread.start()
     else:
         if widget.get_playing_used_state():
             self.playbackPanel.playlist.set_music_album_at(row, album, False)
Example #8
0
 def show_artist_info(self):
     row = self.currentRow()
     artist, musicName = get_artist_and_musicname_from_title(
         self.playlist.get_music_title_at(row))
     self.show_artist_info_signal.emit(artist)
Example #9
0
 def update_artist_info(self, title):
     artist, musicName = get_artist_and_musicname_from_title(title)
     return self.set_artist_info(artist)
Example #10
0
 def show_artist_info(self):
     row = self.currentRow()
     artist, musicName = get_artist_and_musicname_from_title(self.playlist.get_music_title_at(row))
     self.show_artist_info_signal.emit(artist)
 def update_artist_info(self, title):
     artist, musicName = get_artist_and_musicname_from_title(title)
     return self.set_artist_info(artist)