* cleanup oxdbarchive, consolidated cache code
* no tg_flash * fix extract_timeline
This commit is contained in:
parent
40d1554124
commit
9779cfc86a
7 changed files with 45 additions and 321 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# -*- Mode: Python; -*-
|
||||
# vi:si:et:sw=2:sts=2:ts=2
|
||||
|
||||
from sqlobject import *
|
||||
from turbogears.database import PackageHub
|
||||
import turbogears
|
||||
|
|
@ -15,7 +16,6 @@ from glob import glob
|
|||
import shutil
|
||||
|
||||
|
||||
import oxdb_cache
|
||||
import cache
|
||||
import oxdb_import
|
||||
from oxdb_utils import oxdb_title, oxdb_director, oxdb_id
|
||||
|
|
@ -63,7 +63,8 @@ class Archive(SQLObject):
|
|||
params is a dict with at least md5sum, path, date but also needs
|
||||
audio, video, length, size, bpp for new files
|
||||
'''
|
||||
params['path'] = params['path'].replace(self.basePath, '')
|
||||
params['path'] = params['path'].replace(self.basePath, u'')
|
||||
|
||||
q = ArchiveFile.select(AND(
|
||||
ArchiveFile.q.archiveID == self.id,
|
||||
ArchiveFile.q.md5sum == params['md5sum'],
|
||||
|
|
@ -140,8 +141,6 @@ class Archive(SQLObject):
|
|||
md5sum_on_disk.append(oxdb_files[f]['md5sum'])
|
||||
else:
|
||||
meta = oxdb_import.oxdb_file_metadata(meta)
|
||||
#remove base
|
||||
meta['path'] = f.encode('utf-8')
|
||||
#FIXME: check input
|
||||
for key in ['bpp', 'size', 'length', 'date']:
|
||||
meta[key] = int(float(meta[key]))
|
||||
|
|
@ -160,9 +159,9 @@ class Archive(SQLObject):
|
|||
|
||||
class ArchiveFile(SQLObject):
|
||||
'''
|
||||
ALTER TABLE file_meta CHANGE size size bigint;
|
||||
ALTER TABLE file_meta CHANGE pixels pixels bigint;
|
||||
ALTER TABLE file_meta CHANGE srt srt LONGTEXT;
|
||||
ALTER TABLE archive_file CHANGE size size bigint;
|
||||
ALTER TABLE archive_file CHANGE pixels pixels bigint;
|
||||
ALTER TABLE archive_file CHANGE srt srt LONGTEXT;
|
||||
'''
|
||||
md5sum = UnicodeCol(length=128, alternateID=True)
|
||||
oxdb = UnicodeCol(length=128)
|
||||
|
|
@ -328,10 +327,18 @@ class ArchiveFile(SQLObject):
|
|||
if f.nameExtra == self.nameExtra or f.nameExtra == 'en':
|
||||
self.subtitle_meta_id = f.id
|
||||
|
||||
|
||||
def _get_mini_movie_file(self):
|
||||
return join(oxdb_cache.mini_movie_folder, self.md5sum[:4], "%s.avi" % self.md5sum)
|
||||
return join(cache.cache_root, 'mini', self.md5sum[:4], "%s.avi" % self.md5sum)
|
||||
|
||||
def _get_frameFolder(self):
|
||||
f = join(cache.cache_root, 'mini', self.md5sum[:4], self.md5sum)
|
||||
if not exists(f):
|
||||
os.makedirs(f)
|
||||
return f
|
||||
|
||||
def _get_timelineFile(self):
|
||||
return join(cache.cache_root, 'timeline', self.md5sum[:4], "%s.png" % self.md5sum)
|
||||
|
||||
def removeMiniMovie(self):
|
||||
if os.path.exists(self.mini_movie_file):
|
||||
os.remove(self.mini_movie_file)
|
||||
|
|
@ -345,16 +352,16 @@ class ArchiveFile(SQLObject):
|
|||
return None
|
||||
|
||||
def extractAll(self, force = False):
|
||||
self.updateMeta()
|
||||
self.extractClipMovie()
|
||||
self.extractTimeline()
|
||||
|
||||
def extractClip(self, inpoint, outpoint=-1, flash_folder=oxdb_cache.frame_cache_root):
|
||||
if not self.extracted or force:
|
||||
self.updateMeta()
|
||||
self.extractClipMovie()
|
||||
self.extractTimeline()
|
||||
self.extracted = True
|
||||
|
||||
def extractClip(self, inpoint, outpoint=-1, flash_folder=cache.frame_cache_root):
|
||||
movie_file = self.mini_movie_file
|
||||
flash_folder = join(flash_folder, self.oxdb)
|
||||
flash_movie = join(flash_folder, "%s.flv" % inpoint.replace(':', '.'))
|
||||
if not os.path.exists(flash_folder):
|
||||
os.makedirs(flash_folder)
|
||||
position = inpoint.replace(':', '.')
|
||||
flash_movie = join(self.frameFolder, '%s.%s' % (position, 'flv'))
|
||||
width = 128
|
||||
height = int(width / (self.width / self.height))
|
||||
height = height - height % 2
|
||||
|
|
@ -364,12 +371,10 @@ class ArchiveFile(SQLObject):
|
|||
outpoint = s['stop']
|
||||
else:
|
||||
outpoint = shift_time(2000, inpoint)
|
||||
if self.part > 1:
|
||||
offset = self.offset
|
||||
extract_flash(movie_file, flash_movie, inpoint, outpoint, width, height, offset = 0)
|
||||
#extract_flash_ng(self.absolutePath, flash_movie, inpoint, outpoint, width, height, offset)
|
||||
|
||||
def extractFrame(self, position, img_folder=oxdb_cache.frame_cache_root):
|
||||
def extractFrame(self, position, img_folder=cache.frame_cache_root):
|
||||
if self.movieFile:
|
||||
return self.movieFile.extractFrame(position, img_folder)
|
||||
movie_file = self.mini_movie_file
|
||||
|
|
@ -378,7 +383,7 @@ class ArchiveFile(SQLObject):
|
|||
os.makedirs(img_folder)
|
||||
extract_frame(movie_file, position, img_folder, offset = 0, redo = False)
|
||||
|
||||
def extractFrames(self, img_folder=oxdb_cache.frame_cache_root):
|
||||
def extractFrames(self, img_folder=cache.frame_cache_root):
|
||||
if self.movieFile:
|
||||
return self.movieFile.extractFrames(img_folder)
|
||||
movie_file = self.absolutePath
|
||||
|
|
@ -394,7 +399,7 @@ class ArchiveFile(SQLObject):
|
|||
movie_file = self.absolutePath
|
||||
if not movie_file or not os.path.exists(movie_file):
|
||||
return
|
||||
if os.path.exists(mini_movie_file):
|
||||
if os.path.exists(mini_movie_file) and not force:
|
||||
print "clip exists, skipping extraction", mini_movie_file
|
||||
return
|
||||
if not os.path.exists(dirname(mini_movie_file)):
|
||||
|
|
@ -409,8 +414,6 @@ class ArchiveFile(SQLObject):
|
|||
print cmd.encode('utf-8')
|
||||
os.system(cmd.encode('utf-8'))
|
||||
|
||||
def _get_timelineFile(self):
|
||||
return join(oxdb_cache.cache_root, 'timeline', self.md5sum[:4], "%s.png" % self.md5sum)
|
||||
|
||||
def removeTimeline(self):
|
||||
if os.path.exists(self.timelineFile):
|
||||
|
|
@ -428,7 +431,7 @@ class ArchiveFile(SQLObject):
|
|||
|
||||
t = self.timelineFile
|
||||
if os.path.exists(self.mini_movie_file):
|
||||
if not os.path.exists(t):
|
||||
if not os.path.exists(os.path.dirname(t)):
|
||||
os.makedirs(os.path.dirname(t))
|
||||
#lets only extract the timeline if it does not exist yet
|
||||
if os.path.exists(t):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue