Update of /cvsroot/freevo/freevo/src/helpers
In directory sc8-pr-cvs1:/tmp/cvs-serv11801/src/helpers
Added Files:
.cvsignore cache.py imdb.py musicsqlimport.py
Log Message:
Moved the first three helpers from helpers/ to src/helpers and changed
the freevo script to easy access them. The old helpers need a cleanup:
o what is realy needed?
o what should be in src/helpers because we need it from time to time?
o what should go to contrib?
--- NEW FILE: .cvsignore ---
*.pyc *.pyo
--- NEW FILE: cache.py ---
#!/usr/bin/env python
import sys
import os
import config
import util
def delete_old_files():
print 'deleting old cache files from older freevo version'
del_list = []
for file in ('image-viewer-thumb.jpg', 'thumbnails/image-viewer-thumb.jpg'):
file = os.path.join(config.FREEVO_CACHEDIR, file)
if os.path.isfile(file):
del_list.append(file)
d = os.path.join(config.FREEVO_CACHEDIR, 'audio')
if os.path.isdir(d):
del_list.append(d)
del_list += util.match_files(os.path.join(config.FREEVO_CACHEDIR, 'thumbnails'),
['jpg',])
for f in del_list:
if os.path.isdir(f):
os.system('rm -rf %s' % f)
else:
os.system('rm %s' % f)
def cache_helper(result, dirname, names):
result.append(dirname)
return result
def cache_directories():
import mmpython
mmcache = '%s/mmpython' % config.FREEVO_CACHEDIR
if not os.path.isdir(mmcache):
os.mkdir(mmcache)
mmpython.use_cache(mmcache)
mmpython.mediainfo.DEBUG = 0
mmpython.factory.DEBUG = 0
all_dirs = []
print 'caching directories...'
for n, d in config.DIR_MOVIES + config.DIR_AUDIO + config.DIR_IMAGES:
os.path.walk(d, cache_helper, all_dirs)
for d in all_dirs:
print d
mmpython.cache_dir(d)
os.system('touch %s/VERSION' % mmcache)
if __name__ == "__main__":
if len(sys.argv)>1 and sys.argv[1] == '--help':
print 'freevo cache helper to delete unused cache entries and to'
print 'cache all files in your data directories.'
print
print 'this script has no options (yet)'
print
sys.exit(0)
delete_old_files()
cache_directories()
--- NEW FILE: imdb.py ---
#!/usr/bin/env python
#if 0 /*
# -----------------------------------------------------------------------
# imdbp.py - IMDB helper script to generate fxd files
# -----------------------------------------------------------------------
# $Id: imdb.py,v 1.1 2003/08/05 19:32:55 dischi Exp $
#
# Notes:
#
# Todo:
#
# -----------------------------------------------------------------------
# $Log: imdb.py,v $
# Revision 1.1 2003/08/05 19:32:55 dischi
# Moved the first three helpers from helpers/ to src/helpers and changed
# the freevo script to easy access them. The old helpers need a cleanup:
# o what is realy needed?
# o what should be in src/helpers because we need it from time to time?
# o what should go to contrib?
#
# Revision 1.27 2003/08/04 18:42:03 dischi
# remove some stuff we do not need with the new freevo script
#
# Revision 1.26 2003/07/18 21:31:03 dischi
# new imdb helper based in the new fxdimdb
#
# Revision 1.26 2003/07/16 22:07:00 den_RDC
# rewrite to use fxd_imdb class
#
# Revision 1.25 2003/06/25 15:37:37 dischi
# some try-except if you can't write files
#
# Revision 1.24 2003/06/24 18:38:41 dischi
# Fixed handling when search returns only one result
#
# Revision 1.23 2003/06/24 18:12:45 dischi
# fixed string translation with urllib (not urllib2)
#
# Revision 1.22 2003/06/24 16:15:07 dischi
# o updated by den_RDC - changed code to urllib2 - exceptions are handled by
# urllib2, including 302 redirection -- proxy servers ,including transparant
# proxies now work
# o added support for better image finder. Right now there we can also get
# posters from www.impawards.com
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# 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 MER-
# CHANTABILITY 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.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif
import sys
import os
import config
from video.fxdimdb import FxdImdb, makeVideo
from random import Random
FALSE = 0
TRUE = 1
def usage():
print 'imdb.py -s string: search imdb for string'
print
print 'imdb.py -g filename: guess imdb for possible filename match'
print
print 'imdb.py [--rom-drive=/path/to/device] nr output files'
print ' Generate output.fxd for the movie.'
print ' Files is a list of files that belongs to this movie.'
print ' Use [dvd|vcd] to add the whole disc or use [dvd|vcd][title]'
print ' to add a special DVD or VCD title to the list of files'
print
print 'imdb.py [--rom-drive=/path/to/device] -a fxd-file file'
print ' add file to fxd-file.fxd'
print
print 'If no rom-drive is given and one is required, /dev/cdrom is assumed'
print
sys.exit(1)
def parse_file_args(input):
files = []
cdid = []
for i in input:
if i == 'dvd' or i == 'vcd' or i == 'cd':
cdid += [ i ]
else:
files += [ i ]
return files, cdid
#
# Main function
#
if __name__ == "__main__":
import getopt
drive = '/dev/cdrom'
driveset = FALSE
task = ''
search_arg = ''
try:
opts, args = getopt.getopt(sys.argv[1:], 'ag:s:', ('rom-drive=','list-guess='))
except getopt.GetoptError:
usage()
pass
for o, a in opts:
if o == '-a':
if task:
usage()
task = 'add'
if o == '-s':
if task:
usage()
task = 'search'
search_arg = a
if o == '-g':
if task:
usage()
task = 'guess'
search_arg = a
if o == '--rom-drive':
drive=a
driveset = TRUE
fxd = FxdImdb()
if task == 'add':
if len(args) == 2:
usage()
fxd.setFxdFile(arg[0])
if fxd.isDiscset() == TRUE:
fxd.setDiscset(drive, None)
elif fxd.isDiscset() == FALSE:
type = 'file'
if arg[1].find('[dvd]') != -1: type = 'dvd'
if arg[1].find('[vcd]') != -1: type = 'vcd'
id = abs( Random() * 100 )
if driveset == TRUE:
video = makeVideo(type, 'f' + str(id), arg[1], device=drive)
else : video = makeVideo(type, 'f' + str(id), arg[1])
fxd.setVideo(video)
else:
print 'Fxd file is not valid, updating failed'
sys.exit(1)
fxd.writeFxd()
sys.exit(0)
if task == 'search':
if len(args) != 0:
usage()
filename = search_arg
print "searching " + filename
for result in fxd.searchImdb(filename):
if result[3]:
print '%s %s (%s, %s)' % result
else:
print '%s %s (%s)' % (result[0], result[1], result[2])
sys.exit(0)
if task == 'guess':
filename = search_arg
print "searching " + filename
for result in fxd.guessImdb(filename):
if result[3]:
print '%s %s (%s, %s)' % result
else:
print '%s %s (%s)' % (result[0], result[1], result[2])
sys.exit(0)
# normal usage
if len(args) < 2:
usage()
imdb_number = args[0]
filename = args[1]
files, cdid = parse_file_args(args[2:])
if not (files or cdid):
usage()
fxd.setImdbId(imdb_number)
fxd.setFxdFile(filename)
x=0
for file in files:
type = 'file'
if file.find('[dvd]') != -1: type = 'dvd'
if file.find('[vcd]') != -1: type = 'vcd'
if driveset == TRUE: video = makeVideo(type, 'f' + str(x) , file, device=drive)
else: video = makeVideo(type, 'f' + str(x), file)
fxd.setVideo(video)
x = x+1
fxd.writeFxd()
--- NEW FILE: musicsqlimport.py ---
#!/usr/bin/env python
# The basics
import os,string,fnmatch,sys
# The DB stuff
import sqlite
# Metadata tools
import mmpython
sys.path.append('./src/')
import config, util
CACHEDIR = config.FREEVO_CACHEDIR
DBFILE ='freevo.sqlite'
DATABASE = os.path.join(config.FREEVO_CACHEDIR, DBFILE)
mmpython.use_cache('%s/mmpython' % (config.FREEVO_CACHEDIR))
# Utility functions
def inti(a):
if a:
return int(a)
else:
return 0
def check_db():
# verify the database exists
if not os.path.exists(DATABASE):
return None
# verify the table exists
db = sqlite.connect(DATABASE)
cursor = db.cursor()
cursor.execute('SELECT name FROM sqlite_master where name="music" and
type="table"')
if not cursor.fetchone()[0] == 'music':
return None
return DATABASE
def create_db():
db = sqlite.connect(DATABASE)
cursor = db.cursor()
cursor.execute("CREATE TABLE music (id INTEGER PRIMARY KEY, dirtitle VARCHAR(255),
md5 VARCHAR(32) UNIQUE, path VARCHAR(255), filename VARCHAR(255), type VARCHAR(3),
artist VARCHAR(255), title VARCHAR(255), album VARCHAR(255), year VARCHAR(255), track
NUMERIC(3), track_total NUMERIC(3), bpm NUMERIC(3), last_play float, play_count
NUMERIC, start_time NUMERIC, end_time NUMERIC, rating NUMERIC, eq VARCHAR)")
db.commit()
db.close()
def make_query(filename,dirtitle):
md5 = 'null'
if not os.path.exists(filename):
print "File %s does not exist" % (filename)
return None
mmpython.cache_dir(os.path.dirname(filename))
a = mmpython.parse(filename)
md5 = util.md5file(filename)
# This is ugly, how do I clean it up?
trackno = -1
trackof = -1
if a['trackno']:
trackno = inti(a['trackno'].split('/')[0])
if a['trackno'].find('/') != -1:
trackof = inti(a['trackno'].split('/')[1])
VALUES =
"(null,\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',%i,%i,%i,\'%s\',%f,%i,\'%s\',\'%s\',%i,\'%s\')"
\
%
(util.escape(dirtitle),md5,util.escape(os.path.dirname(filename)),util.escape(os.path.basename(filename)),
\
'mp3',util.escape(a['artist']),util.escape(a['title']),util.escape(a['album']),inti(a['date']),trackno,
\
trackof, 100,0,0,'0',inti(a['length']),0,'null')
SQL = 'INSERT OR IGNORE INTO music VALUES ' + VALUES
return SQL
def mainloop(path='/media/Music',dirtitle='',type='*.mp3'):
db = sqlite.connect(DATABASE,autocommit=0)
cursor = db.cursor()
songs = util.recursefolders(path,1,type,1)
cursor.execute('SELECT path, filename FROM music')
count = 0
for row in cursor.fetchall():
try:
songs.remove(os.path.join(row['path'],row['filename']))
count = count + 1
except ValueError:
# Why doesn't it just give a return code
pass
if count > 0:
print "Skipped %i songs already in the database..." % (count)
tempvar = ''
for song in songs:
cursor.execute(make_query(song,dirtitle))
# Only call commit after we're done to save time...
# (autocommit slows down the db dramatically)
db.commit()
db.close()
if __name__ == '__main__':
if len(sys.argv)>1 and sys.argv[1] == '--help':
print 'Freevo musicsqlimport helper'
print 'adds all mp3 files into the database'
sys.exit(0)
if not check_db():
print "Creating data file..."
create_db()
if len(sys.argv) > 1:
print "Adding %s to %s..." % (sys.argv[1],config.DIR_AUDIO[0][0])
mainloop(sys.argv[1],config.DIR_AUDIO[0][0])
else:
print "Populating Database with entries"
for dir in config.DIR_AUDIO:
print "Scanning %s" % dir[0]
mainloop(dir[1],dir[0])
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog