From f6b69d57688f2cfd601fe3b6305e1d17c3719f70 Mon Sep 17 00:00:00 2001 From: "G. Pellerin" Date: Sat, 28 May 2011 23:43:42 +0200 Subject: [PATCH] first pass for django migration --- {css => htdocs/css}/telecaster.css | 0 {img => htdocs/images}/accept.png | Bin {img => htdocs/images}/arrow_refresh.png | Bin {img => htdocs/images}/bin.png | Bin {img => htdocs/images}/cancel.png | Bin {img => htdocs/images}/control_pause_blue.png | Bin {img => htdocs/images}/control_play_blue.png | Bin {img => htdocs/images}/control_stop.png | Bin {img => htdocs/images}/control_stop_blue.png | Bin .../apps/preferences-desktop-rotate.png | Bin .../16x16/apps/preferences-desktop-rotate.png | Bin .../22x22/apps/preferences-desktop-rotate.png | Bin .../32x32/apps/preferences-desktop-rotate.png | Bin .../48x48/apps/preferences-desktop-rotate.png | Bin .../64x64/apps/preferences-desktop-rotate.png | Bin .../8x8/apps/preferences-desktop-rotate.png | Bin {img => htdocs/images}/drive_add.png | Bin {img => htdocs/images}/drive_burn.png | Bin {img => htdocs/images}/drive_delete.png | Bin {img => htdocs/images}/drive_error.png | Bin {img => htdocs/images}/folder_go.png | Bin {img => htdocs/images}/folder_link.png | Bin {img => htdocs/images}/ipod_cast.png | Bin {img => htdocs/images}/logo_telecaster_wh.png | Bin {img => htdocs/images}/rotate_desktop.desktop | 0 {img => htdocs/images}/stop.png | Bin {img => htdocs/images}/tick.png | Bin {img => htdocs/images}/transmit.png | Bin {img => htdocs/images}/transmit_add.png | Bin {img => htdocs/images}/transmit_blue.png | Bin {img => htdocs/images}/transmit_delete.png | Bin {img => htdocs/images}/transmit_edit.png | Bin {img => htdocs/images}/transmit_error.png | Bin {img => htdocs/images}/transmit_go.png | Bin {img => htdocs/images}/tux.png | Bin models.py | 193 +++++++++++++++++- telecaster.py | 38 ++-- templates/telecaster/base.html | 81 ++++++++ templates/telecaster/start.html | 32 +++ templates/telecaster/stop.html | 28 +++ tools/{ => scripts}/ffmpeg_dv_jack_fifo_fw | 0 tools/{ => scripts}/ffmpeg_dv_jack_fifo_usb | 0 .../{ => scripts}/ffmpeg_dv_jack_fifo_usb_gst | 0 urls.py | 76 +++++++ {tools => vendor}/edcast-jack/Makefile.am | 0 {tools => vendor}/edcast-jack/Makefile.in | 0 {tools => vendor}/edcast-jack/aclocal.m4 | 0 {tools => vendor}/edcast-jack/conf/sample.cfg | 0 {tools => vendor}/edcast-jack/config.guess | 0 {tools => vendor}/edcast-jack/config.sub | 0 {tools => vendor}/edcast-jack/configure | 0 {tools => vendor}/edcast-jack/configure.in | 0 {tools => vendor}/edcast-jack/depcomp | 0 {tools => vendor}/edcast-jack/edcast.cpp | 0 {tools => vendor}/edcast-jack/install-sh | 0 .../edcast-jack/libedcast/Makefile | 0 .../edcast-jack/libedcast/Makefile.am | 0 .../edcast-jack/libedcast/Makefile.in | 0 .../edcast-jack/libedcast/Socket.cpp | 0 .../edcast-jack/libedcast/cbuffer.c | 0 .../edcast-jack/libedcast/cbuffer.h | 0 .../edcast-jack/libedcast/enc_if.h | 0 .../edcast-jack/libedcast/libedcast.cpp | 0 .../edcast-jack/libedcast/libedcast.dsp | 0 .../edcast-jack/libedcast/libedcast.h | 0 .../libedcast/libedcast_resample.h | 0 .../edcast-jack/libedcast/libedcast_socket.h | 0 .../edcast-jack/libedcast/resample.c | 0 {tools => vendor}/edcast-jack/ltmain.sh | 0 {tools => vendor}/edcast-jack/m4/lame.m4 | 0 {tools => vendor}/edcast-jack/m4/mad.m4 | 0 {tools => vendor}/edcast-jack/m4/ogg.m4 | 0 {tools => vendor}/edcast-jack/m4/vorbis.m4 | 0 {tools => vendor}/edcast-jack/missing | 0 views.py | 107 ++++++++++ webview.py | 2 +- 76 files changed, 535 insertions(+), 22 deletions(-) rename {css => htdocs/css}/telecaster.css (100%) rename {img => htdocs/images}/accept.png (100%) rename {img => htdocs/images}/arrow_refresh.png (100%) rename {img => htdocs/images}/bin.png (100%) rename {img => htdocs/images}/cancel.png (100%) rename {img => htdocs/images}/control_pause_blue.png (100%) rename {img => htdocs/images}/control_play_blue.png (100%) rename {img => htdocs/images}/control_stop.png (100%) rename {img => htdocs/images}/control_stop_blue.png (100%) rename {img => htdocs/images}/desktop/128x128/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/desktop/16x16/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/desktop/22x22/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/desktop/32x32/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/desktop/48x48/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/desktop/64x64/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/desktop/8x8/apps/preferences-desktop-rotate.png (100%) rename {img => htdocs/images}/drive_add.png (100%) rename {img => htdocs/images}/drive_burn.png (100%) rename {img => htdocs/images}/drive_delete.png (100%) rename {img => htdocs/images}/drive_error.png (100%) rename {img => htdocs/images}/folder_go.png (100%) rename {img => htdocs/images}/folder_link.png (100%) rename {img => htdocs/images}/ipod_cast.png (100%) rename {img => htdocs/images}/logo_telecaster_wh.png (100%) rename {img => htdocs/images}/rotate_desktop.desktop (100%) rename {img => htdocs/images}/stop.png (100%) rename {img => htdocs/images}/tick.png (100%) rename {img => htdocs/images}/transmit.png (100%) rename {img => htdocs/images}/transmit_add.png (100%) rename {img => htdocs/images}/transmit_blue.png (100%) rename {img => htdocs/images}/transmit_delete.png (100%) rename {img => htdocs/images}/transmit_edit.png (100%) rename {img => htdocs/images}/transmit_error.png (100%) rename {img => htdocs/images}/transmit_go.png (100%) rename {img => htdocs/images}/tux.png (100%) create mode 100644 templates/telecaster/base.html create mode 100644 templates/telecaster/start.html create mode 100644 templates/telecaster/stop.html rename tools/{ => scripts}/ffmpeg_dv_jack_fifo_fw (100%) rename tools/{ => scripts}/ffmpeg_dv_jack_fifo_usb (100%) rename tools/{ => scripts}/ffmpeg_dv_jack_fifo_usb_gst (100%) create mode 100644 urls.py rename {tools => vendor}/edcast-jack/Makefile.am (100%) rename {tools => vendor}/edcast-jack/Makefile.in (100%) rename {tools => vendor}/edcast-jack/aclocal.m4 (100%) rename {tools => vendor}/edcast-jack/conf/sample.cfg (100%) rename {tools => vendor}/edcast-jack/config.guess (100%) rename {tools => vendor}/edcast-jack/config.sub (100%) rename {tools => vendor}/edcast-jack/configure (100%) rename {tools => vendor}/edcast-jack/configure.in (100%) rename {tools => vendor}/edcast-jack/depcomp (100%) rename {tools => vendor}/edcast-jack/edcast.cpp (100%) rename {tools => vendor}/edcast-jack/install-sh (100%) rename {tools => vendor}/edcast-jack/libedcast/Makefile (100%) rename {tools => vendor}/edcast-jack/libedcast/Makefile.am (100%) rename {tools => vendor}/edcast-jack/libedcast/Makefile.in (100%) rename {tools => vendor}/edcast-jack/libedcast/Socket.cpp (100%) rename {tools => vendor}/edcast-jack/libedcast/cbuffer.c (100%) rename {tools => vendor}/edcast-jack/libedcast/cbuffer.h (100%) rename {tools => vendor}/edcast-jack/libedcast/enc_if.h (100%) rename {tools => vendor}/edcast-jack/libedcast/libedcast.cpp (100%) rename {tools => vendor}/edcast-jack/libedcast/libedcast.dsp (100%) rename {tools => vendor}/edcast-jack/libedcast/libedcast.h (100%) rename {tools => vendor}/edcast-jack/libedcast/libedcast_resample.h (100%) rename {tools => vendor}/edcast-jack/libedcast/libedcast_socket.h (100%) rename {tools => vendor}/edcast-jack/libedcast/resample.c (100%) rename {tools => vendor}/edcast-jack/ltmain.sh (100%) rename {tools => vendor}/edcast-jack/m4/lame.m4 (100%) rename {tools => vendor}/edcast-jack/m4/mad.m4 (100%) rename {tools => vendor}/edcast-jack/m4/ogg.m4 (100%) rename {tools => vendor}/edcast-jack/m4/vorbis.m4 (100%) rename {tools => vendor}/edcast-jack/missing (100%) diff --git a/css/telecaster.css b/htdocs/css/telecaster.css similarity index 100% rename from css/telecaster.css rename to htdocs/css/telecaster.css diff --git a/img/accept.png b/htdocs/images/accept.png similarity index 100% rename from img/accept.png rename to htdocs/images/accept.png diff --git a/img/arrow_refresh.png b/htdocs/images/arrow_refresh.png similarity index 100% rename from img/arrow_refresh.png rename to htdocs/images/arrow_refresh.png diff --git a/img/bin.png b/htdocs/images/bin.png similarity index 100% rename from img/bin.png rename to htdocs/images/bin.png diff --git a/img/cancel.png b/htdocs/images/cancel.png similarity index 100% rename from img/cancel.png rename to htdocs/images/cancel.png diff --git a/img/control_pause_blue.png b/htdocs/images/control_pause_blue.png similarity index 100% rename from img/control_pause_blue.png rename to htdocs/images/control_pause_blue.png diff --git a/img/control_play_blue.png b/htdocs/images/control_play_blue.png similarity index 100% rename from img/control_play_blue.png rename to htdocs/images/control_play_blue.png diff --git a/img/control_stop.png b/htdocs/images/control_stop.png similarity index 100% rename from img/control_stop.png rename to htdocs/images/control_stop.png diff --git a/img/control_stop_blue.png b/htdocs/images/control_stop_blue.png similarity index 100% rename from img/control_stop_blue.png rename to htdocs/images/control_stop_blue.png diff --git a/img/desktop/128x128/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/128x128/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/128x128/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/128x128/apps/preferences-desktop-rotate.png diff --git a/img/desktop/16x16/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/16x16/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/16x16/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/16x16/apps/preferences-desktop-rotate.png diff --git a/img/desktop/22x22/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/22x22/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/22x22/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/22x22/apps/preferences-desktop-rotate.png diff --git a/img/desktop/32x32/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/32x32/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/32x32/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/32x32/apps/preferences-desktop-rotate.png diff --git a/img/desktop/48x48/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/48x48/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/48x48/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/48x48/apps/preferences-desktop-rotate.png diff --git a/img/desktop/64x64/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/64x64/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/64x64/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/64x64/apps/preferences-desktop-rotate.png diff --git a/img/desktop/8x8/apps/preferences-desktop-rotate.png b/htdocs/images/desktop/8x8/apps/preferences-desktop-rotate.png similarity index 100% rename from img/desktop/8x8/apps/preferences-desktop-rotate.png rename to htdocs/images/desktop/8x8/apps/preferences-desktop-rotate.png diff --git a/img/drive_add.png b/htdocs/images/drive_add.png similarity index 100% rename from img/drive_add.png rename to htdocs/images/drive_add.png diff --git a/img/drive_burn.png b/htdocs/images/drive_burn.png similarity index 100% rename from img/drive_burn.png rename to htdocs/images/drive_burn.png diff --git a/img/drive_delete.png b/htdocs/images/drive_delete.png similarity index 100% rename from img/drive_delete.png rename to htdocs/images/drive_delete.png diff --git a/img/drive_error.png b/htdocs/images/drive_error.png similarity index 100% rename from img/drive_error.png rename to htdocs/images/drive_error.png diff --git a/img/folder_go.png b/htdocs/images/folder_go.png similarity index 100% rename from img/folder_go.png rename to htdocs/images/folder_go.png diff --git a/img/folder_link.png b/htdocs/images/folder_link.png similarity index 100% rename from img/folder_link.png rename to htdocs/images/folder_link.png diff --git a/img/ipod_cast.png b/htdocs/images/ipod_cast.png similarity index 100% rename from img/ipod_cast.png rename to htdocs/images/ipod_cast.png diff --git a/img/logo_telecaster_wh.png b/htdocs/images/logo_telecaster_wh.png similarity index 100% rename from img/logo_telecaster_wh.png rename to htdocs/images/logo_telecaster_wh.png diff --git a/img/rotate_desktop.desktop b/htdocs/images/rotate_desktop.desktop similarity index 100% rename from img/rotate_desktop.desktop rename to htdocs/images/rotate_desktop.desktop diff --git a/img/stop.png b/htdocs/images/stop.png similarity index 100% rename from img/stop.png rename to htdocs/images/stop.png diff --git a/img/tick.png b/htdocs/images/tick.png similarity index 100% rename from img/tick.png rename to htdocs/images/tick.png diff --git a/img/transmit.png b/htdocs/images/transmit.png similarity index 100% rename from img/transmit.png rename to htdocs/images/transmit.png diff --git a/img/transmit_add.png b/htdocs/images/transmit_add.png similarity index 100% rename from img/transmit_add.png rename to htdocs/images/transmit_add.png diff --git a/img/transmit_blue.png b/htdocs/images/transmit_blue.png similarity index 100% rename from img/transmit_blue.png rename to htdocs/images/transmit_blue.png diff --git a/img/transmit_delete.png b/htdocs/images/transmit_delete.png similarity index 100% rename from img/transmit_delete.png rename to htdocs/images/transmit_delete.png diff --git a/img/transmit_edit.png b/htdocs/images/transmit_edit.png similarity index 100% rename from img/transmit_edit.png rename to htdocs/images/transmit_edit.png diff --git a/img/transmit_error.png b/htdocs/images/transmit_error.png similarity index 100% rename from img/transmit_error.png rename to htdocs/images/transmit_error.png diff --git a/img/transmit_go.png b/htdocs/images/transmit_go.png similarity index 100% rename from img/transmit_go.png rename to htdocs/images/transmit_go.png diff --git a/img/tux.png b/htdocs/images/tux.png similarity index 100% rename from img/tux.png rename to htdocs/images/tux.png diff --git a/models.py b/models.py index a77edc6..5e8a592 100644 --- a/models.py +++ b/models.py @@ -34,15 +34,32 @@ # Author: Guillaume Pellerin """ +import os +import pwd +import datetime +import time +import urllib +import liblo + +from tools import * + +from mutagen.oggvorbis import OggVorbis +from mutagen.id3 import ID3, TIT2, TP1, TAL, TDA, TDAT, TDRC, TCO, COM + from django.db.models import * +from django.forms import ModelForm app_label = 'telecaster' + class Organization(Model): name = CharField(_('name')) description = CharField(_('description')) + def __str__(self): + return self.name + class Meta: db_table = app_label + '_' + 'organization' @@ -51,6 +68,9 @@ class Department(Model): name = CharField(_('name')) description = CharField(_('description')) + def __str__(self): + return self.name + class Meta: db_table = app_label + '_' + 'department' @@ -60,7 +80,10 @@ class Conference(Model): title = CharField(_('title')) description = CharField(_('description')) department = Foreignkey('Department', related_name='conferences', verbose_name='department') - + + def __str__(self): + return self.title + class Meta: db_table = app_label + '_' + 'conference' @@ -70,7 +93,10 @@ class Session(Model): name = CharField(_('name')) description = CharField(_('description')) number = IntegerField(_('number')) - + + def __str__(self): + return self.name + class Meta: db_table = app_label + '_' + 'session' @@ -83,6 +109,9 @@ class Professor(Model): telephone = CharField(_('telephone')) email = CharField(_('email')) + def __str__(self): + return self.name + class Meta: db_table = app_label + '_' + 'professor' @@ -101,4 +130,164 @@ class Station(Model): class Meta: db_table = app_label + '_' + 'station' + def set_conf(self, conf): + self.conf = conf + def setup(self): + self.date = datetime.datetime.now().strftime("%Y") + self.time = datetime.datetime.now().strftime("%x-%X") + self.time_txt = self.time.replace('/','_').replace(':','_').replace(' ','_') + self.conf = conf + + self.conf = self.conf['telecaster'] + self.user = pwd.getpwuid(os.getuid())[0] + self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' + self.rec_dir = self.conf['media']['rec_dir'] + self.deefuzzer_default_conf_file = self.conf['deefuzzer']['conf'] + self.deefuzzer_user_file = self.user_dir + os.sep + 'deefuzzer.xml' + self.bitrate = self.conf['media']['bitrate'] + self.dict['Bitrate'] = str(self.bitrate) + ' kbps' + self.record = str_to_bool(self.conf['media']['record']) + self.rec_dir = self.conf['media']['rec_dir'] + self.play_dir = self.conf['media']['play_dir'] + self.ogg_quality = self.conf['media']['ogg_quality'] + self.format = self.conf['media']['format'] + self.channels = int(self.conf['media']['channels']) + self.description = [self.title, self.department, self.conference, self.session, self.professor, self.comment] + self.server_name = [self.title, self.department, self.conference] + self.ServerDescription = clean_string('-'.join(self.description)) + self.ServerName = clean_string('_-_'.join(self.server_name)) + self.mount_point = self.ServerName + self.filename = clean_string('_-_'.join(self.description[1:])) + '-' + self.time_txt + '.' + self.format + self.output_dir = self.rec_dir + os.sep + self.date + os.sep + self.department + self.file_dir = self.output_dir + os.sep + self.ServerName + self.uid = os.getuid() + self.odd_pid = get_pid('^edcast_jack', self.uid) + self.deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.deefuzzer_user_file, self.uid) + self.new_title = clean_string('-'.join(self.server_name)+'-'+self.session+'-'+self.professor+'-'+self.comment) + self.short_title = clean_string('-'.join(self.conference)+'-'+self.session+'-'+self.professor+'-'+self.comment) + self.genre = self.conf['infos']['genre'] + self.encoder = 'TeleCaster by Parisson' + + if not os.path.exists(self.file_dir): + os.makedirs(self.file_dir) + + self.jack_inputs = [] + if 'jack' in self.conf: + jack_inputs = self.conf['jack']['input'] + if len(jack_inputs) > 1: + for jack_input in jack_inputs: + self.jack_inputs.append(jack_input['name']) + else: + self.jack_inputs.append(jack_inputs['name']) + + self.deefuzzer_dict = xml2dict(self.deefuzzer_default_conf_file) + self.deefuzzer_osc_ports = [] + self.server_ports = [] + + for station in self.deefuzzer_dict['deefuzzer']['station']: + if station['control']['mode'] == '1': + self.deefuzzer_osc_ports.append(station['control']['port']) + self.server_ports.append(station['server']['port']) + if station['server']['host'] == 'localhost' or station['server']['host'] == '127.0.0.1': + self.conf['play_port'] = station['server']['port'] + else: + self.conf['play_port'] = '8000' + + def deefuzzer_setup(self): + i = 0 + for station in self.deefuzzer_dict['deefuzzer']['station']: + station['infos']['short_name'] = self.mount_point + station['infos']['name'] = self.ServerName + station['infos']['description'] = self.ServerDescription.replace(' ','_') + station['infos']['genre'] = self.genre + station['media']['bitrate'] = self.bitrate + station['media']['dir'] = self.play_dir + station['media']['voices'] = str(len(self.jack_inputs)) + station['record']['dir'] = self.file_dir + station['relay']['mode'] = '1' + station['relay']['author'] = self.professor + self.deefuzzer_dict['deefuzzer']['station'][i] = station + i += 1 + self.deefuzzer_xml = dicttoxml(self.deefuzzer_dict) + + def deefuzzer_write_conf(self): + conf_file = open(self.deefuzzer_user_file,'w') + conf_file.write(self.deefuzzer_xml) + conf_file.close() + + def deefuzzer_start(self): + command = 'deefuzzer ' + self.deefuzzer_user_file + ' > /dev/null &' + os.system(command) + self.set_lock() + + def set_lock(self): + lock = open(self.lock_file,'w') + lock_text = clean_string('_*_'.join(self.description)) + lock_text = lock_text.replace('\n','') + lock.write(lock_text) + lock.close() + + def del_lock(self): + os.remove(self.lock_file) + + def deefuzzer_stop(self): + if len(self.deefuzzer_pid) != 0: + os.system('kill -9 '+self.deefuzzer_pid[0]) + + def rec_stop(self): + if len(self.deefuzzer_pid) != 0: + for port in self.deefuzzer_osc_ports: + target = liblo.Address(int(port)) + liblo.send(target, '/record', 0) + + def mp3_convert(self): + os.system('oggdec -o - '+ self.file_dir+os.sep+self.filename+' | lame -S -m m -h -b '+ self.bitrate + \ + ' --add-id3v2 --tt "'+ self.new_title + '" --ta "'+self.professor+'" --tl "'+self.title+'" --ty "'+self.date+ \ + '" --tg "'+self.genre+'" - ' + self.file_dir+os.sep+self.ServerDescription + '.mp3 &') + + def write_tags_ogg(self): + file = self.file_dir + os.sep + self.filename + if os.path.exists(file): + audio = OggVorbis(file) + audio['TITLE'] = self.new_title.decode('utf8') + audio['ARTIST'] = self.professor.decode('utf8') + audio['ALBUM'] = self.title.decode('utf8') + audio['DATE'] = self.date.decode('utf8') + audio['GENRE'] = self.genre.decode('utf8') + audio['SOURCE'] = self.title.decode('utf8') + audio['ENCODER'] = self.encoder.decode('utf8') + audio['COMMENT'] = self.comment.decode('utf8') + audio.save() + + def write_tags_mp3(self): + file = self.file_dir + os.sep + self.filename + if os.path.exists(file): + os.system('mp3info -t "a" -a "a" '+file) + audio = ID3(file) + #tag = tags.__dict__['TITLE'] + audio.add(TIT2(encoding=3, text=self.new_title.decode('utf8'))) + #tag = tags.__dict__['ARTIST'] + audio.add(TP1(encoding=3, text=self.professor.decode('utf8'))) + #tag = tags.__dict__['ALBUM'] + audio.add(TAL(encoding=3, text=self.title.decode('utf8'))) + #tag = tags.__dict__['DATE'] + audio.add(TDRC(encoding=3, text=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) + #tag = tags.__dict__['GENRE'] + audio.add(TCO(encoding=3, text=self.genre.decode('utf8'))) + #tag = tags.__dict__['COMMENT'] + #audio.add(COM(encoding=3, text=self.comment)) + audio.save() + + def start(self): + self.set_lock() + self.deefuzzer_setup() + self.deefuzzer_write_conf() + self.deefuzzer_start() + + def stop(self): + self.rec_stop() + time.sleep(2) + self.deefuzzer_stop() + self.del_lock() + diff --git a/telecaster.py b/telecaster.py index b68a15c..5cefb0a 100755 --- a/telecaster.py +++ b/telecaster.py @@ -92,7 +92,7 @@ class TeleCaster: if deefuzzer_pid == [] and form.has_key("action") and \ form.has_key("department") and form.has_key("conference") and \ form.has_key("session") and form["action"].value == "start": - + self.conference_dict = {'title': '', 'department': '', 'conference': '', @@ -100,17 +100,17 @@ class TeleCaster: 'professor': '', 'comment': ''} - for data in self.conference_dict: - if not form.has_key(data): - self.conference_dict[data] = 'Inconnu' - else: - value = form.getfirst(data) - if '....' in value: - self.conference_dict[data] = 'Inconnu' - else: - self.conference_dict[data] = value - - self.conference_dict['title'] = self.title + for data in self.conference_dict: + if not form.has_key(data): + self.conference_dict[data] = 'Inconnu' + else: + value = form.getfirst(data) + if '....' in value: + self.conference_dict[data] = 'Inconnu' + else: + self.conference_dict[data] = value + + self.conference_dict['title'] = self.title s = Station(self.conf_file, self.conference_dict, self.lock_file) s.start() time.sleep(2) @@ -123,21 +123,21 @@ class TeleCaster: self.logger.write_info('started') elif deefuzzer_pid and form.has_key("action") and form["action"].value == "stop": - self.logger.write_info('stopping') + self.logger.write_info('stopping') if os.path.exists(self.lock_file): self.conference_dict = get_conference_from_lock(self.lock_file) - s = Station(self.conf_file, self.conference_dict, self.lock_file) + s = Station(self.conf_file, self.conference_dict, self.lock_file) s.stop() - time.sleep(2) - self.main() + time.sleep(2) + self.main() elif deefuzzer_pid == []: form.start_form(writing, casting) self.logger.write_info('stopped') - elif deefuzzer_pid != []: - os.system('kill -9 '+deefuzzer_pid[0]) - self.main() + elif deefuzzer_pid != []: + os.system('kill -9 '+deefuzzer_pid[0]) + self.main() conf_file = '/etc/telecaster/telecaster.xml' diff --git a/templates/telecaster/base.html b/templates/telecaster/base.html new file mode 100644 index 0000000..91f1cec --- /dev/null +++ b/templates/telecaster/base.html @@ -0,0 +1,81 @@ + + + +TeleCaster - {{ self.title }} + + + +{% block javascript %} + + + +{% endblock javascript %} + + + +
+
" +logo_telecaster +
 TeleCaster - Audio Web Live Recording
