2015-11-25 22:00:57 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2016-03-30 22:56:50 +00:00
|
|
|
import time
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2020-07-29 20:52:44 +00:00
|
|
|
from hydrus.core import HydrusConstants as HC
|
|
|
|
from hydrus.core import HydrusData
|
|
|
|
from hydrus.core import HydrusThreading
|
|
|
|
|
|
|
|
from hydrus.external import hexagonitswfheader
|
|
|
|
|
2015-11-25 22:00:57 +00:00
|
|
|
if HC.PLATFORM_LINUX:
|
|
|
|
|
|
|
|
SWFRENDER_PATH = os.path.join( HC.BIN_DIR, 'swfrender_linux' )
|
|
|
|
|
2019-11-20 23:10:46 +00:00
|
|
|
elif HC.PLATFORM_MACOS:
|
2015-11-25 22:00:57 +00:00
|
|
|
|
|
|
|
SWFRENDER_PATH = os.path.join( HC.BIN_DIR, 'swfrender_osx' )
|
|
|
|
|
|
|
|
elif HC.PLATFORM_WINDOWS:
|
|
|
|
|
|
|
|
SWFRENDER_PATH = os.path.join( HC.BIN_DIR, 'swfrender_win32.exe' )
|
|
|
|
|
2013-02-19 00:11:43 +00:00
|
|
|
# to all out there who write libraries:
|
|
|
|
# hexagonit.swfheader is a perfect library. it is how you are supposed to do it.
|
2013-08-07 22:25:18 +00:00
|
|
|
def GetFlashProperties( path ):
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-08-14 20:21:49 +00:00
|
|
|
with open( path, 'rb' ) as f:
|
2013-08-07 22:25:18 +00:00
|
|
|
|
|
|
|
metadata = hexagonitswfheader.parse( f )
|
|
|
|
|
2021-05-05 20:12:11 +00:00
|
|
|
# abs since one flash delivered negatives, and hexagonit calcs by going width = ( xmax - xmin ) etc...
|
|
|
|
|
|
|
|
width = abs( metadata[ 'width' ] )
|
|
|
|
height = abs( metadata[ 'height' ] )
|
2013-08-07 22:25:18 +00:00
|
|
|
|
|
|
|
num_frames = metadata[ 'frames' ]
|
|
|
|
fps = metadata[ 'fps' ]
|
|
|
|
|
2020-05-06 21:31:41 +00:00
|
|
|
if fps is None or fps == 0:
|
|
|
|
|
|
|
|
fps = 1
|
|
|
|
|
|
|
|
|
2019-01-09 22:59:03 +00:00
|
|
|
duration = ( 1000 * num_frames ) // fps
|
2013-08-07 22:25:18 +00:00
|
|
|
|
|
|
|
return ( ( width, height ), duration, num_frames )
|
|
|
|
|
2015-11-25 22:00:57 +00:00
|
|
|
|
|
|
|
def RenderPageToFile( path, temp_path, page_index ):
|
|
|
|
|
2019-01-09 22:59:03 +00:00
|
|
|
cmd = [ SWFRENDER_PATH, path, '-o', temp_path, '-p', str( page_index ) ]
|
2015-11-25 22:00:57 +00:00
|
|
|
|
2016-03-30 22:56:50 +00:00
|
|
|
timeout = HydrusData.GetNow() + 60
|
|
|
|
|
2019-01-09 22:59:03 +00:00
|
|
|
sbp_kwargs = HydrusData.GetSubprocessKWArgs()
|
|
|
|
|
2020-06-17 21:31:54 +00:00
|
|
|
HydrusData.CheckProgramIsNotShuttingDown()
|
|
|
|
|
2019-01-09 22:59:03 +00:00
|
|
|
p = subprocess.Popen( cmd, **sbp_kwargs )
|
2015-11-25 22:00:57 +00:00
|
|
|
|
2016-03-30 22:56:50 +00:00
|
|
|
while p.poll() is None:
|
|
|
|
|
|
|
|
if HydrusData.TimeHasPassed( timeout ):
|
|
|
|
|
|
|
|
p.terminate()
|
|
|
|
|
|
|
|
raise Exception( 'Could not render the swf page within 60 seconds!' )
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep( 0.5 )
|
|
|
|
|
2015-11-25 22:00:57 +00:00
|
|
|
|
2020-06-17 21:31:54 +00:00
|
|
|
HydrusThreading.SubprocessCommunicate( p )
|
2017-06-07 22:05:15 +00:00
|
|
|
|