Skip to content

🎧 Your Personal Streaming Service

Add download for songs

Deluan6fe1f84c68c4
diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json
index c3b725027..a9227c668 100644
--- a/resources/i18n/pt.json
+++ b/resources/i18n/pt.json
@@ -24,7 +24,8 @@
"addToQueue": "Adicionar à fila",
"playNow": "Tocar agora",
"addToPlaylist": "Adicionar à playlist",
- "shuffleAll": "Aleatório"
+ "shuffleAll": "Aleatório",
+ "download": "Baixar"
}
},
"album": {
diff --git a/server/subsonic/stream.go b/server/subsonic/stream.go
index 800ce7640..05c3480ee 100644
--- a/server/subsonic/stream.go
+++ b/server/subsonic/stream.go
@@ -86,9 +86,9 @@ func (c *StreamController) Download(w http.ResponseWriter, r *http.Request) (*re
}
setHeaders := func(name string) {
- filename := fmt.Sprintf("attachment; filename=%s.zip", name)
- filename = strings.ReplaceAll(filename, ",", "_")
- w.Header().Set("Content-Disposition", filename)
+ name = strings.ReplaceAll(name, ",", "_")
+ disposition := fmt.Sprintf("attachment; filename=\"%s.zip\"", name)
+ w.Header().Set("Content-Disposition", disposition)
w.Header().Set("Content-Type", "application/zip")
}
@@ -99,6 +99,8 @@ func (c *StreamController) Download(w http.ResponseWriter, r *http.Request) (*re
return nil, err
}
+ disposition := fmt.Sprintf("attachment; filename=\"%s\"", stream.Name())
+ w.Header().Set("Content-Disposition", disposition)
http.ServeContent(w, r, stream.Name(), stream.ModTime(), stream)
return nil, nil
case *model.Album:
diff --git a/ui/src/common/AlbumContextMenu.js b/ui/src/common/AlbumContextMenu.js
index d0a8ae7db..2646c19f5 100644
--- a/ui/src/common/AlbumContextMenu.js
+++ b/ui/src/common/AlbumContextMenu.js
@@ -35,22 +35,27 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
const options = {
play: {
+ needData: true,
label: 'resources.album.actions.playAll',
action: (data, ids) => dispatch(playTracks(data, ids)),
},
addToQueue: {
+ needData: true,
label: 'resources.album.actions.addToQueue',
action: (data, ids) => dispatch(addTracks(data, ids)),
},
shuffle: {
+ needData: true,
label: 'resources.album.actions.shuffle',
action: (data, ids) => dispatch(shuffleTracks(data, ids)),
},
addToPlaylist: {
+ needData: true,
label: 'resources.album.actions.addToPlaylist',
action: (data, ids) => dispatch(openAddToPlaylist({ selectedIds: ids })),
},
download: {
+ needData: false,
label: 'resources.album.actions.download',
action: () => subsonic.download(record.id),
},
@@ -80,19 +85,23 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
const handleItemClick = (e) => {
setAnchorEl(null)
const key = e.target.getAttribute('value')
- dataProvider
- .getList('albumSong', {
- pagination: { page: 1, perPage: -1 },
- sort: { field: 'discNumber, trackNumber', order: 'ASC' },
- filter: { album_id: record.id, disc_number: discNumber },
- })
- .then((response) => {
- let { data, ids } = extractSongsData(response)
- options[key].action(data, ids)
- })
- .catch(() => {
- notify('ra.page.error', 'warning')
- })
+ if (options[key].needData) {
+ dataProvider
+ .getList('albumSong', {
+ pagination: { page: 1, perPage: -1 },
+ sort: { field: 'discNumber, trackNumber', order: 'ASC' },
+ filter: { album_id: record.id, disc_number: discNumber },
+ })
+ .then((response) => {
+ let { data, ids } = extractSongsData(response)
+ options[key].action(data, ids)
+ })
+ .catch(() => {
+ notify('ra.page.error', 'warning')
+ })
+ } else {
+ options[key].action()
+ }
e.stopPropagation()
}
diff --git a/ui/src/common/SongContextMenu.js b/ui/src/common/SongContextMenu.js
index 4e8c5ca09..6125e76db 100644
--- a/ui/src/common/SongContextMenu.js
+++ b/ui/src/common/SongContextMenu.js
@@ -9,6 +9,7 @@ import StarIcon from '@material-ui/icons/Star'
import StarBorderIcon from '@material-ui/icons/StarBorder'
import { addTracks, setTrack } from '../audioplayer'
import { openAddToPlaylist } from '../dialogs/dialogState'
+import subsonic from '../subsonic'
const useStyles = makeStyles({
noWrap: {
@@ -39,19 +40,25 @@ const SongContextMenu = ({
const options = {
playNow: {
label: 'resources.song.actions.playNow',
- action: (record) => setTrack(record),
+ action: (record) => dispatch(setTrack(record)),
},
addToQueue: {
label: 'resources.song.actions.addToQueue',
- action: (record) => addTracks({ [record.id]: record }),
+ action: (record) => dispatch(addTracks({ [record.id]: record })),
},
addToPlaylist: {
label: 'resources.song.actions.addToPlaylist',
action: (record) =>
- openAddToPlaylist({
- selectedIds: [record.mediaFileId || record.id],
- onSuccess: (id) => onAddToPlaylist(id),
- }),
+ dispatch(
+ openAddToPlaylist({
+ selectedIds: [record.mediaFileId || record.id],
+ onSuccess: (id) => onAddToPlaylist(id),
+ })
+ ),
+ },
+ download: {
+ label: 'resources.song.actions.download',
+ action: (record) => subsonic.download(record.id),
},
}
@@ -69,7 +76,7 @@ const SongContextMenu = ({
e.preventDefault()
setAnchorEl(null)
const key = e.target.getAttribute('value')
- dispatch(options[key].action(record))
+ options[key].action(record)
e.stopPropagation()
}
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index a189a4de7..9d73bce7e 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -25,7 +25,8 @@
"addToQueue": "Play Later",
"addToPlaylist": "Add to Playlist",
"playNow": "Play Now",
- "shuffleAll": "Shuffle All"
+ "shuffleAll": "Shuffle All",
+ "download": "Download"
}
},
"album": {
diff --git a/ui/src/subsonic/index.js b/ui/src/subsonic/index.js
index aa77d785c..5338e643c 100644
--- a/ui/src/subsonic/index.js
+++ b/ui/src/subsonic/index.js
@@ -26,6 +26,6 @@ const url = (command, id, options) => {
const scrobble = (id, submit) =>
fetchUtils.fetchJson(url('scrobble', id, { submission: submit }))
-const download = (id, submit) => (window.location.href = url('download', id))
+const download = (id) => (window.location.href = url('download', id))
export default { url, scrobble, download }