+
+ +{% block hardware %} + +{% if acpi.power_state == 0 %} + + +
+
Status
+ + + + + + + + + + + + + + + + + + + + + + + + +
Name : {{ status.url }}
IP address : {{ status.ip }}
Power : {{ status.power }}
Battery charge : {{ status.batt_charge }}
Temp core 1 : {{ status.temperature }}
JACK audio server : {{ status.jack_state }}
Encoder : {{ status.casting }}
{{ status.writing }}
{{ status.casting }}
+
+
+ +{% block content %} +{% endblock content %} + +{% block footer %} +
TeleCaster "+self.version+" © {% year %} Parisson SARL. Tous droits réservés. +
+ + + + diff --git a/templates/telecaster/start.html b/templates/telecaster/start.html new file mode 100644 index 0000000..5b55647 --- /dev/null +++ b/templates/telecaster/start.html @@ -0,0 +1,32 @@ +{% extends "/telecaster/base.html" %} + +{% block content %} + +
{% csrf_token %} +
+ + + + {% for field in form %} + + + + + + {% endfor %} +
{% for error in form.non_field_errors %}
  • {{ error }}
  • {% endfor %}
    {{ field.errors }}
    {{ field.label_tag }}:{{ field }}
    + +
    +
    + + + Play Live + Archives + Trash +
    +
    + +
    +
    + +{% endblock content %} diff --git a/templates/telecaster/stop.html b/templates/telecaster/stop.html new file mode 100644 index 0000000..116ecf1 --- /dev/null +++ b/templates/telecaster/stop.html @@ -0,0 +1,28 @@ +{% extends "/telecaster/base.html" %} + +{% block content %} + +
    {% csrf_token %} +
    + + + + + + + + +
    Organization : {{ station.organization }}
    Département : {{ station.conference.department }}
    Conference : {{ station.conference }}
    Session : {{ station.session }}
    Professeur : {{ station.professor }}
    Commentaire : {{ station.comment }}
    +
    +
    +
    + +Play + +Archives +Trash +
    +
    +
    + +{% endblock content %} diff --git a/tools/ffmpeg_dv_jack_fifo_fw b/tools/scripts/ffmpeg_dv_jack_fifo_fw similarity index 100% rename from tools/ffmpeg_dv_jack_fifo_fw rename to tools/scripts/ffmpeg_dv_jack_fifo_fw diff --git a/tools/ffmpeg_dv_jack_fifo_usb b/tools/scripts/ffmpeg_dv_jack_fifo_usb similarity index 100% rename from tools/ffmpeg_dv_jack_fifo_usb rename to tools/scripts/ffmpeg_dv_jack_fifo_usb diff --git a/tools/ffmpeg_dv_jack_fifo_usb_gst b/tools/scripts/ffmpeg_dv_jack_fifo_usb_gst similarity index 100% rename from tools/ffmpeg_dv_jack_fifo_usb_gst rename to tools/scripts/ffmpeg_dv_jack_fifo_usb_gst diff --git a/urls.py b/urls.py new file mode 100644 index 0000000..0c22d81 --- /dev/null +++ b/urls.py @@ -0,0 +1,76 @@ +#!/usr/bin/python +# *-* coding: utf-8 *-* +""" + telecaster + + Copyright (c) 2006-2011 Guillaume Pellerin + +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". + +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. + +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. + +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. + +# Author: Guillaume Pellerin +""" + +from django.conf.urls.defaults import * +from telemeta.models import * +from telemeta.views import WebView +from jsonrpc import jsonrpc_site +import os.path + +#import telecaster.config +#telecaster.config.check() + +# initialization +web_view = WebView() + + +htdocs = os.path.dirname(__file__) + '/htdocs' + +urlpatterns = patterns('', + url(r'^$', web_view.index, name="telemeta-home"), + + # items + url(r'^items/$', 'django.views.generic.list_detail.object_list', + dict(all_items, paginate_by=20, template_name="telemeta/mediaitem_list.html"), + name="telemeta-items"), + url(r'^items/(?P[A-Za-z0-9._-]+)/$', web_view.item_detail, + name="telemeta-item-detail"), + url(r'^items/(?P[A-Za-z0-9._-]+)/dc/$', web_view.item_detail, + {'template': 'telemeta/mediaitem_detail_dc.html'}, + name="telemeta-item-dublincore"), + url(r'^items/(?P[A-Za-z0-9._-]+)/dc/xml/$', web_view.item_detail, + {'format': 'dublin_core_xml'}, + + # CSS+Images (FIXME: for developement only) + url(r'^css/(?P.*)$', 'django.views.static.serve', + {'document_root': htdocs+'/css'}, + name="telemeta-css"), + url(r'images/(?P.*)$', 'django.views.static.serve', + {'document_root': htdocs+'/images'}, + name="telemeta-images"), + url(r'^js/(?P.*)$', 'django.views.static.serve', + {'document_root': htdocs+'/js'}, + name="telemeta-js"), diff --git a/tools/edcast-jack/Makefile.am b/vendor/edcast-jack/Makefile.am similarity index 100% rename from tools/edcast-jack/Makefile.am rename to vendor/edcast-jack/Makefile.am diff --git a/tools/edcast-jack/Makefile.in b/vendor/edcast-jack/Makefile.in similarity index 100% rename from tools/edcast-jack/Makefile.in rename to vendor/edcast-jack/Makefile.in diff --git a/tools/edcast-jack/aclocal.m4 b/vendor/edcast-jack/aclocal.m4 similarity index 100% rename from tools/edcast-jack/aclocal.m4 rename to vendor/edcast-jack/aclocal.m4 diff --git a/tools/edcast-jack/conf/sample.cfg b/vendor/edcast-jack/conf/sample.cfg similarity index 100% rename from tools/edcast-jack/conf/sample.cfg rename to vendor/edcast-jack/conf/sample.cfg diff --git a/tools/edcast-jack/config.guess b/vendor/edcast-jack/config.guess similarity index 100% rename from tools/edcast-jack/config.guess rename to vendor/edcast-jack/config.guess diff --git a/tools/edcast-jack/config.sub b/vendor/edcast-jack/config.sub similarity index 100% rename from tools/edcast-jack/config.sub rename to vendor/edcast-jack/config.sub diff --git a/tools/edcast-jack/configure b/vendor/edcast-jack/configure similarity index 100% rename from tools/edcast-jack/configure rename to vendor/edcast-jack/configure diff --git a/tools/edcast-jack/configure.in b/vendor/edcast-jack/configure.in similarity index 100% rename from tools/edcast-jack/configure.in rename to vendor/edcast-jack/configure.in diff --git a/tools/edcast-jack/depcomp b/vendor/edcast-jack/depcomp similarity index 100% rename from tools/edcast-jack/depcomp rename to vendor/edcast-jack/depcomp diff --git a/tools/edcast-jack/edcast.cpp b/vendor/edcast-jack/edcast.cpp similarity index 100% rename from tools/edcast-jack/edcast.cpp rename to vendor/edcast-jack/edcast.cpp diff --git a/tools/edcast-jack/install-sh b/vendor/edcast-jack/install-sh similarity index 100% rename from tools/edcast-jack/install-sh rename to vendor/edcast-jack/install-sh diff --git a/tools/edcast-jack/libedcast/Makefile b/vendor/edcast-jack/libedcast/Makefile similarity index 100% rename from tools/edcast-jack/libedcast/Makefile rename to vendor/edcast-jack/libedcast/Makefile diff --git a/tools/edcast-jack/libedcast/Makefile.am b/vendor/edcast-jack/libedcast/Makefile.am similarity index 100% rename from tools/edcast-jack/libedcast/Makefile.am rename to vendor/edcast-jack/libedcast/Makefile.am diff --git a/tools/edcast-jack/libedcast/Makefile.in b/vendor/edcast-jack/libedcast/Makefile.in similarity index 100% rename from tools/edcast-jack/libedcast/Makefile.in rename to vendor/edcast-jack/libedcast/Makefile.in diff --git a/tools/edcast-jack/libedcast/Socket.cpp b/vendor/edcast-jack/libedcast/Socket.cpp similarity index 100% rename from tools/edcast-jack/libedcast/Socket.cpp rename to vendor/edcast-jack/libedcast/Socket.cpp diff --git a/tools/edcast-jack/libedcast/cbuffer.c b/vendor/edcast-jack/libedcast/cbuffer.c similarity index 100% rename from tools/edcast-jack/libedcast/cbuffer.c rename to vendor/edcast-jack/libedcast/cbuffer.c diff --git a/tools/edcast-jack/libedcast/cbuffer.h b/vendor/edcast-jack/libedcast/cbuffer.h similarity index 100% rename from tools/edcast-jack/libedcast/cbuffer.h rename to vendor/edcast-jack/libedcast/cbuffer.h diff --git a/tools/edcast-jack/libedcast/enc_if.h b/vendor/edcast-jack/libedcast/enc_if.h similarity index 100% rename from tools/edcast-jack/libedcast/enc_if.h rename to vendor/edcast-jack/libedcast/enc_if.h diff --git a/tools/edcast-jack/libedcast/libedcast.cpp b/vendor/edcast-jack/libedcast/libedcast.cpp similarity index 100% rename from tools/edcast-jack/libedcast/libedcast.cpp rename to vendor/edcast-jack/libedcast/libedcast.cpp diff --git a/tools/edcast-jack/libedcast/libedcast.dsp b/vendor/edcast-jack/libedcast/libedcast.dsp similarity index 100% rename from tools/edcast-jack/libedcast/libedcast.dsp rename to vendor/edcast-jack/libedcast/libedcast.dsp diff --git a/tools/edcast-jack/libedcast/libedcast.h b/vendor/edcast-jack/libedcast/libedcast.h similarity index 100% rename from tools/edcast-jack/libedcast/libedcast.h rename to vendor/edcast-jack/libedcast/libedcast.h diff --git a/tools/edcast-jack/libedcast/libedcast_resample.h b/vendor/edcast-jack/libedcast/libedcast_resample.h similarity index 100% rename from tools/edcast-jack/libedcast/libedcast_resample.h rename to vendor/edcast-jack/libedcast/libedcast_resample.h diff --git a/tools/edcast-jack/libedcast/libedcast_socket.h b/vendor/edcast-jack/libedcast/libedcast_socket.h similarity index 100% rename from tools/edcast-jack/libedcast/libedcast_socket.h rename to vendor/edcast-jack/libedcast/libedcast_socket.h diff --git a/tools/edcast-jack/libedcast/resample.c b/vendor/edcast-jack/libedcast/resample.c similarity index 100% rename from tools/edcast-jack/libedcast/resample.c rename to vendor/edcast-jack/libedcast/resample.c diff --git a/tools/edcast-jack/ltmain.sh b/vendor/edcast-jack/ltmain.sh similarity index 100% rename from tools/edcast-jack/ltmain.sh rename to vendor/edcast-jack/ltmain.sh diff --git a/tools/edcast-jack/m4/lame.m4 b/vendor/edcast-jack/m4/lame.m4 similarity index 100% rename from tools/edcast-jack/m4/lame.m4 rename to vendor/edcast-jack/m4/lame.m4 diff --git a/tools/edcast-jack/m4/mad.m4 b/vendor/edcast-jack/m4/mad.m4 similarity index 100% rename from tools/edcast-jack/m4/mad.m4 rename to vendor/edcast-jack/m4/mad.m4 diff --git a/tools/edcast-jack/m4/ogg.m4 b/vendor/edcast-jack/m4/ogg.m4 similarity index 100% rename from tools/edcast-jack/m4/ogg.m4 rename to vendor/edcast-jack/m4/ogg.m4 diff --git a/tools/edcast-jack/m4/vorbis.m4 b/vendor/edcast-jack/m4/vorbis.m4 similarity index 100% rename from tools/edcast-jack/m4/vorbis.m4 rename to vendor/edcast-jack/m4/vorbis.m4 diff --git a/tools/edcast-jack/missing b/vendor/edcast-jack/missing similarity index 100% rename from tools/edcast-jack/missing rename to vendor/edcast-jack/missing diff --git a/views.py b/views.py index 60f00ef..1e2e635 100644 --- a/views.py +++ b/views.py @@ -1 +1,108 @@ # Create your views here. + +import os +import cgi +import datetime +import time +import string + +from tools import * +from models import * +from forms import* + + +def render(request, template, data = None, mimetype = None): + return render_to_response(template, data, context_instance=RequestContext(request), + mimetype=mimetype) + +class WebView(object): + + interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2','eth3'] + acpi_states = {0: 'battery', 1: 'AC', 2: 'AC'} + acpi = acpi.Acpi() + + def __init__(self, conf_file): + self.uid = os.getuid() + self.user = pwd.getpwuid(os.getuid())[0] + self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' + if not os.path.exists(self.user_dir): + os.makedirs(self.user_dir) + self.conf_file = conf_file + conf_dict = xml2dict(self.conf_file) + self.conf = conf_dict['telecaster'] + self.title = self.conf['infos']['name'] + self.log_file = self.conf['log'] + self.logger = Logger(self.log_file) + self.url = self.conf['infos']['url'] + + def index(self, request): + self.get_ids() + stations = Station.objects.filter(started=True) + + if stations and (self.writing or self.casting): + template = 'telecaster/stop.html' + # FIXME: manage multiple stations + station = stations[0] + if request.method == 'POST': + station.set_conf(self.conf) + station.setup() + station.stop() + time.sleep(2) + self.logger.write_info('stop') + return HttpResponseRedirect('/') + + else: + template = 'telecaster/start.html' + if request.method == 'POST': + station = StationForm(data=request.POST) + if station.is_valid(): + station.set_conf(self.conf) + station.setup() + station.start() + station.started = True + station.save() + self.logger.write_info('start') + time.sleep(2) + return HttpResponseRedirect('/') + else: + station = StationForm() + + return render(request, template, {'station': station}) + + def get_hosts(self): + ip = '' + for interface in self.interfaces: + try: + ip = get_ip_address(interface) + if ip: + self.ip = ip + break + except: + self.ip = 'localhost' + if 'url' in self.conf['infos']: + self.url = 'http://' + self.conf['infos']['url'] + else: + self.url = 'http://' + self.ip + + def get_ids(self): + edcast_pid = get_pid('edcast_jack', self.uid) + deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.user_dir+os.sep+'deefuzzer.xml', self.uid) + self.writing = edcast_pid != [] + self.casting = deefuzzer_pid != [] + + def get_status(self): + self.get_hosts() + self.get_ids() + self.acpi.update() + status = {} + status['acpi_state'] = acpi_states[self.acpi.charging_state()] + status['acpi_percent'] = self.acpi.percent() + status['acpi_temperature'] = self.acpi.temperature(0) + status['jack_state'] = jackd_pid != [] + status['url'] = self.url + status['ip'] = self.ip + status['url'] = self.url + status['casting'] = self.casting + status['writing'] = self.writing + return status + diff --git a/webview.py b/webview.py index 48cee74..f3d9cee 100644 --- a/webview.py +++ b/webview.py @@ -231,7 +231,7 @@ class WebView(FieldStorage): self.casting = writing self.writing = casting self.refresh = False - self.mount_point = 'telecaster_live.' + self.format + self.mount_point = 'telecaster_live.' + self.format self.header() self.javascript() self.sub_header() -- 2.39.5