From: yomguy <> Date: Wed, 28 Nov 2007 14:27:53 +0000 (+0000) Subject: Rm oldies X-Git-Tag: 0.9~342 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3cfd99e9789617b82f125d90b30b15f0626633c6;p=telecaster-client.git Rm oldies --- diff --git a/old/teleoddcast_dev.py b/old/teleoddcast_dev.py deleted file mode 100755 index e46800c..0000000 --- a/old/teleoddcast_dev.py +++ /dev/null @@ -1,301 +0,0 @@ -#!/usr/bin/python -# *-* coding: utf-8 *-* -""" - teleoddcast - - Copyright (c) 2006-2007 Guillaume Pellerin - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -""" - -version = '0.2.1' - -import os -import cgi -import shutil -import datetime -import time -from mutagen.oggvorbis import OggVorbis - -def get_pid(proc,uid): - """Get a process pid filtered by arguments and uid""" - (list1, list2) = os.popen4('pgrep -f -U '+str(uid)+' '+'"'+proc+'"') - pids = list2.readlines() - if pids != '': - for pid in pids: - index = pids.index(pid) - pids[index] = pid[:-1] - return pids - - -def get_lines(file): - """Get lines from a file""" - fic = open(file,'r') - lines = fic.readlines() - fic.close() - return lines - -def clean_string(string): - """removes blank spaces and accents""" - string = string.replace(' ','_') - string = string.replace('é','e') - string = string.replace('è','e') - return string - -def start_stream(odd_conf_file, lock_file, media_dir, title, category, course, session, professor, comment): - oddconf = open(odd_conf_file,'r') - params = oddconf.readlines() - oddconf.close() - newlines = [] - for line in params: - if 'ServerDescription' in line.split('='): - ServerDescription = title+'_-_'+category+'_-_'+course+'_-_'+session+'_-_'+professor+'_-_'+comment - ServerDescription = ServerDescription.replace(' ','_') - newlines.append('ServerDescription='+ServerDescription+'\n') - elif 'ServerName' in line.split('='): - ServerName=title+'_-_'+category+'_-_'+course+'_-_'+session - ServerName=clean_string(ServerName) - newlines.append('ServerName='+ServerName+'\n') - elif 'ServerMountpoint' in line.split('='): - mount_point = '/'+clean_string(title)+'_-_'+clean_string(category)+'_-_'+clean_string(course)+'.ogg' - newlines.append('ServerMountpoint='+mount_point+'\n') - else: - newlines.append(line) - oddconf = open(odd_conf_file,'w') - oddconf.writelines(newlines) - oddconf.close() - os.system('oddcastv3 -n "'+clean_string(course)+'" -c '+odd_conf_file+ \ - ' alsa_pcm:capture_1 alsa_pcm:capture_2 > /dev/null &') - lock = open(lock_file,'w') - lock_text = clean_string(title+'_*_'+category+'_*_'+course+'_*_'+session+'_*_'+professor+'_*_'+comment) - lock_text = lock_text.replace('\n','') - lock.write(lock_text) - lock.close() - time.sleep(1) - return mount_point - -def start_rip(url, mount_point, media_dir, category): - output_dir = media_dir+os.sep+category+os.sep - #print mount_point - if not os.path.exists(output_dir): - os.mkdir(output_dir) - os.system('streamripper '+url+mount_point+' -d '+output_dir+' -D "%S" -s -t --quiet > /dev/null &') - -def stop_oddcast(pid): - os.system('kill -9 '+pid) - -def rm_lockfile(lock_file): - os.system('rm '+lock_file) - -def stop_rip(pid,media_dir,title,category,course,session,professor,comment): - os.system('kill -9 '+pid) - time.sleep(1) - date = datetime.datetime.now().strftime("%Y") - filename = clean_string(title+'_-_'+category+'_-_'+course+'_-_'+session+'_-_'+date+'_-_'+professor+'_-_'+comment+'.ogg') - dirname = media_dir + os.sep + category + os.sep + clean_string(title+'_-_'+category+'_-_'+course+'_-_'+session) - if os.path.exists(dirname) and os.path.exists(dirname+os.sep+'incomplete'): - shutil.move(dirname+os.sep+'incomplete'+os.sep+' - .ogg',dirname+os.sep) - shutil.rmtree(dirname+os.sep+'incomplete'+os.sep) - os.rename(dirname+os.sep+' - .ogg',dirname+os.sep+filename) - -def get_params_from_lock(lock_file): - lockfile = open(lock_file,'r') - params = lockfile.readline() - params_ok = params.split('_*_') - lockfile.close() - return params_ok - -def write_tags(media_dir,title,category,course,session,professor,comment): - date = datetime.datetime.now().strftime("%Y") - filename = clean_string(title+'_-_'+category+'_-_'+course+'_-_'+session+'_-_'+date+'_-_'+professor+'_-_'+comment+'.ogg') - new_title = clean_string(title+'_-_'+category+'_-_'+course+'_-_'+session) - dirname = media_dir + os.sep + category + os.sep + new_title - if os.path.exists(dirname+os.sep+filename): - audio = OggVorbis(dirname+os.sep+filename) - audio['TITLE'] = new_title - audio['ARTIST'] = professor - audio['ALBUM'] = title - audio['DATE'] = date - audio['GENRE'] = 'Vocal' - audio['SOURCE'] = title - audio['ENCODER'] = 'TeleOddCast by Parisson' - audio['COMMENT'] = comment - audio.save() - -def get_def_tags(doc): - for tag in doc.documentElement.getElementsByTagName('category') : - name = tag.getAttribute('name') - value = typeToolBox.cast(tag.getAttribute('value'), tag.getAttribute('type')) - tags.__dict__[name] = value - for opt in doc.documentElement.getElementsByTagName('opt') : - name = opt.getAttribute('name') - value = typeToolBox.cast(opt.getAttribute('value'), opt.getAttribute('type')) - options.__dict__[name] = value - - -# Required header that tells the browser how to render the HTML. -print "Content-Type: text/html\n\n" - -def header(title): - print "" - print "" - print "\t"+title+"" - print "" - print "" - print "" - print "
" - print "
" - print "\t

 TeleOddCast - L'enregistrement et la diffusion audio en direct par internet

