Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
d0nd3r3k committed Mar 22, 2014
1 parent 0bae66f commit 7913555
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 142 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#Install

Must have Node.js installed on the Raspberry Pi. To install Node follow this [link](https://github.com/DonaldDerek/rPi-cheat-sheet)

```
git clone https://github.com/DonaldDerek/RaspberryPiTV.git
cd RaspberyPiTV/
npm install
npm start
```


#RaspberryPi TV
---------------
This project was born during a workshop given at [Lamba Labs - Beirut Hacker Space](http://lambalabs.org/) and it was announced during the [Google IO Extend Beirut 2013 Event](https://plus.google.com/u/0/events/cp2togh80nq76q6p301ed3vkodo) Organized by [GDG-Beirut](https://plus.google.com/u/0/102062106640051908932)
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ app.get('/play/:video_id', function (req, res) {
io.set('log level', 1);

server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
console.log('Pirate TV is running on port ' + app.get('port'));
});

var ss;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GoogleTV-rPi",
"version": "0.0.1",
"name": "PiRTV",
"version": "0.0.2",
"private": false,
"scripts": {
"start": "node app.js"
Expand Down
43 changes: 3 additions & 40 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<meta charset="utf-8">
<title>rPiTV - Lamba Labs Workshop</title>
<title>PiRTV</title>

<link href="css/style.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
Expand All @@ -10,7 +10,7 @@
<div id="loader" class="status fadeInDown animated hidden">Y</div>
<div class="logo"></div>
<div class="logo-txt">
<h2>rPiTV</h2>
<h2>PiRTV</h2>
</div>
<div class="time-block">
<div id="time" ></div>
Expand Down Expand Up @@ -44,44 +44,7 @@ <h2>rPiTV</h2>
<script src="js/jquery-2.0.1.min.js"></script>
<script src="js/mustache.js" type="text/javascript"></script>
<script src="js/main.js" type="text/javascript"></script>
<script>
var socket = io.connect('http://192.168.0.102:8080');
//var socket = io.connect('http://raspberrypi.local:8080');
socket.on('connect', function(data){
socket.emit('screen');
});

socket.on('controlling', function(data){
var current = $(".selected");

if(data.action === "goLeft"){

$(".selected").removeClass("selected");

if($(current).prev().attr("id") === "start-block"){
$("#end-block").prev().addClass("selected");
} else{
$(current).prev().addClass("selected");
}

}
else if(data.action === "goRight"){

$(".selected").removeClass("selected");

if($(current).next().attr("id") === "end-block"){
$("#start-block").next().addClass("selected");
} else{
$(current).next().addClass("selected");
}

}
else if(data.action === "enter"){

}
})

</script>
<script src="js/display.js" type="text/javascript"></script>
<script id="weatherTpl" type="text/template">
<li>
<p class="icon">{{icon}}</p>
Expand Down
35 changes: 35 additions & 0 deletions public/js/display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var host = document.location.origin;
var socket = io.connect(host);
socket.on('connect', function(data){
socket.emit('screen');
});

socket.on('controlling', function(data){
var current = $(".selected");

if(data.action === "goLeft"){

$(".selected").removeClass("selected");

if($(current).prev().attr("id") === "start-block"){
$("#end-block").prev().addClass("selected");
} else{
$(current).prev().addClass("selected");
}

}
else if(data.action === "goRight"){

$(".selected").removeClass("selected");

if($(current).next().attr("id") === "end-block"){
$("#start-block").next().addClass("selected");
} else{
$(current).next().addClass("selected");
}

}
else if(data.action === "enter"){

}
})
75 changes: 75 additions & 0 deletions public/js/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var host = document.location.origin;
var socket = io.connect(host);
socket.on('connect', function(data){
socket.emit('remote');

//Youtube
var Youtube = {
getVideo: function(query, socket){
var max_videos = 12;
var url = "http://gdata.youtube.com/feeds/api/videos?vq=" + escape(query) + "&max-results=" + max_videos + "&alt=json-in-script&callback=?";

$.getJSON(url, function(data){
$("ul.video").html("");
var jsonObj = [];
$(data.feed.entry).each(function(key, item){
var a = item.id.$t.split("/"),
id = a[6],
title = item.title.$t,
thumbnail = item.media$group.media$thumbnail[0].url,
totalSec = item.media$group.yt$duration.seconds,
hours = parseInt( totalSec / 3600 ) % 24,
minutes = parseInt( totalSec / 60 ) % 60,
seconds = totalSec % 60;

var duration = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);


jsonObj = {
id:id,
title:title,
thumbnail:thumbnail,
duration:duration};


var template = $('#videoTpl').html(),
html = Mustache.to_html(template, jsonObj);
$('ul.video').append(html);

});
$(".watch").on("click",function(){
var video_id = $(this).data('id');
socket.emit('video',{action:"play", video_id:video_id});
});
});

}
}

$$(".r-container").swipeLeft(function(){
socket.emit('controll',{action:"swipeLeft"});
});

$$(".r-container").swipeRight(function(){
socket.emit('controll',{action:"swipeRight"});
});
$$(".r-header").tap(function(){
socket.emit('controll',{action:"tap"});
$(".app-body").fadeToggle("fast", function () {});
$.get(host+'/omx/quit',function(data){
console.log(data);
});
});
$$(".app-body").tap(function(){
$.get(host+'/omx/pause',function(data){
console.log(data);
});
});
$(".search input").change(function() {
Youtube.getVideo($(this).val(), socket);
});

socket.on("loading", function(data){
console.log(data);
})
});
86 changes: 3 additions & 83 deletions public/remote.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<meta charset="utf-8">
<title>rPiTV - Remote</title>
<title>PiRTV</title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="css/flat-ui.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
Expand All @@ -17,7 +17,7 @@
<body>
<div class="r-container ">
<div class="r-header">
<h2>rPiTV Remote</h2>
<h2>Pirate Remote</h2>
</div>
<div class="r-logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 570 720"><script/>
Expand Down Expand Up @@ -53,87 +53,7 @@ <h2>rPiTV Remote</h2>
<script src="js/jquery.flexslider.js"></script>
<script src="js/quo.js"></script>
<script src="js/mustache.js"></script>

<script>

var socket = io.connect('http://192.168.0.102:8080');
//var socket = io.connect('http://raspberrypi.local:8080/');
socket.on('connect', function(data){
socket.emit('remote');

//Youtube
var Youtube = {
getVideo: function(query, socket){
var max_videos = 12;
var url = "http://gdata.youtube.com/feeds/api/videos?vq=" + escape(query) + "&max-results=" + max_videos + "&alt=json-in-script&callback=?";

$.getJSON(url, function(data){
$("ul.video").html("");
var jsonObj = [];
$(data.feed.entry).each(function(key, item){
var a = item.id.$t.split("/"),
id = a[6],
title = item.title.$t,
thumbnail = item.media$group.media$thumbnail[0].url,
totalSec = item.media$group.yt$duration.seconds,
hours = parseInt( totalSec / 3600 ) % 24,
minutes = parseInt( totalSec / 60 ) % 60,
seconds = totalSec % 60;

var duration = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);


jsonObj = {
id:id,
title:title,
thumbnail:thumbnail,
duration:duration};


var template = $('#videoTpl').html(),
html = Mustache.to_html(template, jsonObj);
$('ul.video').append(html);

});
$(".watch").on("click",function(){
var video_id = $(this).data('id');
socket.emit('video',{action:"play", video_id:video_id});
});
});

}
}

$$(".r-container").swipeLeft(function(){
socket.emit('controll',{action:"swipeLeft"});
});

$$(".r-container").swipeRight(function(){
socket.emit('controll',{action:"swipeRight"});
});
$$(".r-header").tap(function(){
socket.emit('controll',{action:"tap"});
$(".app-body").fadeToggle("fast", function () {});
$.get('http://192.168.0.102:8080/omx/quit',function(data){
console.log(data);
});
});
$$(".app-body").tap(function(){
$.get('http://192.168.0.102:8080/omx/pause',function(data){
console.log(data);
});
});
$(".search input").change(function() {
Youtube.getVideo($(this).val(), socket);
});

socket.on("loading", function(data){
console.log(data);
})
});

</script>

<script src="js/remote.js" type="text/javascript"></script>
<script id="videoTpl" type="text/template">
<li class="block">
<div class="tile">
Expand Down
8 changes: 0 additions & 8 deletions routes/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions routes/user.js

This file was deleted.

0 comments on commit 7913555

Please sign in to comment.