-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
109 lines (101 loc) · 3.54 KB
/
index.php
File metadata and controls
109 lines (101 loc) · 3.54 KB
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
<meta name="charset" content="utf-8">
<meta charset="utf-8">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#main').hide();
var downinfo = {img:'',mp3:'',name:'', songId:0, hasDown:false};
$('#api').click(function () {
var songId = 0;
var result = $('#songId').val().trim().replace(/\?.*?$/, '').match(/\d+$/);
if (result) {
songId = parseInt(result[0]);
}
songId = songId ? songId : parseInt($('#songId').val().trim());
if (songId<1) {
alert('error id');
return;
}
$('#songImg').attr('src', "./load.png");
$('#main').hide();
$.ajax({
url: 'api.php',
type: 'POST',
dataType: 'json',
data: {action: 'api', songId:songId},
complete: function(xhr, textStatus) {
//called when complete
},
success: function(data, textStatus, xhr) {
if (data && data.song_id) {
// do not
} else {
alert('error');
return;
}
//called when successful
downinfo.songId = data.song_id;
downinfo.img=data.album_pic;
downinfo.mp3=data.location;
downinfo.name=data.title;
downinfo.hasDown=!!parseInt(data.hasDown);
$('#songId').val(data.song_id);
$('#songImg').attr('src', downinfo.img);
$('#songTitle').text(downinfo.name);
if (downinfo.hasDown) {
$('#songHasDown').show();
} else {
$('#songHasDown').hide();
}
$('#main').show();
},
error: function(xhr, textStatus, errorThrown) {
//called when there is an error
$('#main').hide();
alert('error');
}
});
});
$('#download').click(function () {
$('#api').prop('disabled', true);
$('#download').prop('disabled', true);
$.ajax({
url: 'api.php',
type: 'POST',
dataType: 'json',
data: {action: 'download', songId:downinfo.songId},
complete: function(xhr, textStatus) {
//called when complete
$('#download').prop('disabled', false);
$('#api').prop('disabled', false);
},
success: function(data, textStatus, xhr) {
//called when successful
$('#songHasDown').show();
},
error: function(xhr, textStatus, errorThrown) {
//called when there is an error
alert('error down');
}
});
});
});
</script>
<body id="" style="min-width:640px;">
<div style="margin:100px auto;width:400px;text-align:center;">
<form id="downloadForm" onsubmit="if(!$('#api').prop('disabled')){$('#api').click();}return false;" method="get" accept-charset="utf-8">
<label for="songId">songId </label><input type="text" name="songId" value="" id="songId">
<input id="api" type="button" value="getinfo →">
</form>
<div id="main" style="text-align:center;">
<img id="songImg" src="" style="width:185px;height:185px;" />
<br>
<span id="songTitle" ></span>
<br>
<span id="songHasDown" style="color:red;" >已经下载了</span>
<br>
<br>
<input id="download" type="button" value="download →">
</div>
</div>
</body>