" - print "
" - -def colophon(): - print "
" - print "TeleOddCast "+version+" © 2007 Parisson. Tous droits réservés." - print "
" - -def footer(): - print "
" - print "" - print "" - - - -def start_form(title, categories, courses): - header(title) - print "
" - print "
Cliquez ici pour écouter le flux continu 24/24 en direct
" - print "\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t
Titre :"+title+"
Département :
Intitulé du cours :
Session :
Professeur :
Commentaire :
" - print "\t
Attention, il est important de remplir tous les champs, y compris le commentaire !
" - print "
" - print "
" - print "\t" - print "\t" - print "\t" - print "
" - colophon() - footer() - - -def stop_form(url,title, category, course, session, professor, comment): - """Stop page""" - header(title) - print "
" - print "\t

Cette formation est en cours de diffusion :

" - print "
" - print "\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t
Titre :"+title+"
Département :"+category+"
Intitulé du cours :"+course+"
Session :"+session+"
Professeur :"+professor+"
Commentaire :"+comment+"
" - print "
" - print "
Cliquez ici pour écouter cette formation en direct
" - print "
" - print "
" - print "\t" - print "\t" - print "\t" - print "
" - colophon() - footer() - -def main(): - """Main function""" - title = 'Pre-barreau - Augustins' - root_dir = '/var/www/cgi-bin/' - media_dir = root_dir + 'media/' - server = 'augustins.pre-barreau.com' - port = '8000' - url = 'http://'+server+':'+port - uid = os.getuid() - - xml_conf_file = root_dir+'pre-barreau.xml' - categories = get_lines(root_dir+'pre-barreau_categories.txt') - courses = get_lines(root_dir+'pre-barreau_courses.txt') - odd_conf_file = root_dir+'teleoddcast.cfg' - lock_file = root_dir+'teleoddcast.lock' - oddcast_pid = get_pid('^oddcastv3 -n [^LIVE]',uid) - - doc = xml.dom.minidom.parse(xml_conf_file) - tag_tools.get_def_tags(doc) - - form = cgi.FieldStorage() - - if oddcast_pid == [] and form.has_key("action") and \ - form.has_key("category") and form.has_key("course") and form.has_key("professor") \ - and form.has_key("comment") and form["action"].value == "start": - - mount_point = start_stream(odd_conf_file, lock_file, media_dir, title, - form["category"].value, form["course"].value, - form["session"].value, form["professor"].value, - form["comment"].value) - - category = form["category"].value - start_rip(url,mount_point,media_dir,category) - - stop_form(url,title, - form["category"].value, form["course"].value, - form["session"].value, form["professor"].value, - form["comment"].value) - - elif oddcast_pid != [] and os.path.exists(lock_file) and not form.has_key("action"): - - title,category,course,session,professor,comment = get_params_from_lock(lock_file) - stop_form(url,title,category,course,session,professor,comment) - - elif oddcast_pid != [] and form.has_key("action") and form["action"].value == "stop": - - if os.path.exists(lock_file): - title,category,course,session,professor,comment = get_params_from_lock(lock_file) - - stop_oddcast(oddcast_pid[0]) - mount_point = '/'+clean_string(title)+'_-_'+clean_string(category)+'_-_'+clean_string(course)+'.ogg' - #print mount_point - streamripper_pid = get_pid('streamripper '+url+mount_point,uid) - - if streamripper_pid != []: - stop_rip(streamripper_pid[0],media_dir,title,category,course,session,professor,comment) - write_tags(media_dir,title,category,course,session,professor,comment) - - rm_lockfile(lock_file) - - start_form(title, categories, courses) - - elif oddcast_pid == []: - start_form(title, categories, courses) - -# Call main function. -main() - diff --git a/old/teleoddcast_dev2.py b/old/teleoddcast_dev2.py deleted file mode 100755 index 3aaf37f..0000000 --- a/old/teleoddcast_dev2.py +++ /dev/null @@ -1,320 +0,0 @@ -#!/usr/bin/python -# *-* coding: utf-8 *-* -""" - teleoddcast - - Copyright (c) 2006-2007 Guillaume Pellerin - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -""" - -version = '0.2' - -import os -import cgi -import shutil -import datetime -import time -from mutagen.oggvorbis import OggVorbis - -def get_pid(proc,uid): - """Get a process pid filtered by arguments and uid""" - (list1, list2) = os.popen4('pgrep -f -U '+str(uid)+' '+'"'+proc+'"') - pids = list2.readlines() - if pids != '': - for pid in pids: - index = pids.index(pid) - pids[index] = pid[:-1] - return pids - - -def get_lines(file): - """Get lines from a file""" - fic = open(file,'r') - lines = fic.readlines() - fic.close() - return lines - -def clean_string(string): - """removes blank spaces and accents""" - string = string.replace(' ','_') - string = string.replace('é','e') - string = string.replace('è','e') - return string - -def start_stream(odd_conf_file, lock_file, media_dir, title, department, course, session, professor, comment): - oddconf = open(odd_conf_file,'r') - params = oddconf.readlines() - oddconf.close() - newlines = [] - for line in params: - if 'ServerDescription' in line.split('='): - ServerDescription = title+'_-_'+department+'_-_'+course+'_-_'+session+'_-_'+professor+'_-_'+comment - ServerDescription = ServerDescription.replace(' ','_') - newlines.append('ServerDescription='+ServerDescription+'\n') - elif 'ServerName' in line.split('='): - ServerName=title+'_-_'+department+'_-_'+course+'_-_'+session - ServerName=clean_string(ServerName) - newlines.append('ServerName='+ServerName+'\n') - elif 'ServerMountpoint' in line.split('='): - mount_point = '/'+clean_string(title)+'_-_'+clean_string(department)+'_-_'+clean_string(course)+'.ogg' - newlines.append('ServerMountpoint='+mount_point+'\n') - else: - newlines.append(line) - oddconf = open(odd_conf_file,'w') - oddconf.writelines(newlines) - oddconf.close() - os.system('oddcastv3 -n "'+clean_string(course)+'" -c '+odd_conf_file+ \ - ' alsa_pcm:capture_1 alsa_pcm:capture_2 > /dev/null &') - lock = open(lock_file,'w') - lock_text = clean_string(title+'_*_'+department+'_*_'+course+'_*_'+session+'_*_'+professor+'_*_'+comment) - lock_text = lock_text.replace('\n','') - lock.write(lock_text) - lock.close() - time.sleep(1) - return mount_point - -def start_rip(url, mount_point, media_dir, department): - output_dir = media_dir+os.sep+department+os.sep - #print mount_point - if not os.path.exists(output_dir): - os.mkdir(output_dir) - os.system('streamripper '+url+mount_point+' -d '+output_dir+' -D "%S" -s -t --quiet > /dev/null &') - -def stop_oddcast(pid): - os.system('kill -9 '+pid) - -def rm_lockfile(lock_file): - os.system('rm '+lock_file) - -def stop_rip(pid,media_dir,title,department,course,session,professor,comment): - os.system('kill -9 '+pid) - time.sleep(1) - date = datetime.datetime.now().strftime("%Y") - filename = clean_string(title+'_-_'+department+'_-_'+course+'_-_'+session+'_-_'+date+'_-_'+professor+'_-_'+comment+'.ogg') - dirname = media_dir + os.sep + department + os.sep + clean_string(title+'_-_'+department+'_-_'+course+'_-_'+session) - if os.path.exists(dirname) and os.path.exists(dirname+os.sep+'incomplete'): - shutil.move(dirname+os.sep+'incomplete'+os.sep+' - .ogg',dirname+os.sep) - shutil.rmtree(dirname+os.sep+'incomplete'+os.sep) - os.rename(dirname+os.sep+' - .ogg',dirname+os.sep+filename) - -def get_params_from_lock(lock_file): - lockfile = open(lock_file,'r') - params = lockfile.readline() - params_ok = params.split('_*_') - lockfile.close() - return params_ok - -def write_tags(media_dir,title,department,course,session,professor,comment): - date = datetime.datetime.now().strftime("%Y") - filename = clean_string(title+'_-_'+department+'_-_'+course+'_-_'+session+'_-_'+date+'_-_'+professor+'_-_'+comment+'.ogg') - new_title = clean_string(title+'_-_'+department+'_-_'+course+'_-_'+session) - dirname = media_dir + os.sep + department + os.sep + new_title - if os.path.exists(dirname+os.sep+filename): - audio = OggVorbis(dirname+os.sep+filename) - audio['TITLE'] = new_title - audio['ARTIST'] = professor - audio['ALBUM'] = title - audio['DATE'] = date - audio['GENRE'] = 'Vocal' - audio['SOURCE'] = title - audio['ENCODER'] = 'TeleOddCast by Parisson' - audio['COMMENT'] = comment - audio.save() - -# Required header that tells the browser how to render the HTML. -print "Content-Type: text/html\n\n" - -def header(title): - print "" - print "" - print "\t"+title+"" - print "" - print "" - print "" - print "
" - print "
" - print "\t

 TeleOddCast - L'enregistrement et la diffusion audio en direct par internet

" - print "
" - -def colophon(): - print "
" - print "TeleOddCast "+version+" © 2007 Parisson. Tous droits réservés." - print "
" - -def footer(): - print "
" - print "" - print "" - - - -def start_form(title, departments, courses): - header(title) - for department in departments: - print "
" - print "
Cliquez ici pour écouter le flux continu 24/24 en direct
" - print "\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t
Titre :"+title+"
Département :"+department+"
Intitulé du cours :
Session :
Professeur :
Commentaire :
" - print "\t
Attention, il est important de remplir tous les champs, y compris le commentaire !
" - print "
" - print "
" - print "\t" - print "\t" - print "\t" - print "
" - colophon() - footer() - - -def stop_form(url,title, department, course, session, professor, comment): - """Stop page""" - header(title) - print "
" - print "\t

Cette formation est en cours de diffusion :

" - print "
" - print "\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t\t" - print "\t
Titre :"+title+"
Département :"+department+"
Intitulé du cours :"+course+"
Session :"+session+"
Professeur :"+professor+"
Commentaire :"+comment+"
" - print "
" - print "
Cliquez ici pour écouter cette formation en direct
" - print "
" - print "
" - print "\t" - print "\t" - print "\t" - print "
" - colophon() - footer() - -class School: - """ - a School object - """ - - def __init__(self): - self.metadata = {} - - def set_metadata(self, metadata): - self.metadata = metadata - - def get_metadata(self): - return self.metadata - - def - - def set_tag_values(self, tag, values): - for values in courses - self.metadata - - - def add_to_dict(dict,tag,value): - """ - Return a dictionary with the value added to the existing tag - """ - tags = dict[tag] - tags= tags.append(value) - dict[tag] = tags - return dict - - -def main(): - """Main function""" - title = 'Pre-barreau - Augustins' - root_dir = '/var/www/cgi-bin/' - media_dir = root_dir + 'media/' - server = 'augustins.pre-barreau.com' - port = '8000' - url = 'http://'+server+':'+port - uid = os.getuid() - metadata = {'departments':'' , 'courses':'', 'sessions':'', 'professor':'', 'comment':''} - - - departments = get_lines(root_dir+'pre-barreau_departments.txt') - for dep in departments: - add_to_dict(metadata, - courses = get_lines(root_dir+'pre-barreau_courses.txt') - odd_conf_file = root_dir+'teleoddcast.cfg' - - oddcast_pid = get_pid('^oddcastv3 -n [^LIVE]',uid) - lock_file = root_dir+'teleoddcast.lock' - - form = cgi.FieldStorage() - - if oddcast_pid == [] and form.has_key("action") and \ - form.has_key("course") and form.has_key("professor") \ - and form.has_key("comment") and form["action"].value == "start": - - mount_point = start_stream(odd_conf_file, lock_file, media_dir, title, - form["department"].value, form["course"].value, - form["session"].value, form["professor"].value, - form["comment"].value) - - department = form["department"].value - start_rip(url,mount_point,media_dir,department) - - stop_form(url,title, - form["department"].value, form["course"].value, - form["session"].value, form["professor"].value, - form["comment"].value) - - elif oddcast_pid != [] and os.path.exists(lock_file) and not form.has_key("action"): - - title,department,course,session,professor,comment = get_params_from_lock(lock_file) - stop_form(url,title,department,course,session,professor,comment) - - elif oddcast_pid != [] and form.has_key("action") and form["action"].value == "stop": - - if os.path.exists(lock_file): - title,department,course,session,professor,comment = get_params_from_lock(lock_file) - - stop_oddcast(oddcast_pid[0]) - mount_point = '/'+clean_string(title)+'_-_'+clean_string(department)+'_-_'+clean_string(course)+'.ogg' - #print mount_point - streamripper_pid = get_pid('streamripper '+url+mount_point,uid) - - if streamripper_pid != []: - stop_rip(streamripper_pid[0],media_dir,title,department,course,session,professor,comment) - write_tags(media_dir,title,department,course,session,professor,comment) - - rm_lockfile(lock_file) - - start_form(title, departments, courses) - - elif oddcast_pid == []: - start_form(title, departments, courses) - -# Call main function. -main() -