2007-07-10 12:31:08 +00:00
|
|
|
# -*- Mode: Python; -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=2:sts=2:ts=2
|
|
|
|
|
|
|
|
import os
|
|
|
|
from os.path import abspath, exists, join, dirname, basename
|
|
|
|
import shutil
|
|
|
|
from glob import glob
|
|
|
|
|
|
|
|
import Image
|
|
|
|
from StringIO import StringIO
|
|
|
|
|
|
|
|
from scrapeit.utils import read_url
|
|
|
|
|
|
|
|
cache_root = join(dirname(abspath(__file__)), 'cache')
|
|
|
|
img_extension = "jpg"
|
|
|
|
|
|
|
|
frame_cache_root = join(cache_root, 'frame')
|
|
|
|
|
|
|
|
def loadFile(f_name):
|
|
|
|
f = open(f_name)
|
|
|
|
data = f.read()
|
|
|
|
f.close()
|
|
|
|
return data
|
|
|
|
|
|
|
|
def saveFile(f_name, data):
|
|
|
|
f = open(f_name, 'w')
|
|
|
|
f.write(data)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def loadStaticFile(fname):
|
|
|
|
return loadFile(join(dirname(abspath(__file__)), "static", fname))
|
|
|
|
|
|
|
|
def loadFrame(afile, position):
|
2007-07-10 20:01:41 +00:00
|
|
|
position = basename(position).replace(':', '.')
|
2007-07-10 13:32:21 +00:00
|
|
|
frame = join(afile.frameFolder, '%s.%s' % (position, img_extension))
|
2007-07-10 12:31:08 +00:00
|
|
|
if not exists(frame):
|
|
|
|
afile.extractFrame(position)
|
|
|
|
if exists(frame):
|
|
|
|
return loadFile(frame)
|
2007-07-10 14:14:50 +00:00
|
|
|
return ''
|
2007-07-10 12:31:08 +00:00
|
|
|
|
|
|
|
def loadClip(afile, position):
|
2007-07-10 20:01:41 +00:00
|
|
|
position = basename(position).replace(':', '.')
|
2007-07-10 13:32:21 +00:00
|
|
|
flash = join(afile.frameFolder, '%s.%s' % (position, 'flv'))
|
2007-07-10 12:31:08 +00:00
|
|
|
if not exists(flash):
|
|
|
|
afile.extractClip(position)
|
|
|
|
if exists(flash):
|
|
|
|
return loadFile(flash)
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def loadTimeline(afile):
|
|
|
|
timeline = afile.timelineFile
|
|
|
|
if not exists(timeline):
|
|
|
|
afile.extractTimeline()
|
|
|
|
if exists(timeline):
|
|
|
|
return loadFile(timeline)
|
|
|
|
return ''
|