extract still, check if archive is online and nothing changed

This commit is contained in:
j 2008-07-03 18:24:54 +02:00
commit a551640122
8 changed files with 85 additions and 25 deletions

View file

@ -2,6 +2,8 @@
# vi:si:et:sw=2:sts=2:ts=2
import gzip
import StringIO
from glob import glob
import os
from sqlobject import *
from turbogears.database import PackageHub
@ -19,7 +21,7 @@ import shutil
import socket
import simplejson
from oxutils.net import getUrl
from oxlib.net import getUrl
import subtitles
import cache
@ -50,6 +52,28 @@ class Archive(SQLObject):
self.basePath = basePath
return basePath
def findNew(self):
#only update archive if not modified for more than 2 hours
if archive.isOnline():
if archive.sinceLastModification() > 60*60*2:
archive.importFiles()
else:
print "ignoring %s, was changed withing last 2 hours" % archive.basePath
else:
print "WARNING %s, is not online, check power and disk" % archive.basePath
def isOnline(self):
r = os.system('find "%s" >/dev/null 2>&1' % self.basePath)
if r:
return False
r = glob("%s*" % self.basePath)
if not r:
return False
return True
def sinceLastModification(self):
return time.time() - max([os.stat(f).st_mtime for f in glob('%s/*'% self.basePath)])
def notifyFrontend(self, action, md5sum):
if self.baseUrlFrontend:
dto = socket.getdefaulttimeout()
@ -412,7 +436,11 @@ class ArchiveFile(SQLObject):
def _get_posterStillFile(self):
return join(cache.cache_root, 'posterStill', self.md5sum[:4], "%s.png" % self.md5sum)
def stillFile(self, position):
position = oxlib.getValidFilename(position)
return join(cache.cache_root, 'still', self.md5sum[:4], "%s_%s.png" % (self.md5sum, position))
def removeMiniMovie(self):
if exists(self.mini_movie_file):
os.remove(self.mini_movie_file)
@ -504,7 +532,7 @@ class ArchiveFile(SQLObject):
def extractFrames(self, img_folder=cache.frame_cache_root):
for p in self._startPoints():
self.frame(p)
def extractPosterStill(self, position):
oxdb_makedir(dirname(self.posterStillFile))
mFile = self.absolutePath
@ -515,22 +543,22 @@ class ArchiveFile(SQLObject):
def extractClipMovie(self, force = False):
if self.broken:
return
if not self.height:
#only if midentify works we should try to extract the clip
return
if self.path.split('.')[-1] in ('mp3', 'wav', 'srt', 'sub', 'idx', 'rar','jpg', 'png'):
#ignore files known to not be
#do not try to extract non movie files, or files that could not be identified
if not self.height or self.path.split('.')[-1] in ('mp3', 'wav', 'srt', 'sub', 'idx', 'rar','jpg', 'png'):
self.extracted = True
return
mini_movie_file = self.mini_movie_file
movie_file = self.absolutePath
if not movie_file or not exists(movie_file):
return
if exists(mini_movie_file) and not force:
if not exists(mini_movie_file):
self.extracted = False
if self.extracted and not force:
debug("clip exists, skipping extraction %s" % mini_movie_file)
return
self.extracted = False
oxdb_makedir(dirname(mini_movie_file))
options = ''
options += " -ovc lavc -lavcopts vcodec=mjpeg"
options += " -af volnorm=1 -oac mp3lame -lameopts br=64:mode=3 -af resample=44100"
@ -624,7 +652,7 @@ class ArchiveFile(SQLObject):
#return if its not a video
if self.height <= 0:
return
if not (self.extracted and exists(self.mini_movie_file)):
debug("mini movie missing, skipping %s" % self.path)
return
@ -637,13 +665,10 @@ class ArchiveFile(SQLObject):
oxdb_makedir(dirname(t))
#this fails in tg-admin shell
#extractTimelineScript = abspath(join(dirname(__file__), "tools/extract_timeline.py"))
extractTimelineScript = abspath(join(dirname(cache.cache_root), "tools/extract_timeline.py"))
#this fails is called inside server
#extractTimelineScript = "oxdbarchive/tools/extract_timeline.py"
cmd = "python %s %s %s" %(extractTimelineScript, t, self.mini_movie_file)
os.system(cmd)
def loadSubtitleFromFile(self):
if self.movieFile:
movieFile = self.movieFile
@ -706,9 +731,22 @@ class ArchiveFile(SQLObject):
def frame(self, position):
return cache.loadFrame(self, position)
def timeline(self):
return cache.loadTimeline(self)
def posterStill(self, position):
return cache.loadPosterStill(self, position)
def still(self, position):
still = self.stillFile(position)
if not exists(still):
oxdb_makedir(dirname(still))
movieFile = self.absolutePath
if os.path.splitext(movieFile)[-1] in ('.mov', '.mpg', '.mpeg'):
movieFile = self.mini_movie_file
extract_still(movieFile, still, position)
if exists(still):
return cache.loadFile(still)
return ''