-
Notifications
You must be signed in to change notification settings - Fork 0
/
StreamingAPP.py
executable file
·85 lines (66 loc) · 2.53 KB
/
StreamingAPP.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author Lander Usategui San Juan, [email protected], creado para Open Gasteiz
import pygtk
pygtk.require('2.0')
import gtk
import urllib2
import os
class Application():
def __init__(self):
self.window = gtk.Window()
self.window.set_title("Open Gasteiz")
self.create_widgets()
self.connect_signals()
self.window.show_all()
gtk.main()
def create_widgets(self):
self.vbox = gtk.VBox(spacing=10)
self.hbox_1 = gtk.HBox(spacing=10)
self.label = gtk.Label("URL Youtube:")
self.hbox_1.pack_start(self.label)
self.entry = gtk.Entry()
self.hbox_1.pack_start(self.entry)
self.hbox_2 = gtk.HBox(spacing=10)
self.button_ok = gtk.Button("OK")
self.hbox_2.pack_start(self.button_ok)
self.button_exit = gtk.Button("Exit")
self.hbox_2.pack_start(self.button_exit)
self.vbox.pack_start(self.hbox_1)
self.vbox.pack_start(self.hbox_2)
self.window.add(self.vbox)
def connect_signals(self):
self.button_ok.connect("clicked", self.callback_ok)
self.button_exit.connect("clicked", self.callback_exit)
def error_dialog(self,mensaje):
dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,"%s" %(mensaje))
dialog.run()
dialog.destroy()
def callback_ok(self, widget, callback_data=None):
youtubeURL = self.entry.get_text()
if len(youtubeURL) != 0:
if check_internet():
#Comenzamos el streaming
caputureVideo(youtubeURL)
else:
no_internet="Compruebe su acceso a internet"
self.error_dialog(no_internet)
else:
bad_URL = "La URL no puede estar vacía"
#print(bad_URL)
self.error_dialog(bad_URL)
gtk.main_quit()
def callback_exit(self, widget, callback_data=None):
gtk.main_quit()
def check_internet():
# http://stackoverflow.com/questions/3764291/checking-network-connection
try:
urllib2.urlopen('http://216.58.192.142', timeout=1)
return True
except urllib2.URLError as err:
return False
def caputureVideo(url):
os.system("raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | avconv -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv %s
" % (url))
if __name__ == "__main__":
app = Application()