extract still, check if archive is online and nothing changed

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

View file

@ -76,10 +76,11 @@ def loadTimeline(afile):
return loadFile(timeline) return loadFile(timeline)
return '' return ''
def loadPosterStill(afile, position): def loadStil(afile, position):
still = afile.posterStillFile still = afile.stillFile
still.replace('.png', '%s.png' % position)
if not exists(still): if not exists(still):
afile.extractPosterStill(position) afile.extractStill(position)
if exists(still): if exists(still):
return loadFile(still) return loadFile(still)
return '' return ''

View file

@ -12,6 +12,8 @@
# template name # template name
# tg.defaultview = "kid" # tg.defaultview = "kid"
tg.defaultview = "genshi"
# The following kid settings determine the settings used by the kid serializer. # The following kid settings determine the settings used by the kid serializer.
# One of (html|html-strict|xhtml|xhtml-strict|xml|json) # One of (html|html-strict|xhtml|xhtml-strict|xml|json)

View file

@ -51,6 +51,9 @@ class Root(controllers.RootController):
elif action == 'frame': elif action == 'frame':
cherrypy.response.headerMap['Content-Type'] = "image/jpeg" cherrypy.response.headerMap['Content-Type'] = "image/jpeg"
return f.frame(position) return f.frame(position)
elif action == 'still':
cherrypy.response.headerMap['Content-Type'] = "image/png"
return f.still(position)
elif action == 'posterStill': elif action == 'posterStill':
cherrypy.response.headerMap['Content-Type'] = "image/png" cherrypy.response.headerMap['Content-Type'] = "image/png"
return f.posterStill(position) return f.posterStill(position)

View file

@ -9,7 +9,7 @@ def cronDaily():
def findNew(): def findNew():
archive = Archive.get(1) archive = Archive.get(1)
archive.importFiles() archive.findNew()
def extractFrames(): def extractFrames():
for f in ArchiveFile.select(ArchiveFile.q.extracted == False): for f in ArchiveFile.select(ArchiveFile.q.extracted == False):

View file

@ -160,6 +160,16 @@ def extract_frame(movie_file, timestamp, img_folder, width=128, offset = 0, redo
print "update the cache %s missing" % movie_file print "update the cache %s missing" % movie_file
shutil.rmtree(framedir) shutil.rmtree(framedir)
def extract_still(movie_file, png_file, inpoint):
ext = movie_file.split('.')[-1]
if ext in ('sub', 'srt'):
print "this is not a movie file, will not try to extract frames"
return
inpoint = time2ms(inpoint)
extractClipScript = abspath(join(dirname(__file__), "tools/extract_frame.py"))
cmd = '''%s "%s" "%s" %s 0 -1''' % (extractClipScript, movie_file, png_file, inpoint)
run_command(cmd.encode('utf-8'))
def extract_poster_still(movie_file, png_file, inpoint): def extract_poster_still(movie_file, png_file, inpoint):
ext = movie_file.split('.')[-1] ext = movie_file.split('.')[-1]
if ext in ('sub', 'srt'): if ext in ('sub', 'srt'):

View file

@ -2,6 +2,8 @@
# vi:si:et:sw=2:sts=2:ts=2 # vi:si:et:sw=2:sts=2:ts=2
import gzip import gzip
import StringIO import StringIO
from glob import glob
import os
from sqlobject import * from sqlobject import *
from turbogears.database import PackageHub from turbogears.database import PackageHub
@ -19,7 +21,7 @@ import shutil
import socket import socket
import simplejson import simplejson
from oxutils.net import getUrl from oxlib.net import getUrl
import subtitles import subtitles
import cache import cache
@ -50,6 +52,28 @@ class Archive(SQLObject):
self.basePath = basePath self.basePath = basePath
return 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): def notifyFrontend(self, action, md5sum):
if self.baseUrlFrontend: if self.baseUrlFrontend:
dto = socket.getdefaulttimeout() dto = socket.getdefaulttimeout()
@ -413,6 +437,10 @@ class ArchiveFile(SQLObject):
def _get_posterStillFile(self): def _get_posterStillFile(self):
return join(cache.cache_root, 'posterStill', self.md5sum[:4], "%s.png" % self.md5sum) 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): def removeMiniMovie(self):
if exists(self.mini_movie_file): if exists(self.mini_movie_file):
os.remove(self.mini_movie_file) os.remove(self.mini_movie_file)
@ -515,17 +543,17 @@ class ArchiveFile(SQLObject):
def extractClipMovie(self, force = False): def extractClipMovie(self, force = False):
if self.broken: if self.broken:
return return
if not self.height: #do not try to extract non movie files, or files that could not be identified
#only if midentify works we should try to extract the clip if not self.height or self.path.split('.')[-1] in ('mp3', 'wav', 'srt', 'sub', 'idx', 'rar','jpg', 'png'):
return self.extracted = True
if self.path.split('.')[-1] in ('mp3', 'wav', 'srt', 'sub', 'idx', 'rar','jpg', 'png'):
#ignore files known to not be
return return
mini_movie_file = self.mini_movie_file mini_movie_file = self.mini_movie_file
movie_file = self.absolutePath movie_file = self.absolutePath
if not movie_file or not exists(movie_file): if not movie_file or not exists(movie_file):
return 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) debug("clip exists, skipping extraction %s" % mini_movie_file)
return return
self.extracted = False self.extracted = False
@ -637,10 +665,7 @@ class ArchiveFile(SQLObject):
oxdb_makedir(dirname(t)) oxdb_makedir(dirname(t))
#this fails in tg-admin shell #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")) 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) cmd = "python %s %s %s" %(extractTimelineScript, t, self.mini_movie_file)
os.system(cmd) os.system(cmd)
@ -712,3 +737,16 @@ class ArchiveFile(SQLObject):
def posterStill(self, position): def posterStill(self, position):
return cache.loadPosterStill(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 ''

View file

@ -98,7 +98,10 @@ class ExtractFrame:
caps = sink.sink_pads().next().get_negotiated_caps() caps = sink.sink_pads().next().get_negotiated_caps()
for s in caps: for s in caps:
input_size = (s['width'], s['height']) input_size = (s['width'], s['height'])
if self.width > 0:
self.frame_size = self.scaleto(s['width'], s['height']) self.frame_size = self.scaleto(s['width'], s['height'])
else:
self.frame_size = None
#Why are the last frames broken, aka have green pixels #Why are the last frames broken, aka have green pixels
save_last_frame = (4*gst.SECOND/float(s['framerate'])) save_last_frame = (4*gst.SECOND/float(s['framerate']))
if (self.duration-self.frame_pos) < save_last_frame: if (self.duration-self.frame_pos) < save_last_frame:
@ -166,8 +169,11 @@ class ExtractFrame:
self.quit() self.quit()
def quit(self): def quit(self):
if self.frame_img and self.frame_size: if self.frame_img:
if self.frame_size:
img = self.frame_img.resize(self.frame_size, Image.ANTIALIAS) img = self.frame_img.resize(self.frame_size, Image.ANTIALIAS)
else:
img = self.frame_img
img.save(self.frame_file) img.save(self.frame_file)
self.debug('frame saved at %s' % self.frame_file) self.debug('frame saved at %s' % self.frame_file)
self.pipeline.set_state(gst.STATE_NULL) self.pipeline.set_state(gst.STATE_NULL)