[xiph-commits] r13017 - trunk/icebreaker
nickmudd at svn.xiph.org
nickmudd at svn.xiph.org
Wed Jun 6 22:18:40 PDT 2007
Author: nickmudd
Date: 2007-06-06 22:18:40 -0700 (Wed, 06 Jun 2007)
New Revision: 13017
Added:
trunk/icebreaker/config.py
trunk/icebreaker/populate.py
Log:
added populate.py, config.py
Added: trunk/icebreaker/config.py
===================================================================
--- trunk/icebreaker/config.py (rev 0)
+++ trunk/icebreaker/config.py 2007-06-07 05:18:40 UTC (rev 13017)
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# Config file for Icebreaker
+
+file_dir=''
+
+# conn = 'mysql://test:pwd@localhost/testdb'
+# conn = 'mysql://test:pwd@localhost/testdb?debug=1'
+# [To allow debugging, shows sql queries]
+# conn = 'postgres://test:pwd@localhost/testdb'
+# conn = SQLiteConnect('database.db')
+# conn = 'sqlite://path/to/database.db'
+# conn = DBMConnection('database/')
+# conn = 'dbm://path/to/database/'
+
+conn = ''
Property changes on: trunk/icebreaker/config.py
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/icebreaker/populate.py
===================================================================
--- trunk/icebreaker/populate.py (rev 0)
+++ trunk/icebreaker/populate.py 2007-06-07 05:18:40 UTC (rev 13017)
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+# Import modules
+import os
+import mutagen
+from mutagen.oggvorbis import OggVorbis
+from sqlobject import *
+
+# Import variables from config file.
+execfile('config.py')
+
+class data(SQLObject):
+ _connection = conn
+ album1 = StringCol()
+ artist1 = StringCol()
+ title1 = StringCol()
+ path1 = StringCol()
+ genre1 = StringCol()
+try:
+ data.dropTable()
+except:
+ pass
+
+data.createTable()
+
+# Walk filesystem,
+for path, dirs, files in os.walk(file_dir):
+
+# Check for files
+ if len(files) > 0:
+# find number of files
+ w = len(files)
+# Set counter to zero.
+ n = 0
+# while counter is less than file length. (possibly try less than or equal to?)
+ while n < w:
+# join path and files
+ g = os.path.join(path, files[n])
+# split extension from path
+ i = os.path.splitext(g)
+# increment counter
+ n += 1
+# check if extension is .ogg (possibly check for mime type later?)
+ if i[1] != ".ogg":
+ exit
+# read metadata from tag, assign to variables, check errors
+ try:
+ h = mutagen.oggvorbis.OggVorbis(g)
+ except mutagen.oggvorbis.OggVorbisHeaderError:
+ album = ''
+ artist = ''
+ title = ''
+ genre = ''
+ try:
+ album = h['album']
+ except KeyError:
+ album = ''
+ try:
+ artist = h['artist']
+ except KeyError:
+ artist = ''
+ try:
+ title = h['title']
+ except KeyError:
+ title = ''
+ try:
+ genre = h['genre']
+ except KeyError:
+ genre = ''
+# Add row to table.
+ try:
+ data(path1 = g, artist1 = artist, album1 = album, title1 = title, genre1 = genre)
+ except UnicodeDecodeError:
+ exit
+ except UnicodeEncodeError:
+ exit
+# Print metadata, path
+ try:
+ print artist, album, title, genre, g
+ except UnicodeEncodeError:
+ artist = artist.encode('utf-8')
+ album = album.encode('utf-8')
+ title = title.encode('utf-8')
+ genre = genre.encode('utf-8')
+ print artist, album, title, genre, g
Property changes on: trunk/icebreaker/populate.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the commits
mailing list