2007-07-10 12:31:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-06-19 10:14:38 +00:00
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2007-07-10 12:31:08 +00:00
|
|
|
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):
|
2008-06-19 10:14:38 +00:00
|
|
|
f = open(f_name)
|
|
|
|
data = f.read()
|
|
|
|
f.close()
|
|
|
|
return data
|
2007-07-10 12:31:08 +00:00
|
|
|
|
|
|
|
def saveFile(f_name, data):
|
2008-06-19 10:14:38 +00:00
|
|
|
f = open(f_name, 'w')
|
|
|
|
f.write(data)
|
|
|
|
f.close()
|
2007-07-10 12:31:08 +00:00
|
|
|
|
|
|
|
def loadStaticFile(fname):
|
2008-06-19 10:14:38 +00:00
|
|
|
return loadFile(join(dirname(abspath(__file__)), "static", fname))
|
2007-07-10 12:31:08 +00:00
|
|
|
|
|
|
|
def loadFrame(afile, position):
|
2008-06-19 10:14:38 +00:00
|
|
|
position = basename(position).replace(':', '.')
|
|
|
|
frame = join(afile.frameFolder, '%s.%s' % (position, img_extension))
|
|
|
|
if not exists(frame):
|
|
|
|
afile.extractFrame(position)
|
|
|
|
if exists(frame):
|
|
|
|
return loadFile(frame)
|
|
|
|
return ''
|
2007-07-10 12:31:08 +00:00
|
|
|
|
2007-12-12 13:58:19 +00:00
|
|
|
def loadFlvClip(afile, position):
|
2008-06-19 10:14:38 +00:00
|
|
|
position = basename(position).replace(':', '.')
|
|
|
|
positions = position.split(';')
|
|
|
|
if len(positions) > 1:
|
|
|
|
position = positions[0]
|
|
|
|
outpoint = positions[1]
|
|
|
|
else:
|
|
|
|
outpoint = -1
|
|
|
|
flash = join(afile.frameFolder, '%s.%s' % (position, 'flv'))
|
|
|
|
if not exists(flash):
|
|
|
|
afile.extractFlvClip(position, outpoint)
|
|
|
|
if exists(flash):
|
|
|
|
return loadFile(flash)
|
|
|
|
return ''
|
2007-07-10 12:31:08 +00:00
|
|
|
|
2007-12-12 13:58:19 +00:00
|
|
|
def loadOggClip(afile, position):
|
2008-06-19 10:14:38 +00:00
|
|
|
position = basename(position).replace(':', '.')
|
|
|
|
positions = position.split(';')
|
|
|
|
if len(positions) > 1:
|
|
|
|
position = positions[0]
|
|
|
|
outpoint = positions[1]
|
|
|
|
else:
|
|
|
|
outpoint = -1
|
|
|
|
clip = join(afile.frameFolder, '%s.%s' % (position, 'ogv'))
|
|
|
|
if not exists(clip):
|
|
|
|
afile.extractOggClip(position, outpoint)
|
|
|
|
if exists(clip):
|
|
|
|
return loadFile(clip)
|
|
|
|
return ''
|
2007-12-12 13:58:19 +00:00
|
|
|
|
2007-07-10 12:31:08 +00:00
|
|
|
def loadTimeline(afile):
|
2008-06-19 10:14:38 +00:00
|
|
|
timeline = afile.timelineFile
|
|
|
|
if not exists(timeline):
|
|
|
|
afile.extractTimeline()
|
|
|
|
if exists(timeline):
|
|
|
|
return loadFile(timeline)
|
|
|
|
return ''
|
2007-07-18 11:21:01 +00:00
|
|
|
|
2008-07-03 16:24:54 +00:00
|
|
|
def loadStil(afile, position):
|
|
|
|
still = afile.stillFile
|
|
|
|
still.replace('.png', '%s.png' % position)
|
2008-06-19 10:14:38 +00:00
|
|
|
if not exists(still):
|
2008-07-03 16:24:54 +00:00
|
|
|
afile.extractStill(position)
|
2008-06-19 10:14:38 +00:00
|
|
|
if exists(still):
|
|
|
|
return loadFile(still)
|
|
|
|
return ''
|
|
|
|
|