diff --git a/mod-music/discord/cached.go b/mod-music/discord/cached.go index c9d3125..8682749 100644 --- a/mod-music/discord/cached.go +++ b/mod-music/discord/cached.go @@ -37,7 +37,7 @@ func (d *Discord) handleCacheListCommand(s *discordgo.Session, m *discordgo.Mess // Iterate over the files and append their names and IDs to the buffer for _, file := range files { // Append file name and ID to the buffer - fileList.WriteString(fmt.Sprintf("- `%s`\n", file.Name())) + fileList.WriteString(fmt.Sprintf("`%s`\n", file.Name())) } // Send the list of cached files as a message diff --git a/mod-music/discord/play.go b/mod-music/discord/play.go index 794b159..72000d0 100644 --- a/mod-music/discord/play.go +++ b/mod-music/discord/play.go @@ -141,6 +141,7 @@ func getSongsFromSources(originType string, songsOrigins []string, guildID strin song = &player.Song{ SongID: existingTrack.SongID, Title: existingTrack.Title, + URL: existingTrack.URL, Filepath: existingTrack.Filepath, } } else { @@ -190,6 +191,7 @@ func getSongsFromSources(originType string, songsOrigins []string, guildID strin if track.Source == "LocalFile" { slog.Info("Track is from LocalFile") song = []*player.Song{{ + SongID: track.SongID, Title: track.Title, URL: track.URL, Filepath: track.Filepath, @@ -318,8 +320,16 @@ func showStatusMessage(d *Discord, s *discordgo.Session, channelID, prevMessageI // Display current song information if currentSong := d.Player.GetCurrentSong(); currentSong != nil { + var sourceLabels string if len(currentSong.URL) > 0 { - content += fmt.Sprintf("\n**`%v`**\n[%v](%v)\n\n", strings.ToLower(currentSong.Source.String()), currentSong.Title, currentSong.URL) + + if currentSong.Source == player.SourceLocalFile && utils.IsYouTubeURL(currentSong.URL) { + sourceLabels = "`youtube cached`" + } else { + sourceLabels = "`" + strings.ToLower(currentSong.Source.String()) + "`" + } + + content += fmt.Sprintf("\n**`%v`**\n[%v](%v)\n\n", sourceLabels, currentSong.Title, currentSong.URL) } else { content += fmt.Sprintf("\n**`%v`**\n%v\n\n", strings.ToLower(currentSong.Source.String()), currentSong.Title) } diff --git a/mod-music/player/play.go b/mod-music/player/play.go index 23ce9b6..899de55 100644 --- a/mod-music/player/play.go +++ b/mod-music/player/play.go @@ -96,28 +96,19 @@ func (p *Player) Play(startAt int, song *Song) error { p.SetStreamingSession(stream) p.SetCurrentStatus(StatusPlaying) - // Create song ID - var songID string - slog.Fatal(p.GetCurrentSong().SongID) - if len(p.GetCurrentSong().SongID) > 0 { - songID = p.GetCurrentSong().SongID - } else { - songID = GetMD5Hash(p.GetCurrentSong().Title) - } - // Add song to history historySong := &history.Song{ Title: p.GetCurrentSong().Title, URL: p.GetCurrentSong().URL, Filepath: p.GetCurrentSong().Filepath, Duration: p.GetCurrentSong().Duration, - SongID: songID, + SongID: p.GetCurrentSong().SongID, Thumbnail: history.Thumbnail(p.GetCurrentSong().Thumbnail), Source: p.GetCurrentSong().Source.String(), } p.GetHistory().AddTrackToHistory(p.GetVoiceConnection().GuildID, historySong) - if err := p.GetHistory().AddPlaybackCountStats(p.GetVoiceConnection().GuildID, songID); err != nil { + if err := p.GetHistory().AddPlaybackCountStats(p.GetVoiceConnection().GuildID, p.GetCurrentSong().SongID); err != nil { slog.Errorf("error adding playback count stats to history: %v", err) } @@ -135,7 +126,7 @@ func (p *Player) Play(startAt int, song *Song) error { select { case <-ticker.C: if p.GetVoiceConnection() != nil && p.GetStreamingSession() != nil && p.GetCurrentSong() != nil && !p.GetStreamingSession().Paused() { - err := p.GetHistory().AddPlaybackDurationStats(p.GetVoiceConnection().GuildID, songID, float64(interval.Seconds())) + err := p.GetHistory().AddPlaybackDurationStats(p.GetVoiceConnection().GuildID, p.GetCurrentSong().SongID, float64(interval.Seconds())) if err != nil { slog.Warnf("Error adding playback duration stats to history: %v", err) }