From: yomguy Date: Fri, 18 Jun 2010 08:29:38 +0000 (+0000) Subject: make script executable X-Git-Tag: 0.3.2~146 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=43daff6c9303297ac7dea743f1ef4f32a8056d15;p=timeside.git make script executable --- diff --git a/timeside/tools/waveform_batch b/timeside/tools/waveform_batch new file mode 100644 index 0000000..dfb6344 --- /dev/null +++ b/timeside/tools/waveform_batch @@ -0,0 +1,110 @@ +#!/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 + +version = '0.1-beta' + +import os +import sys +from timeside.core import * +from timeside.decoder import * +from timeside.grapher import * + + +class GrapherScheme: + + def __init__(self): + + self.color_scheme = { + 'waveform': [ + (50,0,200), (0,220,80), (255,224,0), (255,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) + ]} + + self.width = 2048 + self.height = 128 + self.bg_color = (255,255,255) + self.force = True + + +class Media2Waveform(object): + + def __init__(self, media_dir, img_dir): + self.root_dir = media_dir + self.img_dir = img_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.media_list = self.get_media_list() + if not os.path.exists(self.img_dir): + os.mkdir(self.img_dir) + self.path_dict = self.get_path_dict() + + def get_media_list(self): + media_list = [] + for root, dirs, files in os.walk(self.root_dir): + if root: + for file in files: + ext = file.split('.')[-1] + if ext == 'mp3' or ext == 'MP3': + media_list.append(root+os.sep+file) + return media_list + + def get_path_dict(self): + path_dict = {} + for media in self.media_list: + name = os.path.splitext(media) + name = name[0].split(os.sep)[-1] + path_dict[media] = self.img_dir + os.sep + name + '.png' + return path_dict + + def process(self): + for source, image in self.path_dict.iteritems(): + if not os.path.exists(image) or self.force: + print 'Rendering ', source, ' to ', image, '...' + audio = os.path.join(os.path.dirname(__file__), source) + decoder = FileDecoder(audio) + waveform = Waveform(width=self.width, height=self.height, output=image, + bg_color=self.bg_color, color_scheme=self.color_scheme) + (decoder | waveform).run() + print 'frames per pixel = ', waveform.graph.samples_per_pixel + waveform.render() + + +if __name__ == '__main__': + if len(sys.argv) <= 2: + print """ + Usage : python waveform_batch /path/to/media_dir /path/to/img_dir + + Dependencies : timeside, python, python-numpy, python-gst0.10, gstreamer0.10-plugins-base + See http://code.google.com/p/timeside/ for more information. + """ + else: + media_dir = sys.argv[-2] + img_dir = sys.argv[-1] + m = Media2Waveform(media_dir, img_dir) + m.process() diff --git a/timeside/tools/waveform_batch.py b/timeside/tools/waveform_batch.py deleted file mode 100644 index dfa75fd..0000000 --- a/timeside/tools/waveform_batch.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/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 - -version = '0.1-beta' - -import os -import sys -from timeside.core import * -from timeside.decoder import * -from timeside.grapher import * - - -class GrapherScheme: - - def __init__(self): - - self.color_scheme = { - 'waveform': [ - (50,0,200), (0,220,80), (255,224,0), (255,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) - ]} - - self.width = 2048 - self.height = 128 - self.bg_color = (255,255,255) - self.force = True - - -class Media2Waveform(object): - - def __init__(self, media_dir, img_dir): - self.root_dir = media_dir - self.img_dir = img_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.media_list = self.get_media_list() - if not os.path.exists(self.img_dir): - os.mkdir(self.img_dir) - self.path_dict = self.get_path_dict() - - def get_media_list(self): - media_list = [] - for root, dirs, files in os.walk(self.root_dir): - if root: - for file in files: - ext = file.split('.')[-1] - if ext == 'mp3' or ext == 'MP3': - media_list.append(root+os.sep+file) - return media_list - - def get_path_dict(self): - path_dict = {} - for media in self.media_list: - name = os.path.splitext(media) - name = name[0].split(os.sep)[-1] - path_dict[media] = self.img_dir + os.sep + name + '.png' - return path_dict - - def process(self): - for source, image in self.path_dict.iteritems(): - if not os.path.exists(image) or self.force: - print 'Rendering ', source, ' to ', image, '...' - audio = os.path.join(os.path.dirname(__file__), source) - decoder = FileDecoder(audio) - waveform = Waveform(width=self.width, height=self.height, output=image, - bg_color=self.bg_color, color_scheme=self.color_scheme) - (decoder | waveform).run() - print 'frames per pixel = ', waveform.graph.samples_per_pixel - waveform.render() - - -if __name__ == '__main__': - if len(sys.argv) <= 2: - print """ - Usage : python waveform_batch.py /path/to/media_dir /path/to/img_dir - - Dependencies : timeside, python, python-numpy, python-gst0.10, gstreamer0.10-plugins-base - See http://code.google.com/p/timeside/ for more information. - """ - else: - media_dir = sys.argv[-2] - img_dir = sys.argv[-1] - m = Media2Waveform(media_dir, img_dir) - m.process()