Index: HTML/Default/songinfo.html
===================================================================
--- HTML/Default/songinfo.html (revision 2884)
+++ HTML/Default/songinfo.html (working copy)
@@ -148,7 +148,7 @@
[% IF itempath %]
[% "LOCATION" | string; "COLON" | string %] |
- [% itempath | unuri | utf8decode | html %] ([% "DOWNLOAD" | string %]) |
+ [% itempath | unuri | utf8decode | html %] ([% "DOWNLOAD" | string %]) |
[% END %]
Index: HTML/Fishbone/songinfo.html
===================================================================
--- HTML/Fishbone/songinfo.html (revision 2884)
+++ HTML/Fishbone/songinfo.html (working copy)
@@ -195,7 +195,7 @@
[% "LOCATION" | string; "COLON" | string %]
- [% itempath | unuri | utf8decode | html %] ([% "DOWNLOAD" | string %])
+ [% itempath | unuri | utf8decode | html %] ([% "DOWNLOAD" | string %])
|
Index: HTML/EN/songinfo.html
===================================================================
--- HTML/EN/songinfo.html (revision 2884)
+++ HTML/EN/songinfo.html (working copy)
@@ -149,7 +149,7 @@
[% "LOCATION" | string; "COLON" | string %]
- [% itempath | unuri | utf8decode | html %]([% "DOWNLOAD" | string %])
+ [% itempath | unuri | utf8decode | html %]([% "DOWNLOAD" | string %])
|
[% END %]
Index: Slim/Web/HTTP.pm
===================================================================
--- Slim/Web/HTTP.pm (revision 2884)
+++ Slim/Web/HTTP.pm (working copy)
@@ -11,6 +11,7 @@
use Digest::MD5;
use FileHandle;
+use File::Basename qw(basename);
use File::Spec::Functions qw(:ALL);
use FindBin qw($Bin);
use HTTP::Daemon;
@@ -804,23 +805,24 @@
$contentType = "image/png";
}
- } elsif ($path =~ /music\/(.+)$/) {
+ } elsif ($path =~ /music\/(\d+)\/download$/) {
- my $file = Slim::Utils::Misc::virtualToAbsolute($1);
+ my $ds = Slim::Music::Info::getCurrentDataStore();
+ my $obj = $ds->objectForId('track', $1);
- if (Slim::Music::Info::isSong($file) && Slim::Music::Info::isFile($file)) {
+ if ($obj && Slim::Music::Info::isSong($obj) && Slim::Music::Info::isFile($obj)) {
- $::d_http && msg("Opening $file to stream...\n");
+ $::d_http && msg("Opening $obj to stream...\n");
- my $songHandle = FileHandle->new(Slim::Utils::Misc::pathFromFileURL($file));
+ my $songHandle = FileHandle->new(Slim::Utils::Misc::pathFromFileURL($obj->url()));
if ($songHandle) {
- my $ds = Slim::Music::Info::getCurrentDataStore();
- my $obj = $ds->objectForUrl($file);
-
- $response->content_type(Slim::Music::Info::mimeType($file));
+ # Send the file down - and hint to the browser
+ # the correct filename to save it as.
+ $response->content_type($obj->content_type());
$response->content_length($obj->filesize());
+ $response->header('Content-Disposition', sprintf('attachment; filename=%s', basename($obj->url())));
my $headers = _stringifyHeaders($response) . $CRLF;
Index: Slim/Web/Pages.pm
===================================================================
--- Slim/Web/Pages.pm (revision 2884)
+++ Slim/Web/Pages.pm (working copy)
@@ -1823,52 +1823,18 @@
if ($track->coverArt('thumb')) {
$params->{'coverThumb'} = $track->id;
}
- }
-
- my $downloadurl;
- if (Slim::Music::Info::isHTTPURL($song)) {
+ if (Slim::Music::Info::isRemoteURL($track->url)) {
- $downloadurl = $song;
+ $params->{'download'} = $track->url();
- } else {
-
- my $loc = $song;
-
- if (Slim::Music::Info::isFileURL($song)) {
- $loc = Slim::Utils::Misc::pathFromFileURL($loc);
- }
-
- # We need to turn the utf8 flag back on, after it's been
- # stripped, so the url encoding will be correct.
- if ($Slim::Utils::Misc::locale eq 'utf8') {
- $loc = Slim::Utils::Misc::utf8decode($loc);
- }
-
- my $curdir = Slim::Utils::Prefs::get('audiodir');
-
- if (!$curdir) {
-
- $downloadurl = undef;
-
- } elsif ($loc =~ /^\Q$curdir\E(.*)/i) {
-
- $downloadurl = '/music';
-
- for my $item (splitdir($1)) {
- $downloadurl .= '/' . Slim::Web::HTTP::escape($item);
- }
-
- $downloadurl =~ s/\/\//\//;
-
} else {
- $downloadurl = $loc;
+ $params->{'download'} = sprintf('/music/%d/download', $track->id());
}
}
-
+
$params->{'itempath'} = $song;
- $params->{'download'} = $downloadurl;
}
sub songInfo {