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
|
<?php
require_once("databaseconnect.php");
require_once("logger.php");
set_time_limit(0);
if(!isset($_GET["hash"]))
{
echo "Invalid hash.";
exit;
}
if(!($row = mysql_fetch_assoc(mysql_query("SELECT file,track,artist,album,title,format,sha1 FROM musictags WHERE sha1 = ".nullString($_GET["hash"])))))
{
echo "Can't find file.";
exit;
}
if (!isset($_SERVER['HTTP_RANGE']))
logDownload(array($row), false);
if($_GET["transcode"] == true)
{
header('Content-Type: audio/mpeg');
header('Content-Transfer-Encoding: binary');
$command = 'ffmpeg -i '.escapeshellarg($row["file"]).' -f mp3 -y -ab 160';
if($row["title"] != "")
{
$command .= " -metadata ".escapeshellarg("title=".$row["title"]);
}
if($row["artist"] != "")
{
$command .= " -metadata ".escapeshellarg("artist=".$row["artist"]);
}
if($row["album"] != "")
{
$command .= " -metadata ".escapeshellarg("album=".$row["album"]);
}
$command .= ' -';
passthru($command);
}
else
{
switch($row["format"])
{
case "mp3":
$mime = "audio/mpeg";
break;
case "m4a":
$mime = "audio/mp4";
break;
case "flac":
$mime = "audio/x-flac";
break;
case "wav":
$mime = "audio/x-wav";
break;
case "ogg":
$mime = "audio/x-ogg";
break;
case "wma":
$mime = "audio/x-ms-wma";
break;
default:
$mime = "application/octet-stream";
break;
}
$filelength = @filesize($row["file"]);
$length = $filelength;
$posfrom = 0;
$posto = $length - 1;
if(isset($_SERVER['HTTP_RANGE']))
{
$data = explode('=',$_SERVER['HTTP_RANGE']);
$ppos = explode('-', trim($data[1]));
$posfrom = (int)trim($ppos[0]);
if(trim($ppos[1]) != "")
{
$posto = (int)trim($ppos[1]);
}
$length = $posto - $posfrom + 1;
header('HTTP/1.1 206 Partial Content', true);
header('Content-Range: bytes '.$posfrom.'-'.$posto.'/'.$filelength);
}
header('Accept-Ranges: bytes');
header('Content-Disposition: inline; filename="'.getPrettyFilename($row).'"');
header('Content-Type: '.$mime);
header('Content-Transfer-Encoding: binary');
header('Pragma: public');
header('Content-Length: '.$length);
$handle = @fopen($row["file"], "rb");
@fseek($handle, $posfrom, SEEK_SET);
@fpassthru($handle);
}
?>
|