Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))