-
Notifications
You must be signed in to change notification settings - Fork 0
/
songs.go
150 lines (127 loc) · 3.72 KB
/
songs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"image"
"net/http"
"qusic/logger"
"qusic/lyrics"
pl "qusic/player"
"qusic/preferences"
"qusic/widgets"
"strings"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
fynesyncedlyrics "github.com/dweymouth/fyne-lyrics"
)
func getLyrics(song *pl.Song) {
lyricsTxt = fynesyncedlyrics.NewLyricsViewer()
lyricsTxt.TextSizeName = theme.SizeNameHeadingText
lyricPage.Objects[2] = lyricsTxt
lyricPage.Refresh()
source := preferences.Preferences.String("lyrics.source")
var err error
switch source {
case "lrclib":
song.Lyrics, err = lyrics.GetSongLRCLIB(song.Name, song.Artists[0].Name, song.Album.Name, song.Duration, false)
case "spotify":
song.Lyrics, err = lyrics.GetLyricsSpotify(spotifyClient, song.ID)
case "youtubesub":
song.Lyrics, err = lyrics.GetLyricsYouTubeSubtitles(song.Video)
case "ytmusicsynced":
song.Lyrics, err = lyrics.GetSongYTMusicSynced(song.Video.ID)
case "ytmusicplain":
song.Lyrics, err = lyrics.GetSongYTMusicPlain(song.Video.ID)
case "genius":
song.Lyrics, err = lyrics.GetSongGenius(song.Artists[0].Name, song.Name)
case "lyrics.ovh":
song.Lyrics, err = lyrics.GetSongLyricsOVH(song.Artists[0].Name, song.Name)
}
if err != nil {
logger.Errorf("No lyrics for %s<source:%s,album:%s,artist:%s,duration:%s>:%v", song.Name, source, song.Album.Name, song.Artists[0].Name, song.Duration, err)
} else {
logger.Infof("Fetched lyrics for %s (source: %s)", song.Name, source)
}
syncedLyrics = song.Lyrics.SyncedLyrics
lyricsAlt.Hide()
lyricsTxt.Show()
if len(syncedLyrics) == 0 {
if song.Lyrics.PlainLyrics == "" {
lyricsAlt.ParseMarkdown("# Sorry, no lyrics were found for this song. Maybe try a different source.")
lyricsAlt.Show()
lyricsTxt.Hide()
} else {
lyricsTxt.SetLyrics(strings.Split(song.Lyrics.PlainLyrics, "\n"), false)
}
} else {
var lines = make([]string, len(syncedLyrics))
for i, lyric := range syncedLyrics {
lines[i] = lyric.Lyric
}
lyricsTxt.SetLyrics(lines, true)
}
tabs.EnableIndex(2)
}
func setPlayedSong(song *pl.Song, w fyne.Window) {
logger.Infof("Now played song: %s (%s)", song.Name, song.URL)
getLyrics(song)
pause.SetIcon(theme.MediaPauseIcon())
d, err := http.Get(song.Thumbnails.Min().URL)
if err != nil {
return
}
image, _, _ := image.Decode(d.Body)
img := canvas.NewImageFromImage(image)
if preferences.Preferences.Bool("hardware_acceleration") {
img.ScaleMode = canvas.ImageScaleFastest
}
songProgressSlider.Max = float64(song.Duration / time.Millisecond)
songProgressSlider.Enable()
fulld.Segments[0].(*widget.TextSegment).Text = durString(song.Duration)
fulld.Segments[0].(*widget.TextSegment).Style.ColorName = theme.ColorNameForeground
fulld.Refresh()
back.Enable()
pause.Enable()
next.Enable()
songinfo := &widgets.SongInfo{
Name: song.Name,
Artist: song.Artists[0].Name,
Image: img,
}
bottom.Objects[0] = songinfo
bottom.Refresh()
}
func play(i int, w fyne.Window) {
q := player.Queue()
s := q[i]
player.GetVideo(s)
logger.Inff("Playing song %s: ", s.Name)
err := player.Play(i)
songProgressSlider.SetValue(0)
logger.Println(err)
setPlayedSong(s, w)
if err != nil {
//dialog.NewError(fmt.Errorf("There was an error playing your song, please check logs"), w).Show()
showToast("There was an error playing your song, please check logs")
stopPlayer()
}
if err != nil {
return
}
}
func playnow(so *pl.Song, w fyne.Window) {
player.GetVideo(so)
logger.Inff("Playing song %s: ", so.Name)
err := player.PlayNow(so)
songProgressSlider.SetValue(0)
logger.Println(err)
setPlayedSong(so, w)
if err != nil {
showToast("There was an error playing your song, please check logs")
stopPlayer()
}
if err != nil {
return
}
}