-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
214 lines (176 loc) · 7.77 KB
/
index.php
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
* User: Benftwc
* Date: 18/11/13 21:00
*/
function getServer() {
try{
$server = new PDO('mysql:host=localhost;dbname=listenandrain', '*****', '*****');
}
catch(Exception $e)
{
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
return $server;
}
function insertData($name, $yid){
$server = getServer();
$query = $server->prepare("INSERT INTO `datas` (name ,yid, count) VALUES ( :name, :yid, 1);");
$query->bindParam(':name', $name);
$query->bindParam(':yid', $yid);
return $query->execute();
}
function updateCount($yid) {
$server = getServer();
$result = $server->exec("UPDATE `datas` SET count=count+1 WHERE yid='" . $yid . "'");
//var_dump($result);
}
function addDatas($name, $yid){
$server = getServer();
$query = $server->query("SELECT * FROM `datas` WHERE yid = '" . $yid . "' LIMIT 0,1");
$result = $query->fetchAll(PDO::FETCH_ASSOC);
if(count($result) != 0) {
updateCount($yid);
} else {
insertData($name, $yid);
}
}
$vid = (isset($_GET['v'])) ? $_GET['v'] : NULL;
$rain = (isset($_GET['r'])) ? $_GET['r'] : "1";
$video = FALSE;
if(isset($vid)){
require_once("youtube-parser.php");
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $vid;
$entry = simplexml_load_file($feedURL);
$video = parseVideoEntry($entry);
addDatas($video->title, $vid);
}
if($video) {
$title = $video->title . ' - Listen and Rain';
} else {
$title = "Listen And Rain - Youtube Enhancer";
}
$imageID = rand(1,3);
$background = 'backgrounds/' . $imageID . '.gif';
?>
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title><?php echo $title; ?></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<style type="text/css">
* { margin: 0; padding: 0; }
html { background: black; }
h1 { font: bold 50px/1 Sans-Serif; letter-spacing: -2px; margin: 0 0 20px 0; text-align: center;}
h3 {margin: 0 0 20px 0; text-align: center;}
body {height:100%; width: 100%; background: white; background-image: url('<?php echo $background; ?>'); background-size: cover; background-position: 50% 50%;}
.form {margin: 50px auto; width: 50%}
.container {width: 50%; padding:20px; margin: 0 auto; background: rgba(255, 255, 255, 0.75);}
form > * {width: 100%; text-align: center;}
iframe { width: 100%; margin: 0 0 20px 0; }
@media (max-width: 480px) {
body { width: 90%; }
}
</style>
</head>
<body>
<div class="container">
<a href="https://github.com/benftwc/listenandrain"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
<h1>Listen and Rain<br>
<small>Youtube Enhancer</small></h1>
<?php if(isset($vid) && !is_null($vid)): ?>
<iframe id="iframe" src="http://www.youtube.com/embed/<?php echo $vid; ?>?rel=0&hd=1&autoplay=1&iv_load_policy=3" frameborder="0" allowfullscreen="" style="width: 100%; height: 511px;"></iframe>
<h3><?php echo $video->title; ?></h3>
<div class="controllers">
Repeater : <input type="checkbox" checked="checked" class="repeater" /> <span class="repeater-counter">1</span> listens<br />
Mood :
<?php if(!$rain) : ?>
<span class="play">Play</span>
<span class="pause" style="display: none;">Pause</span>
<?php else: ?>
<span class="pause">Pause</span>
<span class="play" style="display: none;">Play</span>
<?php endif; ?>
( Set volume to :
<span class="quarter">1/3</span>
<span class="half" style="display: none">2/3</span>
<span class="full" style="display: none">3/3</span>
)
</div>
<audio id="audio"<?php if($rain) : ?> autoplay<?php endif; ?> loop>
<source src="audio/rain.ogg" type="audio/ogg">
<source src="audio/rain.m4a" type="audio/mp4">
<source src="audio/rain.mp3" type="audio/mpeg">
</audio>
<script>
$("#iframe").ready(function () {
var plays = 1;
setInterval(function(){
if ($(".repeater").is(':checked')) {
$('#iframe').attr("src", $('#iframe').attr("src"));
plays++;
$('.repeater-counter').text(plays);
}
}, <?php echo (int)$video->length*1000; ?>);
});
$(document).ready(function() {
var audioElement = document.getElementById('audio');
//audioElement.setAttribute('autoplay', 'autoplay');
//audioElement.setAttribute('loop', 'true');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
audioElement.volume=1;
}, true);
$('.quarter').click(function() {
audioElement.volume=0.33;
$('.quarter').hide();
$('.half').show();
});
$('.half').click(function() {
audioElement.volume=0.66;
$('.half').hide();
$('.full').show();
});
$('.full').click(function() {
audioElement.volume=1;
$('.full').hide();
$('.quarter').show();
});
$('.play').click(function() {
$('.pause').show();
$('.play').hide();
audioElement.play();
});
$('.pause').click(function() {
$('.play').show();
$('.pause').hide();
audioElement.pause();
});
console.log(audioElement);
});
</script>
<?php else: ?>
<div class="form">
<form method="GET">
<input type="text" name="v" placeholder="Enter video ID (eg. MmpAXq7sq8s)" />
<br />
<input type="submit" value="Enjoy ;)" />
</form>
<p>Or try this <a href="index.php?v=jofNR_WkoCE">demo</a>. Enjoy</p>
</div>
<?php endif; ?>
<div class="form">
<a href="https://twitter.com/share" class="twitter-share-button" data-via="Benftwc" data-size="large" data-hashtags="ListenAndRain">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<a href="https://twitter.com/Benftwc" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @Benftwc</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
</div>
<?php require_once('ga-tracking.php'); ?>
</body>
</html>