From: yomguy <> Date: Tue, 20 Jan 2009 16:28:37 +0000 (+0000) Subject: add wav_import tool X-Git-Tag: 1.1~729 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a1454215e0cbe76a2952d2d921e0d5c03650b67c;p=telemeta.git add wav_import tool --- diff --git a/tests/wav_import.py b/tests/wav_import.py new file mode 100644 index 00000000..7ee0a57f --- /dev/null +++ b/tests/wav_import.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +# +# Copyright (C) 2008 Parisson +# All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://svn.parisson.org/telemeta/TelemetaLicense. +# +# Author: Guillaume Pellerin +# +# usage example : +# +# $ python manage.py shell +# >>> from wav_import import TelemetaWavImport +# >>> id_string = 'BM.2006.002.001--25__01-0' +# >>> source_dir = '/home/momo/music/wav/CNRSMH_2006_002_GUYANE' +# >>> t = TelemetaWavImport(id_string, source_dir) +# >>> t.main() + + +import os +import sys +import shutil +import datetime +from telemeta.models import MediaItem +from django.conf import settings + +class TelemetaWavImport: + + def __init__(self, id_string, source_dir): + self.item_media_root_dir = settings.MEDIA_ROOT + os.sep + 'items' + os.sep + self.source_dir = source_dir + self.source_files = os.listdir(self.source_dir) + self.item_list = MediaItem.objects.filter(id__startswith=id_string) + self.collection_id = self.item_list[0].collection_id + self.year = datetime.datetime.now().strftime("%Y") + self.dest_dir = self.item_media_root_dir + self.year + os.sep + self.collection_id + + def copy_files(self): + if not os.path.exists(self.dest_dir): + os.makedirs(self.dest_dir) + for file in self.source_files: + shutil.copy(self.source_dir + os.sep + file, self.dest_dir) + + def wav_import(self): + self.files = os.listdir(self.dest_dir) + self.files.sort() + #print self.files + i = 0 + if len(self.files) > len(self.item_list): + for item in self.item_list: + #item = MediaItem.objects.get(id=object.id) + print item.id + " : " + item.title + " : " + item.file._name = unicode(self.dest_dir + os.sep + self.files[i]) + item.save() + print item.file._name + i += 1 + + def main(self): + self.copy_files() + self.wav_import() + + \ No newline at end of file