From c7271770d5588a90f746c077e825ce35c4dc5edc Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 24 Jul 2008 23:23:55 +0000 Subject: [PATCH] * Add direct to disk writing with oddcastv3 (raw_dir) * Add auto-refresh * Add tests and views for casting and writing * Add full date and time to file names * Restrict comments to XML test fields --- etc/pre-barreau_conferences.xml | 25 +++++++-- etc/telecaster.cfg | 4 +- etc/telecaster_mp3.cfg | 11 ++-- etc/telecaster_mp3.xml | 1 + telecaster.py | 94 ++++++++++++++++++++++++++------- tools.py | 3 ++ 6 files changed, 109 insertions(+), 29 deletions(-) diff --git a/etc/pre-barreau_conferences.xml b/etc/pre-barreau_conferences.xml index bba08a5..fdc4955 100644 --- a/etc/pre-barreau_conferences.xml +++ b/etc/pre-barreau_conferences.xml @@ -1,5 +1,5 @@ - http://localhost + http://192.168.7.202 Pre-Barreau - ICP 8000 mp3 @@ -14,10 +14,10 @@ Droit_administratif_Cours - Droit_civil_Corrections + Droit_des_obligations_Corrections - Droit_civil_Cours + Droit_des_obligations_Cours Droit_commercial_des_affaires_Corrections @@ -255,6 +255,23 @@ COLLET M. - + + 1er_cours + 2e_cours + 3e_cours + 4e_cours + 5e_cours + 6e_cours + 7e_cours + 8e_cours + 9e_cours + 10e_cours + 11e_cours + 12e_cours + 13e_cours + 14e_cours + 15e_cours + 16e_cours + diff --git a/etc/telecaster.cfg b/etc/telecaster.cfg index 7804523..f59d763 100644 --- a/etc/telecaster.cfg +++ b/etc/telecaster.cfg @@ -10,7 +10,7 @@ NumberChannels=1 OggQuality=1 Samplerate=44100 ServerType=Icecast2 -ExternalFile=/tmp +ExternalFile=/tmp/test #YP Settings ServerStreamURL=http://www.pre-barreau.com ServerName=Default_School_-_CRFPA_-_Droit_administratif_Cours @@ -19,6 +19,6 @@ ServerGenre=Teaching #Advanced Settings LogLevel=1 LogFile=oddcastv3.log -SaveAsWAV=0 +SaveAsWAV=1 OutputControl=SERVER,GENERAL,OUTPUT diff --git a/etc/telecaster_mp3.cfg b/etc/telecaster_mp3.cfg index 87ae267..ed72e65 100644 --- a/etc/telecaster_mp3.cfg +++ b/etc/telecaster_mp3.cfg @@ -1,23 +1,26 @@ Server=localhost Port=8000 ServerPassword=source2parisson -ServerMountpoint=/Pre-Barreau_-_ICP_-_CRFPA_-_Droit_civil_Corrections.mp3 +ServerMountpoint=/Pre-Barreau_-_ICP_-_CRFPA_-_Droit_administratif_Corrections.mp3 ServerPublic=0 AutomaticReconnectSecs=10 Encode=MP3 Lame BitrateNominal=64 +OggQuality=1 NumberChannels=1 Samplerate=44100 ServerType=Icecast2 -ExternalFile=/tmp +ExternalFile=/tmp/test #YP Settings ServerStreamURL=http://www.pre-barreau.com -ServerName=Pre-Barreau_-_ICP_-_CRFPA_-_Droit_civil_Corrections -ServerDescription=Pre-Barreau_-_ICP_-_CRFPA_-_Droit_civil_Corrections_-_2_-_GIUSTINIANI_G._-_lkh +ServerName=Pre-Barreau_-_ICP_-_CRFPA_-_Droit_administratif_Corrections +ServerDescription=Pre-Barreau_-_ICP_-_CRFPA_-_Droit_administratif_Corrections_-_2_-_MARINHO_A._-_1er_cours ServerGenre=Teaching #Advanced Settings LogLevel=1 LogFile=oddcastv3.log +SaveDirectoryFlag=1 +SaveDirectory=/home/prebarreau/backup SaveAsWAV=0 OutputControl=SERVER,GENERAL,OUTPUT diff --git a/etc/telecaster_mp3.xml b/etc/telecaster_mp3.xml index 610b598..c899954 100644 --- a/etc/telecaster_mp3.xml +++ b/etc/telecaster_mp3.xml @@ -20,6 +20,7 @@ true /home/prebarreau/media + /home/prebarreau/backup mp3 64 2 diff --git a/telecaster.py b/telecaster.py index b1c62da..d4b1c23 100755 --- a/telecaster.py +++ b/telecaster.py @@ -20,19 +20,22 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ -version = '0.3.3' +version = '0.3.4' import os import cgi +import cgitb import shutil import datetime import time import codecs import string import signal +import unicodedata from tools import * from mutagen.oggvorbis import OggVorbis from mutagen.id3 import ID3, TIT2, TP1, TAL, TDA, TCO, COM +cgitb.enable() class Conference: """A conference object including metadata""" @@ -56,6 +59,7 @@ class Station(Conference): def __init__(self, conf_file, conference_dict, lock_file): Conference.__init__(self, conference_dict) self.date = datetime.datetime.now().strftime("%Y") + self.time = str(datetime.datetime.now().strftime("%x-%X")).replace('/','_') self.conf = xml2dict(conf_file) self.conf = self.conf['telecaster'] self.root_dir = self.conf['server']['root_dir'] @@ -75,7 +79,7 @@ class Station(Conference): clean_string(self.department) + '_-_' + \ clean_string(self.conference)+'.'+self.format self.lock_file = self.root_dir + os.sep + self.conf['server']['lock_file'] - self.filename = self.ServerDescription + '.' + self.format + self.filename = self.ServerDescription + '_-_' + self.time + '.' + self.format self.output_dir = self.media_dir + os.sep + self.department + os.sep + self.date self.file_dir = self.output_dir + os.sep + self.ServerName self.uid = os.getuid() @@ -86,7 +90,7 @@ class Station(Conference): self.encoder = 'TeleCaster by Parisson' self.rsync_host = self.conf['server']['rsync_host'] self.record = str_to_bool(self.conf['media']['record']) - + self.raw_dir = self.conf['media']['raw_dir'] def set_oddcast_conf(self): oddconf = open(self.odd_conf_file,'r') @@ -107,6 +111,9 @@ class Station(Conference): elif 'ServerPassword' in line.split('='): newlines.append('ServerPassword=' + self.password + '\n') + elif 'SaveDirectory' in line.split('='): + newlines.append('SaveDirectory=' + self.raw_dir + '\n') + else: newlines.append(line) @@ -116,7 +123,7 @@ class Station(Conference): def start_oddcast(self): command = 'oddcastv3 -n "'+clean_string(self.conference)[0:16]+'" -c '+self.odd_conf_file+ \ - ' alsa_pcm:capture_1 alsa_pcm:capture_2 > /dev/null &' + ' alsa_pcm:capture_1 > /dev/null &' os.system(command) self.set_lock() time.sleep(1) @@ -137,6 +144,7 @@ class Station(Conference): command = 'streamripper ' + self.url + self.mount_point + \ ' -d '+self.output_dir+' -D "%S" -s -t --quiet > /dev/null &' os.system(command) + time.sleep(3) def stop_oddcast(self): if len(self.odd_pid) != 0: @@ -205,7 +213,7 @@ class Station(Conference): self.write_tags_mp3() self.del_lock() #self.mp3_convert() - self.rsync_out() + #self.rsync_out() def start_mp3cast(self): item_id = item_id @@ -264,16 +272,18 @@ class WebView: self.title = self.conf['title'] self.departments = self.conf['department'] self.professors = self.conf['professor'] + self.comments = self.conf['comment'] #print self.departments #self.conferences = self.conf['department']['conferences'] self.len_departments = len(self.departments) self.len_professors = len(self.professors) self.conference_nb_max = 40 self.professor_nb_max = 40 + self.refresh = False def header(self): # Required header that tells the browser how to render the HTML. - print "Content-Type: text/html\n" + print "Content-Type: text/html\n\n" print "" print "" print "TeleCaster - "+self.title+"" @@ -302,7 +312,9 @@ class WebView: print '}' print ' formulaire.conference.selectedIndex=0;}' print '' - print "" + if self.refresh: + print "" + print "\n" print "" print "
" @@ -322,12 +334,14 @@ class WebView: print "" def start_form(self, message=''): + self.refresh = False self.header() print "
" print "
"+message+"
" print "
Attention, il est important de remplir tous les champs, y compris le commentaire !
" print "" print "" + print "" print "" print "" + print "" print "" + print "" + print "" print "" - print "" + + print "" + print "" + print "
Titre :"+self.title+"
Département :
Conférence :
Session :
Professeur :
Commentaire :
Commentaire :
" print "
Cliquez ici pour écouter le flux continu 24/24 en direct
" print "
" @@ -372,17 +396,27 @@ class WebView: self.colophon() self.footer() - def stop_form(self, conference_dict): + def stop_form(self, conference_dict, writing, casting): """Stop page""" department = conference_dict['department'] conference = conference_dict['conference'] session = conference_dict['session'] professor = conference_dict['professor'] comment = conference_dict['comment'] - + self.refresh = True self.header() print "
" - print "

Cette formation est en cours de diffusion :

" + + print "
" + if writing: + print "

Enregistrement en cours

" + else: + print "

PAS d'enregistrement en cours

" + print '
' + if casting: + print "

Diffusion en cours

" + else: + print "

PAS de diffusion en cours

" print "
" print "" print "" @@ -423,13 +457,21 @@ class TeleCaster: self.odd_conf_file = self.conf['server']['lock_file'] self.title = self.conf['infos']['name'] self.uid = os.getuid() - self.odd_pid = get_pid('^oddcastv3 -n [^LIVE]', self.uid) def main(self): + odd_pid = get_pid('^oddcastv3 -n [^LIVE]', self.uid) + rip_pid = get_pid('streamripper ', self.uid) + writing = False + casting = True + if rip_pid != []: + writing = True + if odd_pid == []: + casting = False + w = WebView(self.school_file) form = cgi.FieldStorage() - if self.odd_pid == [] and form.has_key("action") and \ + if odd_pid == [] and form.has_key("action") and \ form.has_key("department") and form.has_key("conference") and \ form.has_key("professor") and form.has_key("comment") and \ form["action"].value == "start": @@ -443,21 +485,35 @@ class TeleCaster: s = Station(self.conf_file, self.conference_dict, self.lock_file) s.start() - w.stop_form(self.conference_dict) + time.sleep(4) + if get_pid('^oddcastv3 -n [^LIVE]', self.uid) != []: + casting = True + if get_pid('streamripper ', self.uid) == []: + writing = False + ws = WebView(self.school_file) + ws.stop_form(self.conference_dict, writing, casting) + exit() - elif self.odd_pid != [] and os.path.exists(self.lock_file) and not form.has_key("action"): + elif odd_pid != [] and os.path.exists(self.lock_file) and not form.has_key("action"): self.conference_dict = get_conference_from_lock(self.lock_file) - w.stop_form(self.conference_dict) - - elif self.odd_pid != [] and form.has_key("action") and form["action"].value == "stop": + if get_pid('^oddcastv3 -n [^LIVE]', self.uid) != []: + casting = True + if get_pid('streamripper ', self.uid) == []: + writing = False + w.stop_form(self.conference_dict, writing, casting) + exit() + + elif odd_pid != [] and form.has_key("action") and form["action"].value == "stop": 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.stop() w.start_form() + exit() - elif self.odd_pid == []: + elif odd_pid == []: w.start_form() + exit() # Call main function. diff --git a/tools.py b/tools.py index 063547d..c928a2b 100644 --- a/tools.py +++ b/tools.py @@ -102,3 +102,6 @@ def get_conference_from_lock(lock_file): def str_to_bool(string): return string == 'true' + +def norm_string(string): + pass \ No newline at end of file -- 2.39.5