Ability to download tracks

- Adding the option to download the selected track or tracks.
When the download is clicked it opens a dialog that lets you choose where
you want to save the track and the file name (by default
the file name is the track number, the track name and the extension, example "03 - my song.mp3")
If there are many tracks selected it will open one dialog for each track
- Next steps: download an album and a playlist using zip
This commit is contained in:
natilou
2023-06-15 10:12:53 -03:00
parent 7b15fe95e4
commit f190aaf732
6 changed files with 81 additions and 8 deletions
+17 -6
View File
@@ -70,12 +70,13 @@ type Tracklist struct {
DisableSorting bool
// user action callbacks
OnPlayTrackAt func(int)
OnPlaySelection func(tracks []*mediaprovider.Track, shuffle bool)
OnAddToQueue func(trackIDs []*mediaprovider.Track)
OnAddToPlaylist func(trackIDs []string)
OnSetFavorite func(trackIDs []string, fav bool)
OnSetRating func(trackIDs []string, rating int)
OnPlayTrackAt func(int)
OnPlaySelection func(tracks []*mediaprovider.Track, shuffle bool)
OnAddToQueue func(trackIDs []*mediaprovider.Track)
OnAddToPlaylist func(trackIDs []string)
OnSetFavorite func(trackIDs []string, fav bool)
OnSetRating func(trackIDs []string, rating int)
OnShowDownloadDialog func(track *mediaprovider.Track)
OnShowArtistPage func(artistID string)
OnShowAlbumPage func(albumID string)
@@ -508,6 +509,10 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
t.OnAddToPlaylist(t.SelectedTrackIDs())
}
}))
t.ctxMenu.Items = append(t.ctxMenu.Items,
fyne.NewMenuItem("Download", func() {
t.onDownload(t.selectedTracks())
}))
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
t.ctxMenu.Items = append(t.ctxMenu.Items,
fyne.NewMenuItem("Set favorite", func() {
@@ -582,6 +587,12 @@ func (t *Tracklist) onAlbumTapped(albumID string) {
}
}
func (t *Tracklist) onDownload(tracks []*mediaprovider.Track) {
for _, track := range tracks {
t.OnShowDownloadDialog(track)
}
}
func (t *Tracklist) findTrackByID(id string) *mediaprovider.Track {
idx := sharedutil.Find(t.tracks, func(tr *trackModel) bool {
return tr.track.ID == id