forked from MichaelBelgium/Youtube-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
125 lines (118 loc) · 5.82 KB
/
Copy pathindex.php
File metadata and controls
125 lines (118 loc) · 5.82 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Youtube to MP3</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
</head>
<body>
<div class="p-2">
<div class="card">
<div class="card-header">
<h5 class="card-title">Youtube to mp3</h5>
</div>
<div class="card-body">
<form action="convert.php" method="post" id="frm-convert">
<div class="form-group">
<input type="text" name="youtubelink" class="form-control" id="link" placeholder="Youtube url" required />
</div>
<div class="form-group">
<label for="format">Format</label>
<select class="form-control" name="format" id="format">
<option value="mp3">Audio (mp3)</option>
<option value="mp4">Video (mp4)</option>
</select>
</div>
<button type="submit" class="btn btn-outline-primary"><i class="fa fa-refresh" aria-hidden="true"></i> Convert</button>
</form>
</div>
</div>
<div class="card mt-3">
<div class="card-header">
<h5 class="card-title">Json response</h5>
</div>
<div class="card-body">
<pre>{}</pre>
</div>
<div class="card-footer">
<table class="table table-borderless table-sm w-auto">
<tbody>
<tr>
<td>Error:</td>
<td><i class="fa fa-times" aria-hidden="true"></i></td>
</tr>
<tr>
<td>Error message:</td>
<td>-</td>
</tr>
<tr>
<td>Title:</td>
<td>-</td>
</tr>
<tr>
<td>Duration</td>
<td><span id="duration">0</span> seconds</td>
</tr>
<tr>
<td>Youtube ID</td>
<td></td>
</tr>
<tr>
<td>Uploaded at</td>
<td></td>
</tr>
<tr>
<td>
<a target="_blank" class="btn btn-outline-primary disabled" href="#" id="download"><i class="fa fa-cloud-download" aria-hidden="true"></i> Listen/download</a>
<a class="btn btn-outline-danger disabled" href="#" id="remove" data-id="">Remove</a>
</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("#frm-convert").submit(function(e) {
$("#frm-convert button[type=submit]").html("<i class=\"fa fa-spin fa-refresh\" aria-hidden=\"true\"></i> Converting... Please wait");
e.preventDefault();
$.get($(this).attr("action"), { youtubelink: $('#link').val(), format: $('#format').val() }, function(data) {
$("pre").text(JSON.stringify(data, null, 4));
$("#frm-convert button[type=submit]").html("<i class=\"fa fa-refresh\" aria-hidden=\"true\"></i> Convert");
if(data.error) {
$("table tr:eq(0) td:last").html("<i class=\"fa fa-check\" aria-hidden=\"true\"></i>");
$("table tr:eq(1) td:last").text(data.message);
$("table tr:eq(2) td:last").text("-");
$("table tr:eq(3) td:last").text(0);
$("table tr:eq(4) td:last").text("-");
$("table tr:eq(5) td:last").text("-");
$("#download").attr("href", "#").addClass("disabled");
$("#remove").addClass("disabled");
} else {
$("table tr:eq(0) td:last").html("<i class=\"fa fa-times\" aria-hidden=\"true\"></i>");
$("table tr:eq(1) td:last").text("-");
$("table tr:eq(2) td:last").text(data.title + " (" + data.alt_title + ")");
$("table tr:eq(3) td:last").text(data.duration);
$("table tr:eq(4) td:last").text(data.youtube_id);
$("table tr:eq(5) td:last").text(new Date(data.uploaded_at.date));
$("#download").attr("href", data.file).removeClass("disabled");
$("#remove").removeClass("disabled").data("id", data.youtube_id);
}
});
});
$("#remove").click(function() {
$.get("convert.php", { delete: $(this).data("id") }, function(data) {
alert(data.message);
});
});
});
</script>
</body>
</html>