From: yomguy Date: Sun, 8 Jul 2012 17:40:29 +0000 (+0200) Subject: fix unicodes, fix colors, cleanup, add new player view (contour, white bg), add old... X-Git-Tag: 1.4.4~1^2~3 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=f6bc1e03a048bc18732dc0fa49b0dff6640f49b6;p=telemeta.git fix unicodes, fix colors, cleanup, add new player view (contour, white bg), add old (awdio) cgi process --- diff --git a/telemeta/models/dublincore.py b/telemeta/models/dublincore.py index 67ebde8a..504121c0 100644 --- a/telemeta/models/dublincore.py +++ b/telemeta/models/dublincore.py @@ -65,7 +65,11 @@ class Resource(object): [(key, value), ...]""" result = [] for element in self.elements: - result.append((element.name, unicode(element.value))) + if isinstance(element.value, str): + value = element.value.decode('utf8') + else: + value = element.value + result.append((element.name, unicode(value))) return result def add(self, *elements): diff --git a/telemeta/models/media.py b/telemeta/models/media.py index ee0880bb..f5671d36 100644 --- a/telemeta/models/media.py +++ b/telemeta/models/media.py @@ -215,7 +215,8 @@ class MediaCollection(MediaResource): conservation_site = CharField(_('conservation site')) # Technical data - code = CharField(_('code'), unique=True, required=True, validators=[is_valid_collection_code]) + code = CharField(_('code'), unique=True, required=True, + validators=[is_valid_collection_code]) old_code = CharField(_('old code'), unique=False, null=True, blank=True) approx_duration = DurationField(_('approximative duration')) physical_items_num = IntegerField(_('number of components (medium / piece)')) @@ -381,7 +382,7 @@ class MediaItem(MediaResource): def public_id(self): if self.code: return self.code - return self.id + return str(self.id) class Meta(MetaCore): db_table = 'media_items' diff --git a/telemeta/models/system.py b/telemeta/models/system.py index 51938469..c7b3719c 100644 --- a/telemeta/models/system.py +++ b/telemeta/models/system.py @@ -84,7 +84,7 @@ class UserProfile(models.Model): user = ForeignKey(User, unique=True, required=True) institution = CharField(_('Institution')) department = CharField(_('Department')) - attachment = CharField(_('attachment')) + attachment = CharField(_('Attachment')) function = CharField(_('Function')) address = TextField(_('Address')) telephone = CharField(_('Telephone')) diff --git a/telemeta/static/telemeta/css/more.png b/telemeta/static/telemeta/css/more.png index db83cb87..3954eea7 100644 Binary files a/telemeta/static/telemeta/css/more.png and b/telemeta/static/telemeta/css/more.png differ diff --git a/telemeta/static/telemeta/css/telemeta.css b/telemeta/static/telemeta/css/telemeta.css index d1a4dae9..9c07dc31 100644 --- a/telemeta/static/telemeta/css/telemeta.css +++ b/telemeta/static/telemeta/css/telemeta.css @@ -726,7 +726,7 @@ dl.dublincore dd.caption { color: #6a0307 !important; text-decoration: none; margin: 0; - background: #fff url(more.png) no-repeat left top; + background: #fff url(/static/telemeta/images/more.png) no-repeat left top; background-position: 0 -16px; padding-bottom: 2px; padding-left: 16px; diff --git a/telemeta/templates/telemeta/mediaitem_detail.html b/telemeta/templates/telemeta/mediaitem_detail.html index 2a2a96e9..be55192c 100644 --- a/telemeta/templates/telemeta/mediaitem_detail.html +++ b/telemeta/templates/telemeta/mediaitem_detail.html @@ -42,10 +42,13 @@ soundManager.preferFlash = true; //initializing the visualizers to be passed to the player + {% block graphers %} var visualizers = {}; {% for v in visualizers %} visualizers["{{v.name}}"] = "{% url telemeta-item-visualize item.public_id,v.id,"WIDTH","HEIGHT" %}"; {% endfor %} + {% endblock graphers %} + {% if user.is_superuser %} loadPlayer('{% url telemeta-item-analyze-xml item.public_id %}', "{% url telemeta-item-export item.public_id,"mp3" %}", undefined, '{{item.id}}', visualizers, diff --git a/telemeta/templates/telemeta/mediaitem_player_contour.html b/telemeta/templates/telemeta/mediaitem_player_contour.html new file mode 100644 index 00000000..aeb3bd80 --- /dev/null +++ b/telemeta/templates/telemeta/mediaitem_player_contour.html @@ -0,0 +1,54 @@ +{% extends "telemeta/mediaitem_detail.html" %} +{% load telemeta_utils %} +{% load i18n %} + +{% block stylesheets %} +{{ block.super }} + +{% endblock %} + +{% block graphers %} + //initializing the visualizers to be passed to the player + var visualizers = {}; + visualizers["{{visualizer_id}}"] = "{% url telemeta-item-visualize item.public_id,visualizer_id,"WIDTH","HEIGHT" %}"; +{% endblock graphers %} + +{% block title %}{% endblock %} +{% block title_buttons %}{% endblock %} + +{% block layout %} +{% block content %} +
+{% if item.file %} + {% if public_access or user.is_staff %} +
+
+
+
+
+
+ +
+ {% endif %} +{% endif %} +
+ +{% endblock content%} +{% endblock layout %} + +{% block footer %}{% endblock %} diff --git a/telemeta/urls.py b/telemeta/urls.py index 36b3be2c..1a3f11a4 100644 --- a/telemeta/urls.py +++ b/telemeta/urls.py @@ -114,6 +114,8 @@ urlpatterns = patterns('', dict(template='telemeta/mediaitem_player.html'), name="telemeta-item-player"), url(r'^archives/items/(?P[A-Za-z0-9._-]+)/player/(?P[0-9]+)x(?P[0-9]+)/simple/$', item_view.item_detail, dict(template='telemeta/mediaitem_player_simple.html'), name="telemeta-item-player-simple"), + url(r'^archives/items/(?P[A-Za-z0-9._-]+)/player/(?P[0-9]+)x(?P[0-9]+)/countour/$', item_view.item_detail, + dict(template='telemeta/mediaitem_player_contour.html'), name="telemeta-item-player-contour"), url(r'^archives/items/(?P[A-Za-z0-9._-]+)/performances/$', item_view.item_performances_edit, dict(template='telemeta/mediaitem_performances_edit.html'), name="telemeta-item-performances_edit"), url(r'^archives/items/(?P[A-Za-z0-9._-]+)/keywords/$', item_view.item_keywords_edit, diff --git a/tools/dev/push.sh b/tools/dev/push.sh index c6bab55a..6369c231 100755 --- a/tools/dev/push.sh +++ b/tools/dev/push.sh @@ -21,10 +21,10 @@ ssh vcs.parisson.com "cd /var/git/telemeta.git; git update-server-info" #echo "Update jimi.parisson.com:" echo "Update angus.parisson.com:" -ssh angus.parisson.com "cd /home/telemeta/telemeta-master; git pull; \ - cd /home/telemeta/telemeta-develop; git pull; \ - cd /home/telemeta/demo/; ./manage.py migrate telemeta --delete-ghost-migrations; - cd /home/telemeta/sandbox/; ./manage.py migrate telemeta --delete-ghost-migrations; - cd /home/telemeta/parisson/; ./manage.py migrate telemeta --delete-ghost-migrations; " +ssh angus.parisson.com "cd /home/telemeta/telemeta-master; git pull origin master; \ + cd /home/telemeta/telemeta-develop; git pull origin dev; \ + cd /home/telemeta/demo/; ./manage.py migrate --delete-ghost-migrations; + cd /home/telemeta/sandbox/; ./manage.py migrate --delete-ghost-migrations; + cd /home/telemeta/parisson/; ./manage.py migrate --delete-ghost-migrations; " echo "Done !" diff --git a/tools/scripts/process-waveform-cgi.py b/tools/scripts/process-waveform-cgi.py new file mode 100755 index 00000000..317878be --- /dev/null +++ b/tools/scripts/process-waveform-cgi.py @@ -0,0 +1,222 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2009-2010 Guillaume Pellerin + +# This file is part of TimeSide. + +# TimeSide 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. + +# TimeSide 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 TimeSide. If not, see . + +# Author: Guillaume Pellerin + +# for python2.5 + +version = '0.5' + + +import os +import sys +import time +import shutil +import datetime +import timeside + +# soon with python2.6 +#from multiprocessing import Process + +from django.core.management import setup_environ +from django.core.files.base import ContentFile +import cgi +fs = cgi.FieldStorage() + + +orig_media_dir = '/mnt/awdiomusic/musicbase' +project_dir = '/mnt/awdio' +log_file = project_dir + '/logs/process.log' +sys.path.append('/home/awdio/apps/telemeta-awdio') + + +class GrapherScheme: + + def __init__(self): + self.color = 255 + self.color_scheme = { + 'waveform': [ # Four (R,G,B) tuples for three main color channels for the spectral centroid method + (self.color,self.color,self.color) +# (0, 0, 0), (0, 0, 0), (0, 0, 0), (0,0,0) + ], + 'spectrogram': [ + (0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100), (224,224,44), (255,60,30), (255,255,255) + ]} + + # Grapher id + self.id = 'waveform_awdio' + + # Width of the image + self.width = 1800 + + # Height of the image + self.height = 233 + + # Background color + self.bg_color = None + + # Force computation. By default, the class doesn't overwrite existing image files. + self.force = False + + # Nb of threads + # FIXME: memory leak for > 1 ! + self.threads = 1 + + +class TelemetaPreprocessImport(object): + + def __init__(self, root_dir, dest_dir, log_file): + from telemeta.cache import TelemetaCache as Cache + from telemeta.util.logger import Logger + self.media_item_dir = 'items' + self.root_dir = root_dir + 'items' + self.dest_dir = dest_dir + self.threads = 1 + self.logger = Logger(log_file) + self.counter = 0 + self.force = 0 + self.cache = Cache(self.dest_dir) + + self.scheme = GrapherScheme() + self.width = self.scheme.width + self.height = self.scheme.height + self.bg_color = self.scheme.bg_color + self.color_scheme = self.scheme.color_scheme + self.force = self.scheme.force + self.threads = self.scheme.threads + self.logger = Logger(log_file) + self.counter = 0 + self.collection_name = 'awdio' + self.collection = self.set_collection(self.collection_name) + + self.analyzers = timeside.core.processors(timeside.api.IAnalyzer) + self.grapher = timeside.grapher.WaveformAwdio(width=self.width, + height=self.height, + bg_color=self.bg_color, + color_scheme=self.color_scheme) + + + def set_collection(self, collection_name): + import telemeta.models + collections = telemeta.models.media.MediaCollection.objects.filter(code=collection_name) + if not collections: + c = telemeta.models.media.MediaCollection(code=collection_name) + c.title = collection_name + c.save() + msg = 'added' + self.logger.logger.info(collection_name, msg) + collection = c + else: + collection = collections[0] + return collection + + def process(self): + import telemeta.models + keys = fs.keys() + if keys[0] == 'file': + filename = fs['file'].value + media_orig = orig_media_dir + os.sep + filename + media = self.root_dir + os.sep + filename + + if not os.path.exists(media): + shutil.copy(media_orig, media) + os.system('chmod 644 ' + media) + + name, ext = os.path.splitext(filename) + size = str(self.width) + '_' + str(self.height) + image_name = name + '.' + self.scheme.id + '.' + size + '.png' + image = self.dest_dir + os.sep + image_name + xml = name + '.xml' + + if not self.cache.exists(image_name) or not self.cache.exists(xml): + mess = 'Processing ' + media + self.logger.logger.info(mess) + + print "Content-type: text/plain\n" + print mess + decoder = timeside.decoder.FileDecoder(media) + pipe = decoder | self.grapher + analyzers = [] + analyzers_sub = [] + for analyzer in self.analyzers: + subpipe = analyzer() + analyzers_sub.append(subpipe) + pipe = pipe | subpipe + pipe.run() + + mess = 'Rendering ' + image + self.logger.logger.info(mess) + self.grapher.render(output=image) + + mess = 'Frames / Pixel = ' + str(self.grapher.graph.samples_per_pixel) + self.logger.logger.info(mess) + + for analyzer in analyzers_sub: + value = analyzer.result() + if analyzer.id() == 'duration': + value = datetime.timedelta(0,value) + analyzers.append({'name':analyzer.name(), + 'id':analyzer.id(), + 'unit':analyzer.unit(), + 'value':str(value)}) + + self.cache.write_analyzer_xml(analyzers, xml) + + item = telemeta.models.media.MediaItem.objects.filter(code=name) + + if not item: + item = telemeta.models.media.MediaItem(collection=self.collection, code=name) + item.title = name + item.file = self.media_item_dir + os.sep + filename + item.save() + msg = 'added item : ' + filename + self.logger.logger.info(self.collection_name, msg) + + pipe = 0 + decoder = 0 + + print "OK" + + #except: + #pipe = 0 + #decoder = 0 + #mess = 'Could NOT process : ' + media + #self.logger.logger.error(mess) + #print mess + + else: + mess = "Nothing to do with file : " + media + self.logger.logger.info(mess) + print "Content-type: text/plain\n" + print mess + + else: + print "Content-type: text/plain\n" + print "No file given !" + + +if __name__ == '__main__': + sys.path.append(project_dir) + import settings + setup_environ(settings) + media_dir = settings.MEDIA_ROOT + data_dir = settings.TELEMETA_DATA_CACHE_DIR + t = TelemetaPreprocessImport(media_dir, data_dir, log_file) + t.process()